我正在尝试为我的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",
有趣的是,如果我输入了错误的期望,它将失败,因此它会接收文件
答案 0 :(得分:0)
您应该使用mocha提供的describe
和it
函数来声明您的测试。阅读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);
});
});