摩卡测试“ 0通过”

问题描述 投票:0回答:1

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

有趣的是,如果我提出了错误的期望,它将失败,因此它会接收文件

node.js reactjs testing mocha chai
1个回答
0
投票

您应使用mocha提供的describeit函数来声明测试。阅读摩卡咖啡的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);
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.