我正在尝试为我的 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);
包.json
"test": "NODE_ENV=test mocha --require @babel/register --require ./test/*.test.js --watch",
有趣的是,如果我提出错误的期望,它就会失败,所以它会收到文件
最佳答案
您应该使用 mocha 提供的 describe
和 it
函数来声明您的测试。阅读 documentation mocha 的使用说明。
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);
});
});
关于node.js - Mocha 测试 "0 passing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59346114/