如何测试我的Backbone集合在Jasmine中扩展的类

not*_*ere 3 javascript coffeescript backbone.js jasmine

我在Coffeescript中有一个自定义的Backbone.Collection类.

我命名它(它负责分页):

class SI.PaginatedCollection extends Backbone.Collection
Run Code Online (Sandbox Code Playgroud)

我想编写Jasmine规范,测试我是否会扩展该特定类.

对不起我的英语,我现在可能很恐怖.;)

PS我可以解析Javascript,但Coffeescript会很理想.

Buc*_*yle 9

对我来说测试这个似乎有些过分,但你可以这样做:

describe "SI.PaginatedCollection", ->

  beforeEach ->
    @collection = new SI.PaginatedCollection()

  it "is a subclass of Backbone.Collection", ->
    expect(@collection instanceof Backbone.Collection).toBeTruthy()
Run Code Online (Sandbox Code Playgroud)

如果你要经常检查instanceof和/或关心描述性的Jasmine输出,那么制作一个自定义匹配器是值得的,所以你可以这样写:

expect(@collection).toBeInstanceOf(Backbone.Collection)
Run Code Online (Sandbox Code Playgroud)