我正在尝试使用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()是一个字符串。
有人可以向我解释我还没有理解的内容吗?
答案 0 :(得分:3)
你可以使用像上面评论所说的匹配器。例如expect().to.be.equal()