-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const freeze = require('deep-freeze-node'); | ||
const freeze = require('./freeze'); | ||
|
||
class Nobody { | ||
constructor () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-env mocha */ | ||
/* eslint-disable no-unused-expressions */ | ||
var freeze = require('../lib/freeze'); | ||
require('chai').should(); | ||
|
||
describe('freeze', function () { | ||
let person = {}; | ||
let expectedPerson = {}; | ||
|
||
beforeEach(function () { | ||
person = { | ||
name: 'John', | ||
surname: 'Johnson', | ||
age: 26, | ||
address: { | ||
street: '1st Street', | ||
city: 'Los Angeles', | ||
country: 'USA' | ||
}, | ||
vehicles: ['BMW', 'Ferrari', 'Lamborghini'] | ||
}; | ||
|
||
expectedPerson = { | ||
name: 'John', | ||
surname: 'Johnson', | ||
age: 26, | ||
address: { | ||
street: '1st Street', | ||
city: 'Los Angeles', | ||
country: 'USA' | ||
}, | ||
vehicles: ['BMW', 'Ferrari', 'Lamborghini'] | ||
}; | ||
}); | ||
|
||
it('should not override any object properties', function () { | ||
person = freeze(person); | ||
person.name = 'Jack'; | ||
person.surname = 'Jackson'; | ||
person.age = 18; | ||
person.address = { | ||
street: 'Third Street', | ||
city: 'San Francisco', | ||
country: 'USA' | ||
}; | ||
person.vehicles = ['Toyota']; | ||
person.name = 'Jack'; | ||
person.surname = 'Jackson'; | ||
person.age = 18; | ||
person.address.street = 'Third Street'; | ||
person.address.city = 'San Francisco'; | ||
person.address.country = 'USA'; | ||
person.vehicles[0] = 'Toyota'; | ||
|
||
delete person.vehicles[1]; | ||
delete person.vehicles[2]; | ||
|
||
person.should.deep.equal(expectedPerson, 'any object properties should not be overridden'); | ||
}); | ||
|
||
it('should not add new properties to an object', function () { | ||
person = freeze(person); | ||
|
||
person.occupation = 'Lawyer'; | ||
person.nickname = 'JJ'; | ||
|
||
person.should.deep.equal(expectedPerson); | ||
}); | ||
}); |