-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
72 lines (61 loc) · 2.83 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { createDirectoryAndFiles } from "./fileCreators";
import fs from 'fs';
import os from 'os';
import rimraf from 'rimraf';
import fsify from 'fsify';
describe('fileCreators', () => {
describe('createDirectoryAndFiles', () => {
const tempDir = os.tmpdir();
const fsifier = fsify(
{
cwd: tempDir,
}
);
afterEach( async () => {
const testDir = `${tempDir}/MyComponent`;
rimraf.sync(testDir);
});
it('creates directory in path', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
expect(fs.existsSync(`${tempDir}/MyComponent`)).toBe(true);
});
it('creates component typescript file', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
expect(fs.existsSync(`${tempDir}/MyComponent/MyComponent.tsx`)).toBe(true);
});
it('creates test file', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
expect(fs.existsSync(`${tempDir}/MyComponent/MyComponent.test.tsx`)).toBe(true);
});
it('creates sass file', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
expect(fs.existsSync(`${tempDir}/MyComponent/MyComponent.scss`)).toBe(true);
})
it('does not add extra level of indentation', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
const fileContents = fs.readFileSync(`${tempDir}/MyComponent/MyComponent.tsx`, 'utf8');
expect(fileContents).not.toContain(` import`);
});
describe('test file', () => {
it('includes test for rendering component', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
const fileContents = fs.readFileSync(`${tempDir}/MyComponent/MyComponent.test.tsx`, 'utf8');
expect(fileContents).toContain(`expect(container).toBeDefined();`);
});
});
describe('scss file', () => {
it('includes component class', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
const fileContents = fs.readFileSync(`${tempDir}/MyComponent/MyComponent.scss`, 'utf8');
expect(fileContents).toContain(`MyComponent {`);
});
});
describe('code file', () => {
it('includes function component definition', async () => {
await createDirectoryAndFiles(fsifier, 'MyComponent');
const fileContents = fs.readFileSync(`${tempDir}/MyComponent/MyComponent.tsx`, 'utf8');
expect(fileContents).toContain(`export const MyComponent:FunctionComponent<MyComponentProps> = ({}) => {`);
});
});
});
});