【问题标题】:How to check for class inheritance in Coffeescript Mocha Test?如何在 Coffeescript Mocha 测试中检查类继承?
【发布时间】:2013-12-18 14:22:55
【问题描述】:
如何在 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
【问题讨论】:
标签:
coffeescript
mocha.js
should.js
【解决方案1】:
我认为这是最简单的方法:
# 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)