需要外部js文件进行摩卡testing
所以我和我的express.js项目一起玩BDD和摩卡。 我刚刚开始,所以这是我作为我的第一个testing用例:
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'
(也这个coffeescript生成一些奇怪的js,因为它插入返回到最后的声明..这是正确的方式来设置一个testing与咖啡脚本?)
现在当我运行摩卡时,我得到这个错误:
1) Skill #constructor() should return an instance of class skill: ReferenceError: Skill is not defined
我认为这意味着skill.jsinput不正确。 我的技能类非常简单,只是一个构造函数:
class Skill constructor: (@name,@years,@width) ->
如何导入我的模型,以便我的摩卡testing可以访问它们?
你需要像这样导出你的Skill类:
class Skill constructor: (@name,@years,@width) -> module.exports = Skill
并将其分配给您的testing中的variables:
should = require "should" Skill = 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'
如果skill.js位于testing代码的相同path中,请尝试此操作。
require "./skill.js"
- 摩卡如何知道只有我的asynchronoustesting等待和超时?
- node.js在test中设置process.envvariables
- 你如何安装和运行Mocha,Node.jstesting模块? 安装后得到“mocha:command not found”
- primefaces+摩卡在窗户=派生摩卡ENOENT
- Babel + Mocha堆栈跟踪报告错误的行号
- Nodejs摩卡unit testingsqlite3callback未调用插入未执行
- Supertest,我可以创build一个替代的请求与默认设置一些标头?
- 如何在摩卡testing中模拟无连接
- Node.js sinon在并行执行中桩存函数导致失败的testing