* ### .change(function) * * Asserts that a function changes an object property * * var obj = { val: 10 }; * var fn = function() { obj.val += 3 }; * var noChangeFn = function() { return 'foo' + 'bar'; } * expect(fn).to.change(obj, 'val'); * expect(noChangFn
(object, prop, msg)
| 2391 | */ |
| 2392 | |
| 2393 | function assertChanges (object, prop, msg) { |
| 2394 | if (msg) flag(this, 'message', msg); |
| 2395 | var fn = flag(this, 'object'); |
| 2396 | new Assertion(object, msg).to.have.property(prop); |
| 2397 | new Assertion(fn).is.a('function'); |
| 2398 | |
| 2399 | var initial = object[prop]; |
| 2400 | fn(); |
| 2401 | |
| 2402 | this.assert( |
| 2403 | initial !== object[prop] |
| 2404 | , 'expected .' + prop + ' to change' |
| 2405 | , 'expected .' + prop + ' to not change' |
| 2406 | ); |
| 2407 | } |
| 2408 | |
| 2409 | Assertion.addChainableMethod('change', assertChanges); |
| 2410 | Assertion.addChainableMethod('changes', assertChanges); |
nothing calls this directly
no test coverage detected
searching dependent graphs…