From 147cf400a43d531e9da85cf9a29791170d5b7295 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Tue, 2 Oct 2018 19:55:22 +0200 Subject: [PATCH] Added basic tests --- jest.config.js | 1 + .../__snapshots__/index.test.js.snap | 37 +++++++ src/reducers/utils/__tests__/index.test.js | 99 +++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 src/reducers/utils/__tests__/__snapshots__/index.test.js.snap create mode 100644 src/reducers/utils/__tests__/index.test.js diff --git a/jest.config.js b/jest.config.js index d9c12451..3f20eda3 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,6 +12,7 @@ module.exports = { ], collectCoverageFrom: [ 'utils/**.js', + 'reducers/utils/**.js', ], setupFiles: [ './support/setupJest.js', diff --git a/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap b/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap new file mode 100644 index 00000000..f1703259 --- /dev/null +++ b/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap @@ -0,0 +1,37 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`reducers utils observeChanges shoud be the same - returns false 1`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 2`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 3`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 4`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 5`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 6`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 7`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 8`] = `false`; + +exports[`reducers utils observeChanges shoud be the same - returns false 9`] = `false`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 1`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 2`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 3`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 4`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 5`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 6`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 7`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 8`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 9`] = `true`; diff --git a/src/reducers/utils/__tests__/index.test.js b/src/reducers/utils/__tests__/index.test.js new file mode 100644 index 00000000..dc937181 --- /dev/null +++ b/src/reducers/utils/__tests__/index.test.js @@ -0,0 +1,99 @@ +import * as reducerUtils from '../index'; + +describe('reducers utils', () => { + it('observeChanges shoud be the same - returns false', () => { + const data = [ + // example of same data (false) + { + pervious: {}, + current: {}, + }, + { + pervious: 1, + current: 1, + }, + { + pervious: [], + current: [], + }, + { + pervious: 'a', + current: 'a', + }, + { + pervious: { test: 1 }, + current: { test: 1 }, + }, + { + pervious: { test: { test: 1 } }, + current: { test: { test: 1 } }, + }, + { + pervious: { test: { test: [1, 2, 3] } }, + current: { test: { test: [1, 2, 3] } }, + }, + { + pervious: { test: { test: [1, { test: 1 }, 3] } }, + current: { test: { test: [1, { test: 1 }, 3] } }, + }, + { + pervious: { test: { test: [1, { test: 1 }, { test: 3, test1: { test: 3 } }] } }, + current: { test: { test: [1, { test: 1 }, { test: 3, test1: { test: 3 } }] } }, + }, + ]; + + data.forEach((item) => { + expect(reducerUtils.observeChanges( + item.pervious, item.current, + )).toMatchSnapshot(); + }); + }); + + it('observeChanges shoul NOT be the same - returns true', () => { + const data = [ + // example of different data (true) + { + pervious: { test: 1 }, + current: {}, + }, + { + pervious: [{}], + current: [], + }, + { + pervious: 'a', + current: 'b', + }, + { + pervious: 1, + current: '1', + }, + { + pervious: { test: 1 }, + current: { test: 2 }, + }, + { + pervious: { test: { test: 1 } }, + current: { test: { test: 2 } }, + }, + { + pervious: { test: { test: [1, 2, 3] } }, + current: { test: { test: [1, 1, 3] } }, + }, + { + pervious: { test: { test: [1, { test: 1 }, 3] } }, + current: { test: { test: [1, { test: 2 }, 3] } }, + }, + { + pervious: { test: { test: [1, { test: 1 }, { test: 3, test1: { test: 3 } }] } }, + current: { test: { test: [1, { test: 1 }, { test: 3, test1: { test: 1 } }] } }, + }, + ]; + + data.forEach((item) => { + expect(reducerUtils.observeChanges( + item.pervious, item.current, + )).toMatchSnapshot(); + }); + }); +});