From 1fb0f6c57fd82b99955b5909714d569f2c377c0b Mon Sep 17 00:00:00 2001 From: Kurakin Alexander Date: Sat, 19 Dec 2015 19:47:05 +0300 Subject: [PATCH] Fix updating to null and to undefined --- src/mixins.js | 2 +- tests/freezer-spec.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/mixins.js b/src/mixins.js index cdd9018..5c96db1 100644 --- a/src/mixins.js +++ b/src/mixins.js @@ -37,7 +37,7 @@ var commonMethods = { if( !update ){ for( var key in attrs ){ - update = update || this[ key ] != attrs[ key ]; + update = update || this[ key ] !== attrs[ key ]; } // No changes, just return the node diff --git a/tests/freezer-spec.js b/tests/freezer-spec.js index bd10b9e..ea32785 100644 --- a/tests/freezer-spec.js +++ b/tests/freezer-spec.js @@ -123,6 +123,38 @@ describe("Freezer test", function(){ assert.notEqual( updated, data ); }); + it( "Update a value to null", function(){ + data.set('a', null); + + var updated = freezer.getData(); + + assert.deepEqual( updated.a, null ); + + assert.notEqual( updated, data ); + }); + + it( "Update an undefined value to null", function(){ + data = data.set('a', undefined); + data.set('a', null); + + var updated = freezer.getData(); + + assert.strictEqual( updated.a, null ); + + assert.notEqual( updated, data ); + }); + + it( "Update an null value to undefined", function(){ + data = data.set('a', null); + data.set('a', undefined); + + var updated = freezer.getData(); + + assert.strictEqual( updated.a, undefined ); + + assert.notEqual( updated, data ); + }); + it( "Update a value doesnt modify other elements", function(){ data.set({a: 2});