| OLD | NEW |
| (Empty) | |
| 1 "use strict" |
| 2 |
| 3 sinon = require("sinon") |
| 4 |
| 5 describe "Call context", -> |
| 6 spy = null |
| 7 target = null |
| 8 notTheTarget = null |
| 9 |
| 10 beforeEach -> |
| 11 spy = sinon.spy() |
| 12 target = {} |
| 13 notTheTarget = {} |
| 14 |
| 15 describe "calledOn", -> |
| 16 it "should throw an assertion error if the spy is never called", -> |
| 17 expect(-> spy.should.have.been.calledOn(target)).to.throw(AssertionE
rror) |
| 18 |
| 19 it "should throw an assertion error if the spy is called without a conte
xt", -> |
| 20 spy() |
| 21 |
| 22 expect(-> spy.should.have.been.calledOn(target)).to.throw(AssertionE
rror) |
| 23 expect(-> spy.getCall(0).should.have.been.calledOn(target)).to.throw
(AssertionError) |
| 24 |
| 25 it "should throw an assertion error if the spy is called on the wrong co
ntext", -> |
| 26 spy.call(notTheTarget) |
| 27 |
| 28 expect(-> spy.should.have.been.calledOn(target)).to.throw(AssertionE
rror) |
| 29 expect(-> spy.getCall(0).should.have.been.calledOn(target)).to.throw
(AssertionError) |
| 30 |
| 31 it "should not throw if the spy is called on the specified context", -> |
| 32 spy.call(target) |
| 33 |
| 34 expect(-> spy.should.have.been.calledOn(target)).to.not.throw() |
| 35 expect(-> spy.getCall(0).should.have.been.calledOn(target)).to.not.t
hrow() |
| 36 |
| 37 it "should not throw if the spy is called on another context and also th
e specified context", -> |
| 38 spy.call(notTheTarget) |
| 39 spy.call(target) |
| 40 |
| 41 expect(-> spy.should.have.been.calledOn(target)).to.not.throw() |
| 42 expect(-> spy.getCall(1).should.have.been.calledOn(target)).to.not.t
hrow() |
| 43 |
| 44 describe "always calledOn", -> |
| 45 it "should throw an assertion error if the spy is never called", -> |
| 46 expect(-> spy.should.always.have.been.calledOn(target)).to.throw(Ass
ertionError) |
| 47 expect(-> spy.should.have.always.been.calledOn(target)).to.throw(Ass
ertionError) |
| 48 expect(-> spy.should.have.been.always.calledOn(target)).to.throw(Ass
ertionError) |
| 49 |
| 50 it "should throw an assertion error if the spy is called without a conte
xt", -> |
| 51 spy() |
| 52 |
| 53 expect(-> spy.should.always.have.been.calledOn(target)).to.throw(Ass
ertionError) |
| 54 expect(-> spy.should.have.always.been.calledOn(target)).to.throw(Ass
ertionError) |
| 55 expect(-> spy.should.have.been.always.calledOn(target)).to.throw(Ass
ertionError) |
| 56 |
| 57 it "should throw an assertion error if the spy is called on the wrong co
ntext", -> |
| 58 spy.call(notTheTarget) |
| 59 |
| 60 expect(-> spy.should.always.have.been.calledOn(target)).to.throw(Ass
ertionError) |
| 61 expect(-> spy.should.have.always.been.calledOn(target)).to.throw(Ass
ertionError) |
| 62 expect(-> spy.should.have.been.always.calledOn(target)).to.throw(Ass
ertionError) |
| 63 |
| 64 it "should not throw if the spy is called on the specified context", -> |
| 65 spy.call(target) |
| 66 |
| 67 expect(-> spy.should.always.have.been.calledOn(target)).to.not.throw
() |
| 68 expect(-> spy.should.have.always.been.calledOn(target)).to.not.throw
() |
| 69 expect(-> spy.should.have.been.always.calledOn(target)).to.not.throw
() |
| 70 |
| 71 it "should throw an assertion error if the spy is called on another cont
ext and also the specified context", -> |
| 72 spy.call(notTheTarget) |
| 73 spy.call(target) |
| 74 |
| 75 expect(-> spy.should.always.have.been.calledOn(target)).to.throw(Ass
ertionError) |
| 76 expect(-> spy.should.have.always.been.calledOn(target)).to.throw(Ass
ertionError) |
| 77 expect(-> spy.should.have.been.always.calledOn(target)).to.throw(Ass
ertionError) |
| 78 |
| OLD | NEW |