Skip to content

Commit

Permalink
add Object.freeze to sources in tests, phetsims/phet-info#91
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 3, 2019
1 parent d51519e commit a97d1d4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions js/mergeTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ define( require => {
const merge2Copy = _.cloneDeep( merge2 );
const merge3Copy = _.cloneDeep( merge3 );

Object.freeze( merge1 );
Object.freeze( merge2 );
Object.freeze( merge3 );
const merged = merge( original, merge1, merge2, merge3 );

const expected = {
Expand Down Expand Up @@ -259,6 +262,7 @@ define( require => {
}
};
const originalCopy = _.cloneDeep( original );
Object.freeze( original );
const mergedFresh = merge( {}, original, merger );
assert.equal( original.prop.value, originalCopy.prop.value, 'merge should not alter source object values' );
assert.ok( _.isEqual( original, originalCopy ), 'merge should not alter source objects' );
Expand All @@ -269,10 +273,10 @@ define( require => {
assert.equal( testProperty2.value, 'forty three', 'merge should pass object literal references' );
assert.equal( testProperty.value, 42, 'original object literal should be overwritten' );

const merged = merge( original, merger );
assert.equal( merged.nestedOptions.needsAnEnum, testEnum.B, 'merge should preserve overwritten Enumeration types' );
assert.equal( merged.nestedOptions.moreOptions.needsAnEnum, testEnum.C, 'merge should preserve Enumeration types from target' );
assert.equal( merged.nestedOptions.moreOptions.needsDifferentEnum, testEnum.A, 'merge should preserve Enumeration types from source' );
const merged = merge( {}, original, merger );
assert.ok( merged.nestedOptions.needsAnEnum === testEnum.B, 'merge should preserve overwritten Enumeration types' );
assert.ok( merged.nestedOptions.moreOptions.needsAnEnum === testEnum.C, 'merge should preserve Enumeration types from target' );
assert.ok( merged.nestedOptions.moreOptions.needsDifferentEnum === testEnum.A, 'merge should preserve Enumeration types from source' );
} );

QUnit.test( 'try a horribly nested case', assert => {
Expand Down Expand Up @@ -314,6 +318,7 @@ define( require => {
}
};

Object.freeze( merge1 );
const merged = merge( original, merge1 );
const expected = {
p1Options: {
Expand Down Expand Up @@ -434,6 +439,4 @@ define( require => {
assert.ok( original.prop === newObject.prop, 'same Property, ignore default' );
assert.ok( original.enum === newObject.enum, 'same Enumeration, ignore default' );
} );


} );

0 comments on commit a97d1d4

Please sign in to comment.