我是 CoffeeScript 和 Jasmine 的初学者。我尝试测试一个简单的类,如下所示:
class Counter
count: 0
constructor: ->
@count = 0
increment: ->
@count++
decrement: ->
@count--
reset: ->
@count = 0
root = exports ? this
root.Counter = Counter
然后,我编写了如下测试代码:
describe("Counter", ->
counter = new Counter
it("shold have 0 as a count variable at first", ->
expect(counter.count).toBe(0)
)
describe('increment()', ->
it("should count up from 0 to 1", ->
expect(counter.increment()).toBe(1)
)
)
)
第二次测试总是失败,消息如下:
Expected 0 to be 1.
谢谢你的好意。