How to check for class inheritance in Coffeescript Mocha Test?

倾然丶 夕夏残阳落幕 提交于 2020-03-25 18:54:18

问题


How do I check for the class of an object in a mocha spec in Coffeescript?

I have tried the following:

# 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)

However, I receive ReferenceError Foo is not defined


回答1:


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)


来源:https://stackoverflow.com/questions/20335719/how-to-check-for-class-inheritance-in-coffeescript-mocha-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!