should.js icon indicating copy to clipboard operation
should.js copied to clipboard

Stop changing current object in plural assertions

Open btd opened this issue 8 years ago • 0 comments

In future version i would like to stop changing this.obj in assertions like .key or .property. I would like this assertion to save this plural object in addtional property, and if .which is called it will restore it. Examples:

  1. Current behaviour:
({ a: 42 }).should.have.key('a').and.be.Number();

As .key changed current object to be 42 (value of key 'a'), we can chain with a Number assertion.

  1. Proposed change:
({ a: 1, b: 2 }).should.have.key('a').and.key('b');
// this time given object is not changed, but
({ a: 1, b: 'a' }).should.have.key('b').which.is.a.String();
// .which restore last object from .keys to use in next assertions

btd avatar Jan 27 '17 08:01 btd