Skip to content

Commit 462e2a5

Browse files
committed
fix: serialize mutation records
1 parent 7a93d12 commit 462e2a5

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22

33
exports[`timers works with fake timers 1`] = `
44
Array [
5-
MutationRecord {},
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+
},
617
]
718
`;
819

920
exports[`timers works with real timers 1`] = `
1021
Array [
11-
MutationRecord {},
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+
},
1234
]
1335
`;

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ test('waits for the dom to change in the document', async () => {
1919
const mutationResult = await promise
2020
expect(mutationResult).toMatchInlineSnapshot(`
2121
Array [
22-
MutationRecord {},
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+
},
2334
]
2435
`)
2536
})
@@ -31,7 +42,18 @@ test('waits for the dom to change in a specified container', async () => {
3142
const mutationResult = await promise
3243
expect(mutationResult).toMatchInlineSnapshot(`
3344
Array [
34-
MutationRecord {},
45+
Object {
46+
"addedNodes": NodeList [],
47+
"attributeName": "id",
48+
"attributeNamespace": null,
49+
"nextSibling": null,
50+
"oldValue": null,
51+
"previousSibling": null,
52+
"removedNodes": NodeList [],
53+
"target": <div
54+
id="foo"
55+
/>,
56+
},
3557
]
3658
`)
3759
})

tests/setup-env.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,25 @@ 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+
})
18+
},
19+
test: value => {
20+
// list of records will stringify to the same value
21+
return (
22+
Array.isArray(value) === false &&
23+
String(value) === '[object MutationRecord]'
24+
)
25+
},
26+
})

0 commit comments

Comments
 (0)