@storybook/sveltekit 11.0.0-beta.1 → 11.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_browser-chunks/chunk-3HHKZM2E.js +55 -0
- package/dist/_browser-chunks/chunk-VAS652SN.js +88 -0
- package/dist/_node-chunks/{chunk-N7N5BJW4.js → chunk-GPJZQKOH.js} +8 -8
- package/dist/chunk-56nWP1O9.d.ts +43 -0
- package/dist/chunk-B5frDvvZ.d.ts +64 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/mocks/app/forms.d.ts +32 -0
- package/dist/mocks/app/forms.js +74 -14
- package/dist/mocks/app/navigation.d.ts +61 -0
- package/dist/mocks/app/navigation.js +63 -60
- package/dist/mocks/docs-isolation.d.ts +22 -0
- package/dist/mocks/docs-isolation.js +62 -0
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +6 -6
- package/dist/preset.js +11 -10
- package/dist/preview.js +2 -1
- package/dist/vite-plugin.js +7 -7
- package/package.json +20 -8
- package/static/app-state-mock.svelte.d.ts +39 -0
- package/static/app-state-mock.svelte.js +63 -33
- package/template/stories_svelte-kit-skeleton-ts/modules/Forms.svelte +18 -3
- package/template/stories_svelte-kit-skeleton-ts/modules/Hrefs.svelte +8 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/State.svelte +3 -3
- package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-isolated-mocks.stories.js +26 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-shared-mocks.stories.js +28 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-user.svelte +5 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/forms.stories.js +88 -14
- package/template/stories_svelte-kit-skeleton-ts/modules/hrefs.stories.js +42 -33
- package/template/stories_svelte-kit-skeleton-ts/modules/navigation.stories.js +52 -111
- package/template/stories_svelte-kit-skeleton-ts/modules/state.stories.js +45 -63
- package/dist/_browser-chunks/chunk-EB5JBDJD.js +0 -34
- package/dist/chunk-Curl48fh.d.ts +0 -120
- package/static/MockProvider.svelte +0 -123
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { applyAction } from '$app/forms';
|
|
2
|
+
import { goto, refreshAll } from '$app/navigation';
|
|
3
|
+
import { formAction } from '@storybook/sveltekit/forms.mock';
|
|
4
|
+
import { expect, fn, userEvent, waitFor } from 'storybook/test';
|
|
2
5
|
|
|
3
6
|
import Forms from './Forms.svelte';
|
|
4
7
|
|
|
@@ -7,20 +10,91 @@ export default {
|
|
|
7
10
|
component: Forms,
|
|
8
11
|
};
|
|
9
12
|
|
|
10
|
-
const
|
|
13
|
+
const subscribe = async (canvas) => {
|
|
14
|
+
await userEvent.type(canvas.getByLabelText('Email'), 'ada@example.com');
|
|
15
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Subscribe' }));
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const Success = {
|
|
19
|
+
beforeEach() {
|
|
20
|
+
formAction.mockResolvedValue({
|
|
21
|
+
type: 'success',
|
|
22
|
+
status: 200,
|
|
23
|
+
data: { email: 'ada@example.com' },
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
async play({ canvas }) {
|
|
27
|
+
await subscribe(canvas);
|
|
28
|
+
await expect(await canvas.findByText('Subscribed ada@example.com')).toBeInTheDocument();
|
|
29
|
+
await expect(formAction).toHaveBeenCalledOnce();
|
|
30
|
+
const [{ action, formData }] = formAction.mock.calls[0];
|
|
31
|
+
await expect(action).toBeInstanceOf(URL);
|
|
32
|
+
await expect(formData).toBeInstanceOf(FormData);
|
|
33
|
+
await expect(action.search).toBe('?/subscribe');
|
|
34
|
+
await expect(formData.get('email')).toBe('ada@example.com');
|
|
35
|
+
await expect(refreshAll).toHaveBeenCalled();
|
|
36
|
+
await expect(canvas.getByLabelText('Email')).toHaveValue('');
|
|
37
|
+
await expect(canvas.getByTestId('status')).toHaveTextContent('200');
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const Failure = {
|
|
42
|
+
beforeEach() {
|
|
43
|
+
formAction.mockResolvedValue({
|
|
44
|
+
type: 'failure',
|
|
45
|
+
status: 400,
|
|
46
|
+
data: { error: 'Invalid email' },
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
async play({ canvas }) {
|
|
50
|
+
await subscribe(canvas);
|
|
51
|
+
await expect(await canvas.findByRole('alert')).toHaveTextContent('Invalid email');
|
|
52
|
+
await expect(canvas.getByTestId('status')).toHaveTextContent('400');
|
|
53
|
+
await expect(canvas.getByLabelText('Email')).toHaveValue('ada@example.com');
|
|
54
|
+
await expect(refreshAll).not.toHaveBeenCalled();
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const Redirect = {
|
|
59
|
+
beforeEach() {
|
|
60
|
+
formAction.mockResolvedValue({ type: 'redirect', status: 303, location: '/thanks' });
|
|
61
|
+
},
|
|
62
|
+
async play({ canvas }) {
|
|
63
|
+
await subscribe(canvas);
|
|
64
|
+
await waitFor(() => expect(goto).toHaveBeenCalledWith('/thanks'));
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const ServerError = {
|
|
69
|
+
beforeEach() {
|
|
70
|
+
formAction.mockRejectedValue(new Error('Server down'));
|
|
71
|
+
},
|
|
72
|
+
async play({ canvas }) {
|
|
73
|
+
await subscribe(canvas);
|
|
74
|
+
await expect(await canvas.findByRole('alert')).toHaveTextContent('Error: Server down');
|
|
75
|
+
await expect(canvas.getByTestId('status')).toHaveTextContent('500');
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const Cancel = {
|
|
80
|
+
args: {
|
|
81
|
+
submit: fn(({ cancel }) => cancel()),
|
|
82
|
+
},
|
|
83
|
+
async play({ args, canvas }) {
|
|
84
|
+
await subscribe(canvas);
|
|
85
|
+
await waitFor(() => expect(args.submit).toHaveBeenCalled());
|
|
86
|
+
await expect(formAction).not.toHaveBeenCalled();
|
|
87
|
+
},
|
|
88
|
+
};
|
|
11
89
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const button = canvas.getByText('enhance');
|
|
16
|
-
button.click();
|
|
17
|
-
expect(enhance).toHaveBeenCalled();
|
|
90
|
+
export const CustomCallback = {
|
|
91
|
+
args: {
|
|
92
|
+
submit: () => async () => {},
|
|
18
93
|
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
94
|
+
async play({ canvas }) {
|
|
95
|
+
await subscribe(canvas);
|
|
96
|
+
await waitFor(() => expect(formAction).toHaveBeenCalled());
|
|
97
|
+
await expect(applyAction).not.toHaveBeenCalled();
|
|
98
|
+
await expect(canvas.getByLabelText('Email')).toHaveValue('ada@example.com');
|
|
25
99
|
},
|
|
26
100
|
};
|
|
@@ -1,52 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { page } from '$app/state';
|
|
2
|
+
import { link } from '@storybook/sveltekit/navigation.mock';
|
|
3
|
+
import { expect, userEvent } from 'storybook/test';
|
|
2
4
|
|
|
3
5
|
import Hrefs from './Hrefs.svelte';
|
|
4
6
|
|
|
5
7
|
export default {
|
|
6
8
|
title: 'stories/frameworks/sveltekit/modules/hrefs',
|
|
7
9
|
component: Hrefs,
|
|
10
|
+
beforeEach() {
|
|
11
|
+
// necessary to make the rendered output deterministic in CH snapshots
|
|
12
|
+
page.url = new URL('https://storybook.js.org');
|
|
13
|
+
},
|
|
8
14
|
};
|
|
9
15
|
|
|
10
|
-
export const
|
|
11
|
-
async play({
|
|
12
|
-
const canvas = within(canvasElement);
|
|
13
|
-
|
|
16
|
+
export const Links = {
|
|
17
|
+
async play({ canvas }) {
|
|
14
18
|
const initialUrl = window.location.toString();
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
await userEvent.click(canvas.getByText('/basic-href'));
|
|
21
|
+
await expect(link).toHaveBeenCalledWith('/basic-href', expect.any(MouseEvent));
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
'/deep/nested/link?with=true&multiple-params=200#and-an-id'
|
|
23
|
+
await userEvent.click(
|
|
24
|
+
canvas.getByText('/deep/nested/link?with=true&multiple-params=200#and-an-id')
|
|
21
25
|
);
|
|
22
|
-
|
|
26
|
+
await expect(link).toHaveBeenCalledWith(
|
|
27
|
+
'/deep/nested/link?with=true&multiple-params=200#and-an-id',
|
|
28
|
+
expect.any(MouseEvent)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
await userEvent.click(canvas.getByText('https://svelte.dev'));
|
|
32
|
+
await expect(link).toHaveBeenCalledWith('https://svelte.dev', expect.any(MouseEvent));
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
expect(finalUrl).toBe(initialUrl);
|
|
34
|
+
await expect(window.location.toString()).toBe(initialUrl);
|
|
26
35
|
},
|
|
27
36
|
};
|
|
28
37
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const Callbacks = {
|
|
35
|
-
parameters: {
|
|
36
|
-
sveltekit_experimental: {
|
|
37
|
-
hrefs: {
|
|
38
|
-
'/basic-href': basicStringMatch,
|
|
39
|
-
'/basic': noMatch,
|
|
40
|
-
'/deep/nested/link?with=true&multiple-params=200#and-an-id': exactStringMatch,
|
|
41
|
-
'nested/link\\?with': { callback: regexMatch, asRegex: true },
|
|
42
|
-
},
|
|
43
|
-
},
|
|
38
|
+
export const LinkImplementation = {
|
|
39
|
+
beforeEach() {
|
|
40
|
+
link.mockImplementation((href) => {
|
|
41
|
+
page.url = new URL(href, 'https://storybook.js.org');
|
|
42
|
+
});
|
|
44
43
|
},
|
|
45
|
-
play
|
|
46
|
-
await
|
|
47
|
-
expect(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
async play({ canvas }) {
|
|
45
|
+
await userEvent.click(canvas.getByText('/basic-href'));
|
|
46
|
+
await expect(canvas.getByTestId('current-url')).toHaveTextContent(
|
|
47
|
+
'https://storybook.js.org/basic-href'
|
|
48
|
+
);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const NewWindowLinks = {
|
|
53
|
+
async play({ canvas }) {
|
|
54
|
+
const newWindowLink = canvas.getByText('Opens in a new window');
|
|
55
|
+
// Stops the browser from opening the window. The listener on `window` runs after the framework's
|
|
56
|
+
// listener on `document`, so the framework sees the click as it is
|
|
57
|
+
window.addEventListener('click', (event) => event.preventDefault(), { once: true });
|
|
58
|
+
await userEvent.click(newWindowLink);
|
|
59
|
+
await expect(link).not.toHaveBeenCalled();
|
|
51
60
|
},
|
|
52
61
|
};
|
|
@@ -1,151 +1,92 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
goto,
|
|
3
|
+
invalidate,
|
|
4
|
+
invalidateAll,
|
|
5
|
+
pushState,
|
|
6
|
+
refreshAll,
|
|
7
|
+
replaceState,
|
|
8
|
+
} from '$app/navigation';
|
|
9
|
+
import { setAfterNavigate } from '@storybook/sveltekit/navigation.mock';
|
|
10
|
+
import { expect, fn, userEvent } from 'storybook/test';
|
|
2
11
|
|
|
3
12
|
import Navigation from './Navigation.svelte';
|
|
4
13
|
|
|
5
14
|
export default {
|
|
6
15
|
title: 'stories/frameworks/sveltekit/modules/navigation',
|
|
7
16
|
component: Navigation,
|
|
17
|
+
args: {
|
|
18
|
+
afterNavigateFn: fn(),
|
|
19
|
+
},
|
|
8
20
|
};
|
|
9
21
|
|
|
10
|
-
const goto = fn();
|
|
11
|
-
|
|
12
22
|
export const Goto = {
|
|
13
|
-
async play({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
button.click();
|
|
17
|
-
expect(goto).toHaveBeenCalledWith('/storybook-goto');
|
|
18
|
-
},
|
|
19
|
-
parameters: {
|
|
20
|
-
sveltekit_experimental: {
|
|
21
|
-
navigation: {
|
|
22
|
-
goto,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
23
|
+
async play({ canvas }) {
|
|
24
|
+
await userEvent.click(canvas.getByRole('button', { name: 'goto' }));
|
|
25
|
+
await expect(goto).toHaveBeenCalledWith('/storybook-goto');
|
|
25
26
|
},
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
const replaceState = fn();
|
|
29
|
-
|
|
30
29
|
export const ReplaceState = {
|
|
31
|
-
async play({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
button.click();
|
|
35
|
-
expect(replaceState).toHaveBeenCalledWith('/storybook-replace-state', {});
|
|
36
|
-
},
|
|
37
|
-
parameters: {
|
|
38
|
-
sveltekit_experimental: {
|
|
39
|
-
navigation: {
|
|
40
|
-
replaceState,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
30
|
+
async play({ canvas }) {
|
|
31
|
+
await userEvent.click(canvas.getByRole('button', { name: 'replaceState' }));
|
|
32
|
+
await expect(replaceState).toHaveBeenCalledWith('/storybook-replace-state', {});
|
|
43
33
|
},
|
|
44
34
|
};
|
|
45
35
|
|
|
46
|
-
const pushState = fn();
|
|
47
|
-
|
|
48
36
|
export const PushState = {
|
|
49
|
-
async play({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
button.click();
|
|
53
|
-
expect(pushState).toHaveBeenCalledWith('/storybook-push-state', {});
|
|
54
|
-
},
|
|
55
|
-
parameters: {
|
|
56
|
-
sveltekit_experimental: {
|
|
57
|
-
navigation: {
|
|
58
|
-
pushState,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
37
|
+
async play({ canvas }) {
|
|
38
|
+
await userEvent.click(canvas.getByRole('button', { name: 'pushState' }));
|
|
39
|
+
await expect(pushState).toHaveBeenCalledWith('/storybook-push-state', {});
|
|
61
40
|
},
|
|
62
41
|
};
|
|
63
42
|
|
|
64
|
-
export const DefaultActions = {};
|
|
65
|
-
|
|
66
|
-
const invalidate = fn();
|
|
67
|
-
|
|
68
43
|
export const Invalidate = {
|
|
69
|
-
async play({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
button.click();
|
|
73
|
-
expect(invalidate).toHaveBeenCalledWith('/storybook-invalidate');
|
|
74
|
-
},
|
|
75
|
-
parameters: {
|
|
76
|
-
sveltekit_experimental: {
|
|
77
|
-
navigation: {
|
|
78
|
-
invalidate,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
44
|
+
async play({ canvas }) {
|
|
45
|
+
await userEvent.click(canvas.getByRole('button', { name: 'invalidate', exact: true }));
|
|
46
|
+
await expect(invalidate).toHaveBeenCalledWith('/storybook-invalidate');
|
|
81
47
|
},
|
|
82
48
|
};
|
|
83
49
|
|
|
84
|
-
const invalidateAll = fn();
|
|
85
|
-
|
|
86
50
|
export const InvalidateAll = {
|
|
87
|
-
async play({
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
button.click();
|
|
91
|
-
expect(invalidateAll).toHaveBeenCalledWith();
|
|
92
|
-
},
|
|
93
|
-
parameters: {
|
|
94
|
-
sveltekit_experimental: {
|
|
95
|
-
navigation: {
|
|
96
|
-
invalidateAll,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
51
|
+
async play({ canvas }) {
|
|
52
|
+
await userEvent.click(canvas.getByRole('button', { name: 'invalidateAll' }));
|
|
53
|
+
await expect(invalidateAll).toHaveBeenCalledWith();
|
|
99
54
|
},
|
|
100
55
|
};
|
|
101
56
|
|
|
102
|
-
const refreshAll = fn();
|
|
103
|
-
|
|
104
57
|
export const RefreshAll = {
|
|
105
|
-
async play({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
button.click();
|
|
109
|
-
expect(refreshAll).toHaveBeenCalledWith();
|
|
110
|
-
},
|
|
111
|
-
parameters: {
|
|
112
|
-
sveltekit_experimental: {
|
|
113
|
-
navigation: {
|
|
114
|
-
refreshAll,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
58
|
+
async play({ canvas }) {
|
|
59
|
+
await userEvent.click(canvas.getByRole('button', { name: 'refreshAll' }));
|
|
60
|
+
await expect(refreshAll).toHaveBeenCalledWith();
|
|
117
61
|
},
|
|
118
62
|
};
|
|
119
63
|
|
|
120
|
-
const afterNavigateFn = fn();
|
|
121
|
-
|
|
122
64
|
export const AfterNavigate = {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
},
|
|
126
|
-
args
|
|
127
|
-
afterNavigateFn
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
},
|
|
136
|
-
},
|
|
65
|
+
beforeEach() {
|
|
66
|
+
setAfterNavigate({ type: 'link', from: { url: new URL('https://storybook.js.org/search') } });
|
|
67
|
+
},
|
|
68
|
+
async play({ args }) {
|
|
69
|
+
await expect(args.afterNavigateFn).toHaveBeenCalledWith(
|
|
70
|
+
expect.objectContaining({
|
|
71
|
+
type: 'link',
|
|
72
|
+
from: { url: new URL('https://storybook.js.org/search') },
|
|
73
|
+
to: null,
|
|
74
|
+
willUnload: false,
|
|
75
|
+
})
|
|
76
|
+
);
|
|
137
77
|
},
|
|
138
78
|
};
|
|
139
79
|
|
|
140
|
-
const defaultAfterNavigateFn = fn();
|
|
141
|
-
|
|
142
80
|
export const AfterNavigateDefault = {
|
|
143
|
-
async play() {
|
|
144
|
-
expect(
|
|
145
|
-
expect.objectContaining({
|
|
81
|
+
async play({ args }) {
|
|
82
|
+
await expect(args.afterNavigateFn).toHaveBeenCalledWith(
|
|
83
|
+
expect.objectContaining({
|
|
84
|
+
type: 'enter',
|
|
85
|
+
from: null,
|
|
86
|
+
to: null,
|
|
87
|
+
shallow: false,
|
|
88
|
+
willUnload: false,
|
|
89
|
+
})
|
|
146
90
|
);
|
|
147
91
|
},
|
|
148
|
-
args: {
|
|
149
|
-
afterNavigateFn: defaultAfterNavigateFn,
|
|
150
|
-
},
|
|
151
92
|
};
|
|
@@ -1,84 +1,66 @@
|
|
|
1
|
+
import { navigating, page, updated } from '$app/state';
|
|
2
|
+
import { expect } from 'storybook/test';
|
|
3
|
+
|
|
1
4
|
import State from './State.svelte';
|
|
2
5
|
|
|
3
6
|
export default {
|
|
4
7
|
title: 'stories/frameworks/sveltekit/modules/state',
|
|
5
8
|
component: State,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
page: {
|
|
10
|
-
url: new URL('https://storybook.js.org'), // necessary to make the rendered output deterministic in CH snapshots
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
},
|
|
9
|
+
beforeEach() {
|
|
10
|
+
// necessary to make the rendered output deterministic in CH snapshots
|
|
11
|
+
page.url = new URL('https://storybook.js.org');
|
|
14
12
|
},
|
|
15
13
|
};
|
|
16
14
|
|
|
17
15
|
export const Default = {};
|
|
18
16
|
|
|
19
17
|
export const Page = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
url: new URL('https://svelte.dev/docs/kit/'),
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
18
|
+
beforeEach() {
|
|
19
|
+
page.data = { test: 'passed' };
|
|
20
|
+
page.form = { framework: 'SvelteKit', rating: 5 };
|
|
21
|
+
page.params = { referrer: 'storybook' };
|
|
22
|
+
page.route = { id: '/framework/sveltekit' };
|
|
23
|
+
page.status = 200;
|
|
24
|
+
page.url = new URL('https://svelte.dev/docs/kit/');
|
|
25
|
+
},
|
|
26
|
+
async play({ canvas }) {
|
|
27
|
+
await expect(canvas.getByTestId('page')).toHaveTextContent('"test": "passed"');
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const PageUpdatedInPlay = {
|
|
32
|
+
async play({ canvas }) {
|
|
33
|
+
await expect(canvas.getByTestId('page')).not.toHaveTextContent('"test": "passed"');
|
|
34
|
+
page.data = { test: 'passed' };
|
|
35
|
+
await expect(await canvas.findByText(/"test": "passed"/)).toBeInTheDocument();
|
|
42
36
|
},
|
|
43
37
|
};
|
|
44
38
|
|
|
45
39
|
export const Navigating = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
params: {},
|
|
62
|
-
url: new URL('https://storybook.js.org'),
|
|
63
|
-
},
|
|
64
|
-
type: 'link',
|
|
65
|
-
willUnload: true,
|
|
66
|
-
delta: 3,
|
|
67
|
-
complete: Promise.resolve(),
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
40
|
+
beforeEach() {
|
|
41
|
+
navigating.from = {
|
|
42
|
+
params: { framework: 'SvelteKit' },
|
|
43
|
+
route: { id: '/framework/sveltekit' },
|
|
44
|
+
url: new URL('https://svelte.dev'),
|
|
45
|
+
};
|
|
46
|
+
navigating.to = {
|
|
47
|
+
params: {},
|
|
48
|
+
route: { id: '/storybook' },
|
|
49
|
+
url: new URL('https://storybook.js.org'),
|
|
50
|
+
};
|
|
51
|
+
navigating.type = 'link';
|
|
52
|
+
navigating.willUnload = true;
|
|
53
|
+
navigating.delta = 3;
|
|
54
|
+
navigating.complete = Promise.resolve();
|
|
71
55
|
},
|
|
72
56
|
};
|
|
73
57
|
|
|
74
58
|
export const Updated = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
},
|
|
59
|
+
beforeEach() {
|
|
60
|
+
updated.current = true;
|
|
61
|
+
},
|
|
62
|
+
async play({ canvas }) {
|
|
63
|
+
await expect(updated.check).toHaveBeenCalled();
|
|
64
|
+
await expect(canvas.getByTestId('updated')).toHaveTextContent('"current": true');
|
|
83
65
|
},
|
|
84
66
|
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__export
|
|
3
|
-
} from "./chunk-4BE7D4DS.js";
|
|
4
|
-
|
|
5
|
-
// src/preview.ts
|
|
6
|
-
var preview_exports = {};
|
|
7
|
-
__export(preview_exports, {
|
|
8
|
-
beforeEach: () => beforeEach,
|
|
9
|
-
decorators: () => decorators
|
|
10
|
-
});
|
|
11
|
-
import MockProvider from "@storybook/sveltekit/internal/MockProvider.svelte";
|
|
12
|
-
import {
|
|
13
|
-
setAppStateNavigating,
|
|
14
|
-
setAppStatePage,
|
|
15
|
-
setAppStateUpdated
|
|
16
|
-
} from "@storybook/sveltekit/internal/mocks/app/state.svelte.js";
|
|
17
|
-
var svelteKitMocksDecorator = (Story, ctx) => {
|
|
18
|
-
let svelteKitParameters = ctx.parameters?.sveltekit_experimental ?? {};
|
|
19
|
-
return {
|
|
20
|
-
Component: MockProvider,
|
|
21
|
-
props: {
|
|
22
|
-
svelteKitParameters
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}, decorators = [svelteKitMocksDecorator], beforeEach = async (ctx) => {
|
|
26
|
-
let svelteKitParameters = ctx.parameters?.sveltekit_experimental ?? {};
|
|
27
|
-
setAppStatePage(svelteKitParameters?.state?.page), setAppStateNavigating(svelteKitParameters?.state?.navigating), setAppStateUpdated(svelteKitParameters?.state?.updated);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
decorators,
|
|
32
|
-
beforeEach,
|
|
33
|
-
preview_exports
|
|
34
|
-
};
|