【发布时间】:2016-02-02 13:24:31
【问题描述】:
我尝试使用 Chai Should 风格的断言,但是下面的语句让 Mocha 爆炸了。这是我完整的 Require 块:
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
User = mongoose.model('User'),
moment = require('moment'),
SSEvent = mongoose.model('Event'),
chai = require('chai');
chai.use(require('chai-datetime'));
var should = chai.should();
错误信息:
Running "mochaTest:src" (mochaTest) task
>> Mocha exploded!
>> TypeError: chai.should is not a function
>> at Object.<anonymous> (/Users/sebastianweikart/Desktop/dev/conftool-nga-mean/modules/events/tests/server/events.server.model.tests.js:13:19)
>> at Module._compile (module.js:413:34)
>> at Object.Module._extensions..js (module.js:422:10)
>> at Module.load (module.js:357:32)
>> at Function.Module._load (module.js:314:12)
>> at Module.require (module.js:367:17)
>> at require (internal/module.js:16:19)
>> at /Users/sebastianweikart/Desktop/dev/conftool-nga-mean/node_modules/mocha/lib/mocha.js:219:27
可能是什么问题?
我用
"chai": "^3.5.0" 和 "mocha": "~2.4.5" 应该是最新的稳定版本..
更新:
我现在添加了以下简单的剥离测试 - 它仍然爆炸:
'use strict';
/**
* Module dependencies.
*/
var chai = require('chai');
var should = chai.should();
/**
* Unit tests
*/
describe('Chai Should Test', function () {
describe('Chai Should() should work', function () {
it('Chai Should() must work', function (done) {
var spartacus = 'spartacus';
should.exist(spartacus);
done();
});
});
});
Running "mochaTest:src" (mochaTest) task
>> Mocha exploded!
>> TypeError: chai.should is not a function
>> at Object.<anonymous> (/Users/sebastianweikart/Desktop/dev/conftool-nga-mean/modules/events/tests/server/chai.should.test.js:7:19)
【问题讨论】:
-
您的问题中缺少某些内容。我能够运行您的示例测试而不会出现任何错误。