I have a jasmine 2.0 test that if a function is called, the test failed.
I have a function "Remote.get" that should call the first argument (which is a callback) if it is successful, or the second argument if it failed.
If it calls the second argument, I need to mark the test as failed.
How can I clearly mark the test as failed?
describe("my tests", function() {
it("should call the first function", function(done) {
Remote.get(
function() {
// yeah! good!
done();
},
function() {
// whoa, if we got here, then it didn't work
// fail()!
done();
}
);
});
});
I know I could do something like expect(true).toBe(false)
but I the error you get then would be unclear and unrelated to the actual problem. It should give an error like "wrong callback was called" or "Remote.get failure was called". I was hoping there was something more descriptive in Jasmine.
What I'm really looking for is the python equivalent of http://docs.python.org/2/library/unittest.html#unittest.TestCase.fail.
They added a fail()
method very recently in this commit. It will likely be released with the next point release of jasmine (assuming 2.1, unclear when this will be), or you can build your own from edge.
You could write and register a custom matcher whose compare
function in the return value always fails, and assign your custom message to the message
property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With