Tester le message d'une erreur

Par TransientDev, il y a 10 ans


Javascript NodeJS

Bonjour,
je suis en train de tester une fonction qui est censé retourner une erreur dans la fonction callback or quand je fais:

/** * Le test */ else { callback(new Error('Invalid argument type, expect ' + arg.constructor.name + ' to be either a Command or an array of Command')); } /** * Le test */ it('should throw and error if anything else is passed', function() { var spy = sinon.spy(); CommandList.add(42, spy); expect(spy).to.have.been.calledWith(new Error('Invalid argument type, expect String to be either a Command or an array of Command')); });

Le test passe quand même, alors que si je remplace

new Error('blablabla');

par

'blablabla'

dans la fonction et dans le test, le test fail comme prévu.
Du coup comment faire pour tester l'erreur et et son texte?

PS: Ici j'utilise le plugin sinon-chai

Aucune réponse