2021-04-06 19:13:42 +00:00
|
|
|
import nextState from '../../../src/reducers/nextState';
|
|
|
|
|
|
|
|
QUnit.module( 'reducers/nextState' );
|
|
|
|
|
|
|
|
QUnit.test( 'with scalar values', ( assert ) => {
|
|
|
|
const tests = [
|
|
|
|
{
|
|
|
|
before: {},
|
|
|
|
updates: {},
|
|
|
|
after: {}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
before: { unchanged: true, changed: false },
|
|
|
|
updates: { new: true, changed: true },
|
|
|
|
after: { unchanged: true, changed: true, new: true }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
before: { a: { b: { unchanged: true, changed: false } } },
|
|
|
|
updates: { a: { b: { new: true, changed: true } } },
|
|
|
|
after: { a: { b: { unchanged: true, changed: true, new: true } } }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
for ( const i in tests ) {
|
|
|
|
const test = tests[ i ];
|
|
|
|
assert.deepEqual(
|
|
|
|
nextState( test.before, test.updates ),
|
|
|
|
test.after,
|
|
|
|
'Test case #' + i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'original state object should not change', ( assert ) => {
|
|
|
|
const state = {},
|
|
|
|
after = nextState( state, { changed: true } );
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{},
|
|
|
|
'original state is unchanged'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
after,
|
|
|
|
{ changed: true },
|
|
|
|
'new state is different'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'Element instances should not be cloned', ( assert ) => {
|
|
|
|
const element = document.createElement( 'a' ),
|
|
|
|
newElement = document.createElement( 'b' ),
|
|
|
|
state = { element },
|
|
|
|
after = nextState( state, { element: newElement } );
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
state.element, element,
|
2021-04-06 19:13:42 +00:00
|
|
|
'original state is unchanged'
|
|
|
|
);
|
2022-02-09 15:09:19 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
after.element, newElement,
|
2021-04-06 19:13:42 +00:00
|
|
|
'Element instance was not cloned'
|
|
|
|
);
|
|
|
|
} );
|