Hi,
I have a test that checks the length of a function result (an array of objects).
Due to an error in my code the objects inside array where created with a field name called 'undefined'.
Sample
let resultArray = [
{ name : 'a name1',
surname : 'a surname1' ,
undefined: {}
},
{ name : 'a name2',
surname : 'a surname2' ,
undefined: {}
}
]
My test expectation was:
expect(resultArray).to.have.lenght(2);
(also tried with expect(resultArray).to.have.lenghtOf(2))
As a result expect always says that the length of the array was 0 despite the array have 2 elements.
As a workaround I had to change the expectation to this:
expect(resultArray.length).to.equal(2);
I'm using chai version 3.5.0
Hello @endymion00, thank you for your issue.
I tried to reproduce your problem with the following code:
const expect = require('chai').expect;
let resultArray = [
{ name : 'a name1',
surname : 'a surname1' ,
undefined: {}
},
{ name : 'a name2',
surname : 'a surname2' ,
undefined: {}
}
];
expect(resultArray).to.have.length(2); // does not throw
expect(resultArray).to.have.lenghtOf(2); // does not throw
expect(resultArray).to.have.lenght(3);
// /\ this throws AssertionError: expected [ Array(2) ] to have a length of 3 but got 2
I'm using chai 3.5.0 with node 7.0.0
Can you provide a more detailed example? Maybe a public repo demonstrating the problem.
@endymion00 We haven't been able to reproduce this issue. I'm going to go ahead and close this issue, but please feel welcome to reopen it if you have a standalone example to share that demonstrates the problem.
came here accidentally from google.
Isn't the typo in length the problem?
Most helpful comment
came here accidentally from google.
Isn't the typo in
lengththe problem?