Requiring external js file for mocha testing

人盡茶涼 提交于 2019-12-01 16:10:14

You need to export your Skill class like this:

class Skill
    constructor: (@name,@years,@width) ->

module.exports = Skill

And assign it to variable in your test:

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'

if skill.js is in the same path of your test code, try this.

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