-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
mount-in-play.stories.ts
45 lines (42 loc) · 1.12 KB
/
mount-in-play.stories.ts
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
import { expect, mocked, getByRole, spyOn, userEvent } from '@storybook/test';
const meta = {
component: globalThis.Components.Button,
loaders() {
spyOn(console, 'log').mockName('console.log');
console.log('1 - [from loaders]');
},
beforeEach() {
console.log('2 - [from meta beforeEach]');
},
};
export default meta;
export const MountInPlay = {
beforeEach() {
console.log('3 - [from story beforeEach]');
},
decorators: (storyFn) => {
console.log('5 - [from decorator]');
return storyFn();
},
args: {
label: 'Button',
onClick: () => {
console.log('7 - [from onClick]');
},
},
async play({ mount, canvasElement }) {
console.log('4 - [before mount]');
await mount();
console.log('6 - [after mount]');
await userEvent.click(getByRole(canvasElement, 'button'));
await expect(mocked(console.log).mock.calls).toEqual([
['1 - [from loaders]'],
['2 - [from meta beforeEach]'],
['3 - [from story beforeEach]'],
['4 - [before mount]'],
['5 - [from decorator]'],
['6 - [after mount]'],
['7 - [from onClick]'],
]);
},
};