我正在尝试为我的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",
有趣的是,如果我提出了错误的期望,它将失败,因此它会接收文件
您应使用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);
});
});