"expect" 是如何工作的?

How does "expect" work?

我正在尝试使用 mocha 和 chai 创建逻辑测试

var helperFunctions = require('../lib/helperfunctions.js');
var expect = require('chai').expect;

suite('Sample logic tests',function(){
    test('getDynamicContent() should return dynamic content',function(){
       console.log(typeof helperFunctions.getDynamicContent()); // string
       expect(false); //Doesnt seem to do anything
       expect(typeof helperFunctions.getDynamicContent() === 'number'); 
    });
});

我的helperFunctions.js:

exports.getDynamicContent = function(){

    var dynamicContentSource = [
        "Dynamic Content 1",
        "Dynamic Content 2",
        "Dynamic Content 3",
        "Dynamic Content 4",
        "Dynamic Content 5"
    ];
    var randomDynamicContent = dynamicContentSource[Math.floor(Math.random()*dynamicContentSource.length)];
    return randomDynamicContent;
};

出于某种原因,我的测试总是通过,即使 typeof helperFunctions.getDynamicContent() 是一个字符串。

谁能解释一下我不明白的地方?

你应该像上面评论说的那样使用匹配器。 expect().to.be.equal() 例如