generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 64
/
getStorybookMain.test.ts
44 lines (34 loc) 路 1.29 KB
/
getStorybookMain.test.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
import { getStorybookMain, resetStorybookMainCache } from './getStorybookMain';
import * as coreCommon from '@storybook/core-common';
jest.mock('@storybook/core-common');
describe('getStorybookMain', () => {
beforeEach(() => {
resetStorybookMainCache();
});
it('should throw an error if no configuration is found', () => {
expect(() => getStorybookMain('.storybook')).toThrowErrorMatchingSnapshot();
});
describe('no stories', () => {
it('should throw an error if no stories are defined', () => {
jest.spyOn(coreCommon, 'serverRequire').mockImplementation(() => ({}));
expect(() => getStorybookMain('.storybook')).toThrowErrorMatchingSnapshot();
});
it('should throw an error if stories list is empty', () => {
jest.spyOn(coreCommon, 'serverRequire').mockImplementation(() => ({ stories: [] }));
expect(() => getStorybookMain('.storybook')).toThrowErrorMatchingSnapshot();
});
});
it('should return mainjs', () => {
const mockedMain = {
stories: [
{
directory: '../stories/basic',
titlePrefix: 'Example',
},
],
};
jest.spyOn(coreCommon, 'serverRequire').mockImplementation(() => mockedMain);
const res = getStorybookMain('.storybook');
expect(res).toMatchObject(mockedMain);
});
});