[英]Mocha test fails even if the result is correct
I am doing a javascript test and I don't know why this fails because all my tests return the right results. 我正在执行javascript测试,但我不知道为什么测试失败,因为我所有的测试都返回正确的结果。
this is my app.js 这是我的app.js
module.exports = function (array){
var firstBigNumber = 0;
var secondBigNumber = 0;
if(array.length === 0) return 0;
for(var index = 0; index < array.length; index++){
if(parseInt(array[index]) === array[index]){
if(array[index] > 0){
if(array[index] > firstBigNumber){
secondBigNumber = firstBigNumber;
firstBigNumber = array[index];
}else if (array[index] > secondBigNumber) {
secondBigNumber = array[index];
}
}
}
else{
secondBigNumber = 0;
firstBigNumber = 0;
}
}
return [firstBigNumber,secondBigNumber];
}
An this are my tests 这是我的测试
const assert = require('assert');
const app = require('../app');
describe('App', function() {
describe('SimpleTest2', function(){
it('Empty array should return 0', function(){
var array = [];
let result = app(array);
assert.equal(result,0);
});
it('Ignore float elements', function(){
var array = [1.2, 2, 3];
assert.equal(app(array),[3,2]);
});
it('Ignores non-numerical values in array', function(){
var array = ['hei', 2, 3, 4, false];
assert.equal(app(array),[4,3]);
});
The error that I receive is Assertion Error [ERR_Asertion]. 我收到的错误是断言错误[ERR_Asertion]。 The are some of my errors I am getting: 这是我遇到的一些错误:
This is likely happening because [ 3, 2 ] == [ 3, 2 ] = false
. 这可能是因为[ 3, 2 ] == [ 3, 2 ] = false
导致的。 (Welcome to javascript) (欢迎使用javascript)
I think what you are looking for is something similiar to chais array equality. 我认为您正在寻找类似于chais数组相等的东西。 Here's what I found: 这是我发现的:
try .eql or .deepEql instead of .equal. 尝试使用.eql或.deepEql代替.equal。 I was able to get expected results then. 那时我能够获得预期的结果。
Check out http://www.chaijs.com/api/bdd/#arguments-section - It's chai but a really good reference. 请访问http://www.chaijs.com/api/bdd/#arguments-section-很不错,但确实是不错的参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.