From 4df628895e7aa2c69e08853ff7a1d3f198aae9ff Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Mon, 13 Nov 2017 12:53:23 +1100 Subject: [PATCH 1/3] failing specs --- test/core/__snapshots__/snapshot.spec.js.snap | 26 +++++++++++ test/core/snapshot.spec.js | 45 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/test/core/__snapshots__/snapshot.spec.js.snap b/test/core/__snapshots__/snapshot.spec.js.snap index 47227c1..029fd76 100644 --- a/test/core/__snapshots__/snapshot.spec.js.snap +++ b/test/core/__snapshots__/snapshot.spec.js.snap @@ -1,3 +1,23 @@ +exports[`test fails if new is null but old is not 1`] = ` +Object { + "actual": "null", + "count": 1, + "diff": "", + "expected": "
", + "pass": false, +} +`; + +exports[`test fails if old was null but new is not 1`] = ` +Object { + "actual": "
", + "count": 1, + "diff": "", + "expected": "null", + "pass": false, +} +`; + exports[`test fails if the type changes 1`] = ` Object { "actual": " @@ -19,3 +39,9 @@ Object { "pass": false, } `; + +exports[`test passes if new and old are null 1`] = ` +Object { + "pass": true, +} +`; diff --git a/test/core/snapshot.spec.js b/test/core/snapshot.spec.js index a093fc2..0e90b1b 100644 --- a/test/core/snapshot.spec.js +++ b/test/core/snapshot.spec.js @@ -36,3 +36,48 @@ test('does not fail if update is true', () => { expect(result).toEqual({ pass: true }) }) + +test('passes if null, first time', () => { + const tree = null + const result = snapshot('name', tree) + + expect(result).toEqual({ pass: true }) +}) + +test('passes if new and old are null', () => { + snapshot('name', null) + const result = snapshot('name1', null) + + expect(result).toMatchSnapshot() +}) + +test('fails if old was null but new is not', () => { + const name = 'old-was-null' + snapshot(name, null) + + const tree = { type: 'div' } + const result = snapshot(name, tree) + + expect(result).toMatchSnapshot() +}) + +test('fails if new is null but old is not', () => { + const name = 'new-is-null' + const tree = { type: 'div' } + snapshot(name, tree) + + const result = snapshot(name, null) + + expect(result).toMatchSnapshot() +}) + +test('null tree does not fail if update is true', () => { + const name = 'null-with-update' + const tree = { type: 'div' } + snapshot(name, tree) + + const update = true + const result = snapshot(name, null, update) + + expect(result).toEqual({ pass: true }) +}) From ea8f812c50e1e3b771ef230d18c4e3602d8034e8 Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Mon, 13 Nov 2017 12:55:02 +1100 Subject: [PATCH 2/3] updates to pass specs --- src/core/snapshot.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/snapshot.js b/src/core/snapshot.js index 7134983..9c2382d 100644 --- a/src/core/snapshot.js +++ b/src/core/snapshot.js @@ -10,14 +10,16 @@ const typeOf = { value: Symbol.for('react.test.json') } const cleanUp = (result) => { result.actual = result.actual.trim() result.expected = result.expected.trim() - result.diff = result.diff.replace(/\n[ ]+\n/g, '\n\n') + result.diff = (result.diff || '').replace(/\n[ ]+\n/g, '\n\n') } const snapshot = (name, tree, update) => { const destination = path.resolve(base, `${name}.snap`) const state = new SnapshotState(null, update, destination) - Object.defineProperty(tree, '$$typeof', typeOf) + if (tree) { + Object.defineProperty(tree, '$$typeof', typeOf) + } const result = state.match(name, tree) state.save(update) From 4d9fb2cd8fbb1d1bd122eb9a7c0f0f7b5876bdaa Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Mon, 13 Nov 2017 13:00:10 +1100 Subject: [PATCH 3/3] fixed typo in spec --- test/core/snapshot.spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/core/snapshot.spec.js b/test/core/snapshot.spec.js index 0e90b1b..0df052f 100644 --- a/test/core/snapshot.spec.js +++ b/test/core/snapshot.spec.js @@ -45,8 +45,9 @@ test('passes if null, first time', () => { }) test('passes if new and old are null', () => { - snapshot('name', null) - const result = snapshot('name1', null) + const name = 'both-null' + snapshot(name, null) + const result = snapshot(name, null) expect(result).toMatchSnapshot() })