This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.test.jsx
131 lines (109 loc) · 3.66 KB
/
index.test.jsx
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from 'react';
import * as testHelpers from '.';
import * as testHelpersFromSrc from './src/index';
const testHelpersExpectedExports = {
shouldMatchSnapshot: 'function',
isNull: 'function',
testUtilityPackages: 'function',
setWindowValue: 'function',
resetWindowValue: 'function',
suppressPropWarnings: 'function',
};
const expectedExports = { testHelpers: testHelpersExpectedExports };
const actualExports = { testHelpers };
const actualExportsFromSrc = { testHelpers: testHelpersFromSrc };
const ensureErrorWhenMissingExport = testHelperMethod => {
// missing export in the expected
const actualWithAll = { utility: { foo: {}, bar: {} } };
const expectedMissing = { utility: { bar: {} } };
expect(() => {
testHelperMethod(actualWithAll, expectedMissing, 'testing');
}).toThrowError(
"Missing value 'foo' in the expected export for 'testing/utility'.",
);
// missing export in the actual
const actualMissing = { utility: { foo: {} } };
const expectedWithAll = { utility: { bar: {}, foo: {} } };
expect(() => {
testHelperMethod(actualMissing, expectedWithAll, 'testing');
}).toThrowError(
"Missing value 'bar' in the actual export for 'testing/utility'.",
);
};
const ensureErrorWhenMissingFileDefinition = testHelperMethod => {
// missing export in the expected
const actualWithAll = {
utilityOne: { key: {} },
utilityTwo: { key: {} },
};
const expectedMissing = {
utilityOne: { key: {} },
};
expect(() => {
testHelperMethod(actualWithAll, expectedMissing, 'testing');
}).toThrowError(
"Missing value 'utilityTwo' in the expected utilities for 'testing'.",
);
// missing export in the actual
const actualMissing = {
utilityOne: { key: {} },
};
const expectedWithAll = {
utilityOne: { key: {} },
utilityTwo: { key: {} },
};
expect(() => {
testHelperMethod(actualMissing, expectedWithAll, 'testing');
}).toThrowError(
"Missing value 'utilityTwo' in the actual utilities for 'testing'.",
);
};
describe('Psammead test helpers', () => {
it('should test all the utility exports exist and are the correct type', () => {
testHelpers.testUtilityPackages(
actualExports,
expectedExports,
'psammead-test-helpers',
);
});
it('should test all the utility exports exist and are the correct type when coming from src/', () => {
testHelpers.testUtilityPackages(
actualExportsFromSrc,
expectedExports,
'psammead-test-helpers',
);
});
it('should error if expectedExport is missing an export compared to the actual export', () => {
ensureErrorWhenMissingExport(testHelpers.testUtilityPackages);
});
it('should error if expectedExport is missing an export compared to the actual export when coming from /src', () => {
ensureErrorWhenMissingExport(testHelpersFromSrc.testUtilityPackages);
});
it('should error if file definition is missing in the expectation', () => {
ensureErrorWhenMissingFileDefinition(testHelpers.testUtilityPackages);
});
it('should error if file definition is missing in the expectation when coming from /src', () => {
ensureErrorWhenMissingFileDefinition(
testHelpersFromSrc.testUtilityPackages,
);
});
const ExampleComponent = () => (
<main>
<h1>Hello I am a test component</h1>
</main>
);
testHelpers.shouldMatchSnapshot(
'should match the snapshot for the test component',
<ExampleComponent />,
);
const ExampleFragment = () => (
<>
<h1>Hello I am a test component</h1>
<p>I am some test text.</p>
</>
);
testHelpers.shouldMatchSnapshot(
'should match the snapshot for the test component',
<ExampleFragment />,
);
});