如何在Coffeescript Mocha Test中检查类继承?

时间:2013-12-02 18:55:57

标签: coffeescript mocha should.js

如何在Coffeescript中检查mocha规范中的对象类?

我尝试了以下内容:

# foo.coffee
class Foo
module.exports = new Foo()

# foo_spec.coffee
should  = require 'should'
{ Foo } = require 'foo'
foo = new Foo
foo.should.be.an.instanceOf(Foo)

但是,我收到了ReferenceError Foo is not defined

1 个答案:

答案 0 :(得分:0)

我认为这是最简单的方法:

# foo.coffee
class Foo
module.exports = new Foo()
module.exports.Foo = Foo # IMPORTANT, exports the actual class Foo


# foo_spec.coffee
should  = require 'should'
{ Foo } = require 'foo' # Requires said class Foo
foo = new Foo
foo.should.be.an.instanceOf(Foo)