Skip to content

Commit cf57dcd

Browse files
authored
chore: Bump jsdom to 15 (#447)
* chore: Bump jsdom to 15 * fix: serialize mutation records
1 parent 1ee3e7a commit cf57dcd

File tree

4 files changed

+95
-51
lines changed

4 files changed

+95
-51
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"jest-in-case": "^1.0.2",
5353
"jest-serializer-ansi": "^1.0.3",
5454
"jest-watch-select-projects": "^1.0.0",
55-
"jsdom": "^15.1.1",
56-
"kcd-scripts": "^1.7.0"
55+
"jsdom": "^15.2.1",
56+
"kcd-scripts": "^5.0.0"
5757
},
5858
"eslintConfig": {
5959
"extends": "./node_modules/kcd-scripts/eslint.js",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`timers works with fake timers 1`] = `
4+
Array [
5+
Object {
6+
"addedNodes": NodeList [],
7+
"attributeName": "id",
8+
"attributeNamespace": null,
9+
"nextSibling": null,
10+
"oldValue": null,
11+
"previousSibling": null,
12+
"removedNodes": NodeList [],
13+
"target": <div
14+
id="foo"
15+
/>,
16+
"type": "attributes",
17+
},
18+
]
19+
`;
20+
21+
exports[`timers works with real timers 1`] = `
22+
Array [
23+
Object {
24+
"addedNodes": NodeList [],
25+
"attributeName": "id",
26+
"attributeNamespace": null,
27+
"nextSibling": null,
28+
"oldValue": null,
29+
"previousSibling": null,
30+
"removedNodes": NodeList [],
31+
"target": <div
32+
id="foo"
33+
/>,
34+
"type": "attributes",
35+
},
36+
]
37+
`;

src/__tests__/wait-for-dom-change.js

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ test('waits for the dom to change in the document', async () => {
1818
setTimeout(() => container.firstChild.setAttribute('id', 'foo'))
1919
const mutationResult = await promise
2020
expect(mutationResult).toMatchInlineSnapshot(`
21-
Array [
22-
Object {
23-
"addedNodes": Array [],
24-
"attributeName": "id",
25-
"attributeNamespace": null,
26-
"nextSibling": null,
27-
"oldValue": null,
28-
"previousSibling": null,
29-
"removedNodes": Array [],
30-
"target": <div
31-
id="foo"
32-
/>,
33-
"type": "attributes",
34-
},
35-
]
36-
`)
21+
Array [
22+
Object {
23+
"addedNodes": NodeList [],
24+
"attributeName": "id",
25+
"attributeNamespace": null,
26+
"nextSibling": null,
27+
"oldValue": null,
28+
"previousSibling": null,
29+
"removedNodes": NodeList [],
30+
"target": <div
31+
id="foo"
32+
/>,
33+
"type": "attributes",
34+
},
35+
]
36+
`)
3737
})
3838

3939
test('waits for the dom to change in a specified container', async () => {
@@ -42,22 +42,22 @@ test('waits for the dom to change in a specified container', async () => {
4242
setTimeout(() => container.firstChild.setAttribute('id', 'foo'))
4343
const mutationResult = await promise
4444
expect(mutationResult).toMatchInlineSnapshot(`
45-
Array [
46-
Object {
47-
"addedNodes": Array [],
48-
"attributeName": "id",
49-
"attributeNamespace": null,
50-
"nextSibling": null,
51-
"oldValue": null,
52-
"previousSibling": null,
53-
"removedNodes": Array [],
54-
"target": <div
55-
id="foo"
56-
/>,
57-
"type": "attributes",
58-
},
59-
]
60-
`)
45+
Array [
46+
Object {
47+
"addedNodes": NodeList [],
48+
"attributeName": "id",
49+
"attributeNamespace": null,
50+
"nextSibling": null,
51+
"oldValue": null,
52+
"previousSibling": null,
53+
"removedNodes": NodeList [],
54+
"target": <div
55+
id="foo"
56+
/>,
57+
"type": "attributes",
58+
},
59+
]
60+
`)
6161
})
6262

6363
describe('timers', () => {
@@ -73,23 +73,7 @@ describe('timers', () => {
7373
jest.advanceTimersByTime(110)
7474
}
7575

76-
await expect(promise).resolves.toMatchInlineSnapshot(`
77-
Array [
78-
Object {
79-
"addedNodes": Array [],
80-
"attributeName": "id",
81-
"attributeNamespace": null,
82-
"nextSibling": null,
83-
"oldValue": null,
84-
"previousSibling": null,
85-
"removedNodes": Array [],
86-
"target": <div
87-
id="foo"
88-
/>,
89-
"type": "attributes",
90-
},
91-
]
92-
`)
76+
await expect(promise).resolves.toMatchSnapshot()
9377
}
9478

9579
it('works with real timers', async () => {

tests/setup-env.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,26 @@ import '@testing-library/jest-dom/extend-expect'
22
import jestSerializerAnsi from 'jest-serializer-ansi'
33

44
expect.addSnapshotSerializer(jestSerializerAnsi)
5+
// add serializer for MutationRecord
6+
expect.addSnapshotSerializer({
7+
print: (record, serialize) => {
8+
return serialize({
9+
addedNodes: record.addedNodes,
10+
attributeName: record.attributeName,
11+
attributeNamespace: record.attributeNamespace,
12+
nextSibling: record.nextSibling,
13+
oldValue: record.oldValue,
14+
previousSibling: record.previousSibling,
15+
removedNodes: record.removedNodes,
16+
target: record.target,
17+
type: record.type,
18+
})
19+
},
20+
test: value => {
21+
// list of records will stringify to the same value
22+
return (
23+
Array.isArray(value) === false &&
24+
String(value) === '[object MutationRecord]'
25+
)
26+
},
27+
})

0 commit comments

Comments
 (0)