node.js - Mocha 测试 "0 passing"

标签 node.js reactjs testing mocha.js chai

我正在尝试为我的 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",

Directory

有趣的是,如果我提出错误的期望,它就会失败,所以它会收到文件

最佳答案

您应该使用 mocha 提供的 describeit 函数来声明您的测试。阅读 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/

相关文章:

reactjs - 如何在 next 13 中使用 mantine UI

testing - CodenameOne TestRecorder 如何运行测试

javascript - 如何使用 Protractor 获取当前 url?

Python 的 'mock' - 响应参数

node.js - 如何在 Express js 中执行多次填充?

javascript - 未处理的拒绝nodejs

javascript - 如何解码诺克记录的响应

javascript - React 组件状态与 props 动态输入

javascript - 如何在 react js中下载文件

javascript - 为什么这个nodejs代码无论哪个函数在先都会以相同的顺序输出?