From 7a93d124fb5f55ae8df50dfb42903f4844a62c19 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 4 Feb 2020 21:52:57 +0100 Subject: [PATCH 1/2] chore: Bump jsdom to 15 --- package.json | 4 +- .../__snapshots__/wait-for-dom-change.js.snap | 13 +++++ src/__tests__/wait-for-dom-change.js | 58 +++---------------- 3 files changed, 24 insertions(+), 51 deletions(-) create mode 100644 src/__tests__/__snapshots__/wait-for-dom-change.js.snap diff --git a/package.json b/package.json index 87f2a314..55fd2640 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,8 @@ "jest-in-case": "^1.0.2", "jest-serializer-ansi": "^1.0.3", "jest-watch-select-projects": "^1.0.0", - "jsdom": "^15.1.1", - "kcd-scripts": "^1.7.0" + "jsdom": "^15.2.1", + "kcd-scripts": "^5.0.0" }, "eslintConfig": { "extends": "./node_modules/kcd-scripts/eslint.js", diff --git a/src/__tests__/__snapshots__/wait-for-dom-change.js.snap b/src/__tests__/__snapshots__/wait-for-dom-change.js.snap new file mode 100644 index 00000000..24911fb6 --- /dev/null +++ b/src/__tests__/__snapshots__/wait-for-dom-change.js.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`timers works with fake timers 1`] = ` +Array [ + MutationRecord {}, +] +`; + +exports[`timers works with real timers 1`] = ` +Array [ + MutationRecord {}, +] +`; diff --git a/src/__tests__/wait-for-dom-change.js b/src/__tests__/wait-for-dom-change.js index 730a4c20..0de51f49 100644 --- a/src/__tests__/wait-for-dom-change.js +++ b/src/__tests__/wait-for-dom-change.js @@ -18,22 +18,10 @@ test('waits for the dom to change in the document', async () => { setTimeout(() => container.firstChild.setAttribute('id', 'foo')) const mutationResult = await promise expect(mutationResult).toMatchInlineSnapshot(` -Array [ - Object { - "addedNodes": Array [], - "attributeName": "id", - "attributeNamespace": null, - "nextSibling": null, - "oldValue": null, - "previousSibling": null, - "removedNodes": Array [], - "target":
, - "type": "attributes", - }, -] -`) + Array [ + MutationRecord {}, + ] + `) }) test('waits for the dom to change in a specified container', async () => { @@ -42,22 +30,10 @@ test('waits for the dom to change in a specified container', async () => { setTimeout(() => container.firstChild.setAttribute('id', 'foo')) const mutationResult = await promise expect(mutationResult).toMatchInlineSnapshot(` -Array [ - Object { - "addedNodes": Array [], - "attributeName": "id", - "attributeNamespace": null, - "nextSibling": null, - "oldValue": null, - "previousSibling": null, - "removedNodes": Array [], - "target":
, - "type": "attributes", - }, -] -`) + Array [ + MutationRecord {}, + ] + `) }) describe('timers', () => { @@ -73,23 +49,7 @@ describe('timers', () => { jest.advanceTimersByTime(110) } - await expect(promise).resolves.toMatchInlineSnapshot(` - Array [ - Object { - "addedNodes": Array [], - "attributeName": "id", - "attributeNamespace": null, - "nextSibling": null, - "oldValue": null, - "previousSibling": null, - "removedNodes": Array [], - "target":
, - "type": "attributes", - }, - ] - `) + await expect(promise).resolves.toMatchSnapshot() } it('works with real timers', async () => { From 5390825077fe2ca67dc0371b2fac83c845e30ecf Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Mon, 10 Feb 2020 18:45:29 +0100 Subject: [PATCH 2/2] fix: serialize mutation records --- .../__snapshots__/wait-for-dom-change.js.snap | 28 +++++++++++++++++-- src/__tests__/wait-for-dom-change.js | 28 +++++++++++++++++-- tests/setup-env.js | 23 +++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/__tests__/__snapshots__/wait-for-dom-change.js.snap b/src/__tests__/__snapshots__/wait-for-dom-change.js.snap index 24911fb6..86faa06b 100644 --- a/src/__tests__/__snapshots__/wait-for-dom-change.js.snap +++ b/src/__tests__/__snapshots__/wait-for-dom-change.js.snap @@ -2,12 +2,36 @@ exports[`timers works with fake timers 1`] = ` Array [ - MutationRecord {}, + Object { + "addedNodes": NodeList [], + "attributeName": "id", + "attributeNamespace": null, + "nextSibling": null, + "oldValue": null, + "previousSibling": null, + "removedNodes": NodeList [], + "target":
, + "type": "attributes", + }, ] `; exports[`timers works with real timers 1`] = ` Array [ - MutationRecord {}, + Object { + "addedNodes": NodeList [], + "attributeName": "id", + "attributeNamespace": null, + "nextSibling": null, + "oldValue": null, + "previousSibling": null, + "removedNodes": NodeList [], + "target":
, + "type": "attributes", + }, ] `; diff --git a/src/__tests__/wait-for-dom-change.js b/src/__tests__/wait-for-dom-change.js index 0de51f49..5b181b64 100644 --- a/src/__tests__/wait-for-dom-change.js +++ b/src/__tests__/wait-for-dom-change.js @@ -19,7 +19,19 @@ test('waits for the dom to change in the document', async () => { const mutationResult = await promise expect(mutationResult).toMatchInlineSnapshot(` Array [ - MutationRecord {}, + Object { + "addedNodes": NodeList [], + "attributeName": "id", + "attributeNamespace": null, + "nextSibling": null, + "oldValue": null, + "previousSibling": null, + "removedNodes": NodeList [], + "target":
, + "type": "attributes", + }, ] `) }) @@ -31,7 +43,19 @@ test('waits for the dom to change in a specified container', async () => { const mutationResult = await promise expect(mutationResult).toMatchInlineSnapshot(` Array [ - MutationRecord {}, + Object { + "addedNodes": NodeList [], + "attributeName": "id", + "attributeNamespace": null, + "nextSibling": null, + "oldValue": null, + "previousSibling": null, + "removedNodes": NodeList [], + "target":
, + "type": "attributes", + }, ] `) }) diff --git a/tests/setup-env.js b/tests/setup-env.js index 93e6971b..5aefc00b 100644 --- a/tests/setup-env.js +++ b/tests/setup-env.js @@ -2,3 +2,26 @@ import '@testing-library/jest-dom/extend-expect' import jestSerializerAnsi from 'jest-serializer-ansi' expect.addSnapshotSerializer(jestSerializerAnsi) +// add serializer for MutationRecord +expect.addSnapshotSerializer({ + print: (record, serialize) => { + return serialize({ + addedNodes: record.addedNodes, + attributeName: record.attributeName, + attributeNamespace: record.attributeNamespace, + nextSibling: record.nextSibling, + oldValue: record.oldValue, + previousSibling: record.previousSibling, + removedNodes: record.removedNodes, + target: record.target, + type: record.type, + }) + }, + test: value => { + // list of records will stringify to the same value + return ( + Array.isArray(value) === false && + String(value) === '[object MutationRecord]' + ) + }, +})