摩卡测试“0通过”
Mocha test "0 passing"
我正在尝试为我的 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",
Directory
有趣的是,如果我输入了错误的期望,它就会失败,所以它会收到文件
您应该使用 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);
});
});
看来 describe()
和 it()
不需要包裹成任何其他东西,如果它们被包裹起来,mocha 将检测不到它们。
it()
只能包裹在describe()
中,describe()
只能包裹在另一个describe()
.
中
即使有公认的答案,也应该适当强调这一事实。
我正在尝试为我的 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",
Directory
有趣的是,如果我输入了错误的期望,它就会失败,所以它会收到文件
您应该使用 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);
});
});
看来 describe()
和 it()
不需要包裹成任何其他东西,如果它们被包裹起来,mocha 将检测不到它们。
it()
只能包裹在describe()
中,describe()
只能包裹在另一个describe()
.
即使有公认的答案,也应该适当强调这一事实。