que tenían el mismo problema que Usted mencionó en el comentario por el cual mi prueba que no prueba Error
se detendría "mal" mostrando un mensaje mal formateado Died on test #1
sin ninguna información útil.
Terminé usando una combinación de ambos; raises()
para una prueba y try/catch
para la otra.
que utilizan aumentos() para la prueba que realiza pruebas de que un Error
se lanza, similar a este:
test("When myFunction() is called with a invalid instance Then Error is thrown", function() {
// Arrange
var testInstance = {};
// Act
raises(function() {
myFunction(testInstance);
}, Error, "myFunction() should throw an Error");
// Assert
// raises() does assertion
});
Si lo anterior, se emite una Error
todo está bien, y si no se visualiza un mensaje con formato agradable, similar a esto:
myFunction() should throw Error
Result: No exception was thrown.
luego utiliza try/catch
para las pruebas que tienen que asegurar que no Error
se lanza, similar a esto:
test("When myFunction() is called with a valid instance Then no Error is thrown", function() {
// Arrange
var testInstance = new myObject();
var result;
// Act
try {
myFunction(testInstance);
result = true;
} catch(error) {
result = false;
}
// Assert
ok(result, "myFunction() should not throw an Error");
});
Si lo anterior no arroja Error
todo está bien y si un Error
se lanza se muestra un mensaje con formato agradable, similar a esto:
myFunction() should not throw an Error
Source: ...
cheque esta http://stackoverflow.com/questions/10190392/asserting-that-a-function-throws-exceptions-with-qunit puede ayudar – hanane