-
Notifications
You must be signed in to change notification settings - Fork 187
/
console-errors.test.js
52 lines (44 loc) · 1.38 KB
/
console-errors.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {act} from 'react';
import {render} from '@testing-library/react';
import {getAllStoryFiles, getStories} from './test-helpers/get-stories';
jest.mock(
'./src/loader/loader__core',
() =>
class FakeLoader {
updateMessage = jest.fn();
destroy = jest.fn();
},
);
jest.mock('./src/old-browsers-message/old-browsers-message');
const options = {
suite: 'Console errors',
storyKindRegex: /^((?!Style-only\/Old Browsers Message).)*$/,
// storyNameRegex: /^with deprecated item\.type parameter$/,
};
describe(options.suite, () => {
getAllStoryFiles().forEach(({storyFile, title}) => {
const meta = storyFile.default;
if (
(options.storyKindRegex != null && !options.storyKindRegex.test(title)) ||
meta.parameters?.storyshots?.disable
) {
return;
}
describe(title, () => {
const stories = getStories(storyFile).filter(
({name, story}) =>
(options.storyNameRegex == null || options.storyNameRegex.test(name)) &&
!story.parameters.storyshots?.disable,
);
stories.forEach(({name, story}) => {
test(name, async () => {
const consoleError = jest.spyOn(global.console, 'error');
const Component = story;
render(<Component />);
await act(() => Promise.resolve());
expect(consoleError).not.toBeCalled();
});
});
});
});
});