Requiring external js file for mocha testing

后端 未结 2 1085
慢半拍i
慢半拍i 2021-01-17 13:41

So I\'m playing around with BDD and mocha with my express.js project. I\'m just getting started so here is what I have as my first test case:

should = requir         


        
2条回答
  •  失恋的感觉
    2021-01-17 13:57

    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'
    

提交回复
热议问题