-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
stories-app.spec.ts
67 lines (58 loc) · 1.9 KB
/
stories-app.spec.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Tree } from '@nrwl/devkit';
import storiesGenerator from './stories';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import applicationGenerator from '../application/application';
import { Linter } from '@nrwl/linter';
import { reactNativeComponentGenerator } from '../component/component';
describe('react:stories for applications', () => {
let appTree: Tree;
beforeEach(async () => {
appTree = await createTestUIApp('test-ui-app');
});
it('should create the stories', async () => {
await reactNativeComponentGenerator(appTree, {
name: 'another-cmp',
project: 'test-ui-app',
});
await storiesGenerator(appTree, {
project: 'test-ui-app',
});
expect(appTree.exists('apps/test-ui-app/src/app/App.tsx')).toBeTruthy();
expect(
appTree.exists('apps/test-ui-app/src/app/App.stories.tsx')
).toBeTruthy();
expect(
appTree.exists(
'apps/test-ui-app/src/app/another-cmp/another-cmp.stories.tsx'
)
).toBeTruthy();
});
it('should ignore files that do not contain components', async () => {
// create another component
appTree.write(
'apps/test-ui-app/src/app/some-utils.js',
`export const add = (a: number, b: number) => a + b;`
);
await storiesGenerator(appTree, {
project: 'test-ui-app',
});
// should just create the story and not error, even though there's a js file
// not containing any react component
expect(
appTree.exists('apps/test-ui-app/src/app/App.stories.tsx')
).toBeTruthy();
});
});
export async function createTestUIApp(libName: string): Promise<Tree> {
let appTree = createTreeWithEmptyWorkspace();
appTree.write('.gitignore', '');
await applicationGenerator(appTree, {
linter: Linter.EsLint,
skipFormat: false,
style: 'css',
unitTestRunner: 'none',
name: libName,
install: false,
});
return appTree;
}