should.js
should.js copied to clipboard
Stop changing current object in plural assertions
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:
- 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.
- 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