Created
March 15, 2012 16:32
-
-
Save dekokun/2045153 to your computer and use it in GitHub Desktop.
mocha, sinon, should test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sinon = require("sinon") | |
should = require("should") | |
a = {} | |
a.test = () -> | |
[1, 2] | |
describe "calc", -> | |
describe ".add", -> | |
it "should return sum of 2 arguments", -> | |
result = 1 + 2 | |
result.should.equal 3 | |
describe "Spy", -> | |
beforeEach -> | |
sinon.spy(a, "test") | |
afterEach -> | |
a.test.restore() | |
it "called", -> | |
callback = sinon.spy() | |
callback() | |
callback.called.should.true | |
it "calledWith", -> | |
a.test('hoge') | |
a.test.calledWith('hoge').should.true | |
it "calledWith two operator", -> | |
a.test('gero', 'roro') | |
a.test.calledWith('gero', 'roro').should.true | |
it "callCount", -> | |
a.test('gero', 'roro') | |
a.test.callCount.should.equal(1) | |
it "withArgs", -> | |
a.test('gero', 'roro') | |
a.test.withArgs('gero', 'roro').callCount.should.equal(1) | |
it "notCaldWith", -> | |
a.test('gege', 'gogo') | |
a.test('gege', 'gogo') | |
a.test.neverCalledWith('gero', 'roro').should.true | |
it "getCall", -> | |
a.test("gege", "gogo") | |
a.test("1", "2") | |
spyCall = a.test.getCall(1) | |
spyCall.calledWith("1", "2").should.true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment