如何检查类继承在Coffeescript摩卡测试? [英] How to check for class inheritance in Coffeescript Mocha Test?
本文介绍了如何检查类继承在Coffeescript摩卡测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Coffeescript中检查mocha规范中的对象的类?
How do I check for the class of an object in a mocha spec in Coffeescript?
我尝试过以下操作:
# 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)
$ b b
但是,我收到 ReferenceError Foo未定义
推荐答案
我相信这是最简单的方法:
I believe this to be the easiest approach:
# 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)
这篇关于如何检查类继承在Coffeescript摩卡测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文