相关疑难解决方法(0)

需要外部js文件进行mocha测试

所以我正在使用我的express.js项目来玩BDD和mocha.我刚刚开始,所以这里是我的第一个测试用例:

should = require "should"
require "../lib/models/skill.js"


describe 'Skill', ->
    describe '#constructor()', ->
        it 'should return an instance of class skill', ->
            testSkill = new Skill "iOS", "4 years", 100
            testSkill.constructor.name.should.equal 'Skill'
Run Code Online (Sandbox Code Playgroud)

(这个coffeescript也会生成一些奇怪的js,因为它会返回到最后一个语句..这是用coffeescript设置测试的正确方法吗?)

现在,当我运行mocha时,我收到此错误:

 1) Skill #constructor() should return an instance of class skill:
     ReferenceError: Skill is not defined
Run Code Online (Sandbox Code Playgroud)

我认为这意味着skill.js没有正确导入.我的技能类在这一点上非常简单,只是一个构造函数:

class Skill
    constructor: (@name,@years,@width) ->
Run Code Online (Sandbox Code Playgroud)

如何导入模型以便我的mocha测试可以访问它们?

javascript bdd mocha.js node.js coffeescript

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

bdd ×1

coffeescript ×1

javascript ×1

mocha.js ×1

node.js ×1