Skip to content

Commit

Permalink
invalidate array with only a partial object value (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdoron authored and cjihrig committed Jun 21, 2016
1 parent 43e551c commit 88a5d24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ internals.addMethod('error', function (/*type, message*/) {
internals.include = function (value) {

this._flags.deep = !this._flags.shallow;
this._flags.part = this._flags.hasOwnProperty('part') ? this._flags.part : false;
return this.assert(Hoek.contain(this._ref, value, this._flags), 'include ' + internals.display(value));
};

Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,20 @@ describe('expect()', () => {
done();
});

it('invalidates array with only a partial object value', (done) => {

let exception = false;
try {
Code.expect([{ a: 1, b: 1 }]).to.include({ a: 1 });
}
catch (err) {
exception = err;
}

Hoek.assert(exception.message === 'Expected [ { a: 1, b: 1 } ] to include { a: 1 }', exception);
done();
});

it('invalidates arrays (shallow)', (done) => {

let exception = false;
Expand Down

0 comments on commit 88a5d24

Please sign in to comment.