Skip to content

Commit 3dcc850

Browse files
Fix: Expected to find element: span, but never found it.
1 parent ace52f7 commit 3dcc850

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

cypress/components/Headlines.cy.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Headline4,
77
} from '~/components/Headlines';
88
import mockNextRouter, { MockRouter } from '../plugins/mockNextRouterUtils';
9+
import slugifyMarkdownHeadline from '~/lib/slugifyMarkdownHeadline';
910

1011
describe('Headlines Component', () => {
1112
let mockRouter: MockRouter;
@@ -94,11 +95,14 @@ describe('Headlines Component', () => {
9495
it('should be active if the URL has the hash', () => {
9596
/* Testing the active headline with Headline1 */
9697

97-
// Set the URL with the hash
98-
mockRouter.asPath = '/#what-is-json-schema';
98+
const title = 'What is JSON Schema?'
99+
const slug = slugifyMarkdownHeadline(title)
100+
101+
// Update the existing mock router's properties
102+
mockRouter.asPath = `/#${slug}`;
99103

100104
// Check if Correct headline is active
101-
cy.mount(<Headline1>What is JSON Schema?</Headline1>);
105+
cy.mount(<Headline1>{title}</Headline1>);
102106
cy.get('span').should(
103107
'have.class',
104108
'text-startBlue dark:text-endBlue inline-block ml-2',

lib/slugifyMarkdownHeadline.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function slugifyMarkdownHeadline(
99
return slugify(markdownChildren, {
1010
lower: true,
1111
trim: true,
12-
remove: /[*+~.()'"!:@]/g,
12+
remove: /[*+~()'"!]/g,
1313
});
1414

1515
const metaSlug = markdownChildren.reduce((acc, child) => {
@@ -26,10 +26,12 @@ export default function slugifyMarkdownHeadline(
2626
.filter((child) => typeof child === 'string')
2727
.map((string) => string.replace(FRAGMENT_REGEX, ''))
2828
.join(' ');
29+
2930
const slug = slugify(joinedChildren, {
3031
lower: true,
3132
trim: true,
32-
remove: /[*+~.()'"!:@]/g,
33+
remove: /[*+~()'"!]/g,
34+
3335
});
3436
return slug;
3537
}

0 commit comments

Comments
 (0)