What is the general convention for unit testing logic that looks similar to its implementation?
For example, say I have a function like this:
function getNumberOfElements() {
return document.childNodes[0].childNodes.length
}
If I tested this routine in a fixture, I would be repeating the logic in the routine:
it('should return the number of nodes', function() {
var numberOfElements = document.childNodes[0].childNodes.length
expect(getNumberOfElements()).toBe(numberOfElements)
})
So is there a better way? I can see this approach as being prone to all sorts of problems, but how else would you test a function like this?
Aucun commentaire:
Enregistrer un commentaire