Skip to content

Commit

Permalink
Fix intermittent test failure
Browse files Browse the repository at this point in the history
The Bookmark.svelte "truncate option > truncates long title at a space
when possible test" can fail if the randomly generated title contains
special characters. Fix this by escaping special characters in the title
when building the regular expression.
  • Loading branch information
msmolens committed Dec 4, 2020
1 parent eedf30f commit 3971c2b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/treetop/Bookmark.svelte.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Writable, writable } from 'svelte/store';
import { render, screen } from '@testing-library/svelte';
import faker from 'faker';
import { escapeRegExp } from 'lodash';

import Bookmark from '@Treetop/treetop/Bookmark.svelte';
import type * as Treetop from '@Treetop/treetop/types';
Expand Down Expand Up @@ -97,7 +98,9 @@ describe('truncate option', () => {

const link = screen.getByRole('link');
const titleStart = title.substring(0, Math.floor(maxLength / 2));
expect(link).toHaveTextContent(new RegExp(`^${titleStart}.+\\S\\.{3}$`));
expect(link).toHaveTextContent(
new RegExp(`^${escapeRegExp(titleStart)}.+\\S\\.{3}$`)
);
});

it('truncates URL when title is empty', () => {
Expand Down

0 comments on commit 3971c2b

Please sign in to comment.