Skip to content

Commit 56fd45f

Browse files
committed
Add tests for Preact 8!
1 parent b44c1b9 commit 56fd45f

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"env",
4646
{
4747
"targets": {
48-
"node": true
48+
"node": "current"
4949
}
5050
}
5151
]
@@ -86,7 +86,7 @@
8686
"author": "Jason Miller <[email protected]>",
8787
"license": "MIT",
8888
"devDependencies": {
89-
"babel-jest": "^21.2.0",
89+
"babel-jest": "^24.3.1",
9090
"babel-plugin-transform-react-jsx": "^6.24.1",
9191
"babel-preset-env": "^1.6.1",
9292
"bundlesize": "^0.17.1",
@@ -96,7 +96,7 @@
9696
"eslint": "^4.16.0",
9797
"eslint-config-developit": "^1.1.1",
9898
"gzip-size-cli": "^2.1.0",
99-
"jest": "^23.6.0",
99+
"jest": "^24.3.1",
100100
"microbundle": "^0.11.0",
101101
"npm-run-all": "^4.1.2",
102102
"preact": "^10.0.0-alpha.1",

test/fixtures/preact-8.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/preact/preact-8.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This runs the Preact tests against a copy of Preact 8.4.2.
2+
jest.isolateModules(() => {
3+
const preact = require('../fixtures/preact-8.min.js');
4+
jest.setMock('preact', preact);
5+
6+
// Patch Preact 8's render to work like Preact 10:
7+
let render = preact.render;
8+
preact.render = (vnode, parent) => parent._root = render(vnode, parent, parent._root);
9+
10+
global.IS_PREACT_8 = true;
11+
require('./preact.test');
12+
delete global.IS_PREACT_8;
13+
});

test/preact/preact.test.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { Provider, connect } from '../../src/integrations/preact';
44

55
const sleep = ms => new Promise( r => setTimeout(r, ms) );
66

7-
describe('integrations/preact', () => {
7+
const NO_CHILDREN = global.IS_PREACT_8 ? expect.anything() : undefined;
8+
9+
describe(`integrations/preact${global.IS_PREACT_8 ? '-8' : ''}`, () => {
810
describe('<Provider>', () => {
911
afterEach(() => {
1012
render(null, document.body);
@@ -35,9 +37,8 @@ describe('integrations/preact', () => {
3537
});
3638

3739
describe('connect()', () => {
38-
afterEach(async () => {
40+
afterEach(() => {
3941
render(null, document.body);
40-
await sleep(1);
4142
});
4243

4344
it('should pass mapped state as props', () => {
@@ -52,7 +53,7 @@ describe('integrations/preact', () => {
5253
document.body
5354
);
5455
expect(Child).toHaveBeenCalledWith(
55-
{ a: 'b', store },
56+
{ a: 'b', store, children: NO_CHILDREN },
5657
expect.anything()
5758
);
5859
expect(store.subscribe).toBeCalled();
@@ -70,7 +71,7 @@ describe('integrations/preact', () => {
7071
document.body
7172
);
7273
expect(Child).toHaveBeenCalledWith(
73-
{ a: 'b', b: 'c', store },
74+
{ a: 'b', b: 'c', store, children: NO_CHILDREN },
7475
expect.anything()
7576
);
7677
expect(store.subscribe).toBeCalled();
@@ -122,7 +123,7 @@ describe('integrations/preact', () => {
122123

123124
expect(store.subscribe).toBeCalledWith(expect.any(Function));
124125
expect(Child).toHaveBeenCalledWith(
125-
{ store },
126+
{ store, children: NO_CHILDREN },
126127
expect.anything()
127128
);
128129

@@ -131,7 +132,7 @@ describe('integrations/preact', () => {
131132
store.setState({ a: 'b' });
132133
await sleep(1);
133134
expect(Child).toHaveBeenCalledWith(
134-
{ a: 'b', store },
135+
{ a: 'b', store, children: NO_CHILDREN },
135136
expect.anything()
136137
);
137138

@@ -158,20 +159,18 @@ describe('integrations/preact', () => {
158159
}));
159160

160161
const ConnectedChild = connect(mapStateToProps)(Child);
161-
const ref = {};
162162
render(
163163
<Provider store={store}>
164-
<ConnectedChild ref={ref} />
164+
<ConnectedChild />
165165
</Provider>,
166166
document.body
167167
);
168-
let c = ref.current;
169168

170169
expect(mapStateToProps).toHaveBeenCalledTimes(1);
171-
expect(mapStateToProps).toHaveBeenCalledWith({}, { });
170+
expect(mapStateToProps).toHaveBeenCalledWith({}, { children: NO_CHILDREN });
172171
// first render calls mapStateToProps
173172
expect(Child).toHaveBeenCalledWith(
174-
{ mappings: 1, store },
173+
{ mappings: 1, store, children: NO_CHILDREN },
175174
expect.anything()
176175
);
177176

@@ -186,10 +185,10 @@ describe('integrations/preact', () => {
186185
);
187186

188187
expect(mapStateToProps).toHaveBeenCalledTimes(1);
189-
expect(mapStateToProps).toHaveBeenCalledWith({ }, { a: 'b' });
188+
expect(mapStateToProps).toHaveBeenCalledWith({ }, { a: 'b', children: NO_CHILDREN });
190189
// outer props were changed
191190
expect(Child).toHaveBeenCalledWith(
192-
{ mappings: 2, a: 'b', store },
191+
{ mappings: 2, a: 'b', store, children: NO_CHILDREN },
193192
expect.anything()
194193
);
195194

@@ -204,11 +203,11 @@ describe('integrations/preact', () => {
204203
);
205204

206205
expect(mapStateToProps).toHaveBeenCalledTimes(1);
207-
expect(mapStateToProps).toHaveBeenCalledWith({ }, { a: 'b' });
206+
expect(mapStateToProps).toHaveBeenCalledWith({ }, { a: 'b', children: NO_CHILDREN });
208207

209208
// re-rendered, but outer props were not changed
210209
expect(Child).toHaveBeenCalledWith(
211-
{ mappings: 3, a: 'b', store },
210+
{ mappings: 3, a: 'b', store, children: NO_CHILDREN },
212211
expect.anything()
213212
);
214213
});

0 commit comments

Comments
 (0)