【问题标题】:Requiring files to mocha test摩卡测试需要文件
【发布时间】:2016-06-22 11:53:14
【问题描述】:

我的测试模块看起来像这样

//require('./main');
//require('../main');
//require('./scripts/main');
//require('./src/scripts/main');
//require('./src/scripts/main');
//require('../scripts/main');
//require('../src/scripts/main');

var
  assert = require('chai').assert,
  //Notices = require('../src/scripts/notices/notices'),
  notices = new Notices();

describe('NoticesTest', function() {

  describe('getImportantNotices', function () {

    it('Should return array of ImportanceNotice', function () {
      /*notices.getImportantNotices().then(function(val) {
        console.log(val);
        assert.equal(val.data.length, 50);
      }).catch(function() {
        assert.equal(true, false);
      });*/

    });

  });

});

在我做的模块中

export default Notices;

我尝试将 javascript 文件放入其中,但它失败了(找不到模块)。我正在使用 babel 编写 ES6,require 是 ES6 不需要 requirejs。可能是 ES6 require 在 mocha 中不起作用,它需要 requirejs 来要求我的模块?

【问题讨论】:

  • 另外,require('chai').assert; 有效且有效,但我的 .js 文件仍未找到。

标签: javascript mocha.js


【解决方案1】:

你试过了吗

import Notices from '<path>';

【讨论】:

  • 是的,我试过了,这也失败了。导入给Unexpected reserved word
  • 您的 Babel 配置似乎有问题。你使用的是 Babel 5 还是 6?是否添加了预设“es2015”和“stage-0”?
  • 对,我正在使用 babelify。将在晚上晚些时候检查并回复您。谢谢!
  • 我缺少 .babelrc 文件,其中包含“es2015”
猜你喜欢
  • 2017-12-04
  • 1970-01-01
  • 2014-04-06
  • 2019-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多