mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-19 05:02:40 +08:00
Add unit test for TS - CSF source loader
This commit is contained in:
parent
7c63dc94b8
commit
e878516e65
19
__mocks__/inject-decorator.ts.csf.txt
Normal file
19
__mocks__/inject-decorator.ts.csf.txt
Normal file
@ -0,0 +1,19 @@
|
||||
import React from "react";
|
||||
import { action } from "@storybook/addon-actions";
|
||||
import { Button } from "@storybook/react/demo";
|
||||
|
||||
export default {
|
||||
title: "Button"
|
||||
};
|
||||
|
||||
export const text = () => (
|
||||
<Button onClick={action("clicked")}>Hello Button</Button>
|
||||
);
|
||||
|
||||
export const emoji = () => (
|
||||
<Button onClick={action("clicked")}>
|
||||
<span role="img" aria-label="so cool">
|
||||
😀 😎 👍 💯
|
||||
</span>
|
||||
</Button>
|
||||
);
|
@ -0,0 +1,25 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`inject-decorator positive - ts - csf works 1`] = `
|
||||
"var addSourceDecorator = require(\\"@storybook/source-loader/preview\\").addSource;
|
||||
import React from \\"react\\";
|
||||
import { action } from \\"@storybook/addon-actions\\";
|
||||
import { Button } from \\"@storybook/react/demo\\";
|
||||
|
||||
export default {parameters: {\\"storySource\\":{\\"source\\":\\"import React from \\\\\\"react\\\\\\";\\\\nimport { action } from \\\\\\"@storybook/addon-actions\\\\\\";\\\\nimport { Button } from \\\\\\"@storybook/react/demo\\\\\\";\\\\n\\\\nexport default {\\\\n title: \\\\\\"Button\\\\\\"\\\\n};\\\\n\\\\nexport const text = () => (\\\\n <Button onClick={action(\\\\\\"clicked\\\\\\")}>Hello Button</Button>\\\\n);\\\\n\\\\nexport const emoji = () => (\\\\n <Button onClick={action(\\\\\\"clicked\\\\\\")}>\\\\n <span role=\\\\\\"img\\\\\\" aria-label=\\\\\\"so cool\\\\\\">\\\\n 😀 😎 👍 💯\\\\n </span>\\\\n </Button>\\\\n);\\\\n\\",\\"locationsMap\\":{}},},
|
||||
title: \\"Button\\"
|
||||
};
|
||||
|
||||
export const text = addSourceDecorator(() => (
|
||||
<Button onClick={action(\\"clicked\\")}>Hello Button</Button>
|
||||
), {__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__});;
|
||||
|
||||
export const emoji = addSourceDecorator(() => (
|
||||
<Button onClick={action(\\"clicked\\")}>
|
||||
<span role=\\"img\\" aria-label=\\"so cool\\">
|
||||
😀 😎 👍 💯
|
||||
</span>
|
||||
</Button>
|
||||
), {__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__});
|
||||
"
|
||||
`;
|
@ -0,0 +1,22 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import injectDecorator from './inject-decorator';
|
||||
|
||||
describe('inject-decorator', () => {
|
||||
describe('positive - ts - csf', () => {
|
||||
const mockFilePath = './__mocks__/inject-decorator.ts.csf.txt';
|
||||
const source = fs.readFileSync(mockFilePath, 'utf-8');
|
||||
const result = injectDecorator(source, path.resolve(__dirname, mockFilePath), {
|
||||
parser: 'typescript',
|
||||
});
|
||||
|
||||
it('includes storySource parameter in the default exported object', () => {
|
||||
expect(result.source).toMatchSnapshot();
|
||||
expect(result.source).toEqual(
|
||||
expect.stringContaining(
|
||||
'export default {parameters: {"storySource":{"source":"import React from'
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user