<i id='JOGn3'><tr id='JOGn3'><dt id='JOGn3'><q id='JOGn3'><span id='JOGn3'><b id='JOGn3'><form id='JOGn3'><ins id='JOGn3'></ins><ul id='JOGn3'></ul><sub id='JOGn3'></sub></form><legend id='JOGn3'></legend><bdo id='JOGn3'><pre id='JOGn3'><center id='JOGn3'></center></pre></bdo></b><th id='JOGn3'></th></span></q></dt></tr></i><div id='JOGn3'><tfoot id='JOGn3'></tfoot><dl id='JOGn3'><fieldset id='JOGn3'></fieldset></dl></div>
    1. <legend id='JOGn3'><style id='JOGn3'><dir id='JOGn3'><q id='JOGn3'></q></dir></style></legend>

        <bdo id='JOGn3'></bdo><ul id='JOGn3'></ul>

        <small id='JOGn3'></small><noframes id='JOGn3'>

        <tfoot id='JOGn3'></tfoot>
      1. mocha 测试需要外部 js 文件

        时间:2024-04-19
      2. <tfoot id='sHwur'></tfoot>
        <i id='sHwur'><tr id='sHwur'><dt id='sHwur'><q id='sHwur'><span id='sHwur'><b id='sHwur'><form id='sHwur'><ins id='sHwur'></ins><ul id='sHwur'></ul><sub id='sHwur'></sub></form><legend id='sHwur'></legend><bdo id='sHwur'><pre id='sHwur'><center id='sHwur'></center></pre></bdo></b><th id='sHwur'></th></span></q></dt></tr></i><div id='sHwur'><tfoot id='sHwur'></tfoot><dl id='sHwur'><fieldset id='sHwur'></fieldset></dl></div>
          <tbody id='sHwur'></tbody>

            <bdo id='sHwur'></bdo><ul id='sHwur'></ul>
              <legend id='sHwur'><style id='sHwur'><dir id='sHwur'><q id='sHwur'></q></dir></style></legend>

              <small id='sHwur'></small><noframes id='sHwur'>

                  本文介绍了mocha 测试需要外部 js 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

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

                  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 = 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,因为它会插入返回到最后一条语句.这是用coffeescript设置测试的正确方法吗?)

                  (also this coffeescript generates some odd looking js since it inserts returns to last statement.. is this the correct way to setup a test with coffeescript?)

                  现在当我运行 mocha 时出现此错误:

                  Now when I run mocha I get this error:

                   1) Skill #constructor() should return an instance of class skill:
                       ReferenceError: Skill is not defined
                  

                  我认为这意味着 Skill.js 没有正确导入.此时我的技能类很简单,只是一个构造函数:

                  Which I assume means skill.js was not imported correctly. My skill class is very simple at this point, just a constructor:

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

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

                  How do I import my models so my mocha test can access them?

                  推荐答案

                  你需要像这样导出你的 Skill 类:

                  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'
                  

                  这篇关于mocha 测试需要外部 js 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Flot 图表 - 打开/关闭系列 下一篇:在咖啡脚本中调用函数定义的方法

                  相关文章

                    <bdo id='oDayo'></bdo><ul id='oDayo'></ul>
                1. <legend id='oDayo'><style id='oDayo'><dir id='oDayo'><q id='oDayo'></q></dir></style></legend>
                  1. <small id='oDayo'></small><noframes id='oDayo'>

                  2. <i id='oDayo'><tr id='oDayo'><dt id='oDayo'><q id='oDayo'><span id='oDayo'><b id='oDayo'><form id='oDayo'><ins id='oDayo'></ins><ul id='oDayo'></ul><sub id='oDayo'></sub></form><legend id='oDayo'></legend><bdo id='oDayo'><pre id='oDayo'><center id='oDayo'></center></pre></bdo></b><th id='oDayo'></th></span></q></dt></tr></i><div id='oDayo'><tfoot id='oDayo'></tfoot><dl id='oDayo'><fieldset id='oDayo'></fieldset></dl></div>

                    1. <tfoot id='oDayo'></tfoot>