簡體   English   中英

摩卡咖啡“描述”未定義

[英]mocha “describe” is not defined

我閱讀了所有相關的mocha "describe" is not defined但這些帖子似乎都不適合我的情況。

我使用流星,並通過npm安裝了"mocha": "^3.5.0"軟件包

我在流星根目錄中創建了/test文件夾。 和樣本測試mochatest.js

var assert = require("assert"); // node.js core module

describe('Array', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){
      assert.equal(-1, [1,2,3].indexOf(4)); // 4 is not present in this array so indexOf returns -1
    })
  })
});

當我運行摩卡咖啡時,測試通過了。

但是,當我啟動普通服務器時,我得到: ReferenceError: describe is not defined

.meteor/packages/meteor-tool/.1.3.5_1.1wj76e8++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280 throw(ex); ^ ReferenceError: describe is not defined at meteorInstall.test.mochatest.js (test/mochatest.js:3:1) at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1) at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1) at project-i18n.js:6:1 at .meteor/local/build/programs/server/boot.js:297:10 at Array.forEach (native) at Function._.each._.forEach (.meteor/packages/meteor-tool/.1.3.5_1.1wj76e8++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) at .meteor/local/build/programs/server/boot.js:133:5

我覺得流星想在啟動時進行測試,但是找不到摩卡咖啡。

那么該怎么辦?

看起來在服務器運行時以某種方式調用了測試文件。 它不應包含在服務器代碼中的任何位置。 如果您不知道發生了什么,則可以嘗試調試服務器,並在“描述”行中放置一個斷點-嘗試看看如何到達那里。

您需要將/test文件夾重命名為/tests

根據官方的《 流星測試指南》

流星構建工具和流星測試命令將忽略位於任何tests/目錄中的任何文件。 這使您可以將測試放在該目錄中,您可以使用Meteor內置測試工具之外的測試運行器運行測試,而仍不會在應用程序中加載這些文件。

您也可以考慮使用以下擴展名重命名測試文件:

*.test[s].**.spec[s].* -因此您的文件可以命名為mocha.test.js

這些文件也將被Meteor構建工具忽略。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM