我在 Coffeescript 中有一个自定义的 Backbone.Collection 类。
我给它起的名字(它负责分页):
class SI.PaginatedCollection extends Backbone.Collection
我想编写 Jasmine 规范来测试我是否扩展了那个特定的类。
对不起我的英语,我现在可能很糟糕。 ;)
PS 我可以解析 Javascript,但 Coffeescript 会更理想。
最佳答案
测试这个对我来说似乎有点过分了,但你可以这样做:
describe "SI.PaginatedCollection", ->
beforeEach ->
@collection = new SI.PaginatedCollection()
it "is a subclass of Backbone.Collection", ->
expect(@collection instanceof Backbone.Collection).toBeTruthy()
如果你要经常检查 instanceof
和/或你关心描述性的 Jasmine 输出,那么制作一个自定义匹配器是值得的,所以你可以这样写:
expect(@collection).toBeInstanceOf(Backbone.Collection)
关于javascript - 如何测试我的 Backbone 集合在 Jasmine 中扩展到哪个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10797683/