我正在试着为我的react应用程序写一些测试。
当测试正确时,我在控制台中得到了这一点。
0 passing (0ms)测试文件appTest.test.js
var expect = require('chai').expect
, foo = 'bar'
, beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
expect(beverages).to.have.property('tea').with.lengthOf(3);package.json
"test": "NODE_ENV=test mocha --require @babel/register --require ./test/*.test.js --watch",有趣的是,如果我设置了错误的期望,它会失败,因此它会接收文件
发布于 2019-12-16 03:18:32
您应该使用mocha提供的describe和it函数来声明您的测试。有关如何使用它的说明,请阅读mocha的documentation。
describe('My test', function() {
it('foo should be "bar"', function(done) {
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
});
});发布于 2021-08-19 06:37:18
似乎describe()和it()不需要包装成其他任何东西,如果它们被包装起来了,mocha就不会检测到它们。
it()只能包装在describe()中,并且describe()只能包装在另一个describe()中。
即使有一个公认的答案,这一事实也应该得到适当的强调。
https://stackoverflow.com/questions/59346114
复制相似问题