diff --git a/package.json b/package.json index f014b7b..90ba843 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "test": "istanbul cover _mocha test.js --report html -- -R spec", "prepublish": "npm run test" }, - "dependencies": {}, + "dependencies": { + "seamless-immutable": "^7.1.2" + }, "devDependencies": { "chai": "^3.5.0", "coveralls": "^2.11.14", diff --git a/test.js b/test.js index e6ab631..2c8105f 100644 --- a/test.js +++ b/test.js @@ -4,6 +4,7 @@ var expect = require('chai').expect var op = require('./index.js') +const Immutable = require('seamless-immutable') describe('set', function () { it('should set a deep key without modifying the original object', function () { @@ -95,6 +96,37 @@ describe('set', function () { expect(newObj.a.b).to.be.equal(2) }) + + it('should should replace contents of an array inside an object', function () { + var obj = { + foo: { + bar: [ + { + baz: 'fou', + biz: 'bar' + }, { + baz: 'foo', + biz: 'bar' + } + ] + } + } + var immutableObj = Immutable(obj) + var newObj = op.set(immutableObj, 'foo.bar.0.baz', 'foo') + expect(newObj).to.be.equal(Immutable({ + foo: { + bar: [ + { + baz: 'foo', + biz: 'bar' + }, { + baz: 'foo', + biz: 'bar' + } + ] + } + })) + }) }) describe('insert', function () {