Requiring external js file for mocha testing

后端 未结 2 1082
慢半拍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:53

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

    require "./skill.js"
    
    0 讨论(0)
  • 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'
    
    0 讨论(0)
提交回复
热议问题