I'm building a Jasmine spec and writing toThrowError test.
it("Should give time travel error", () => {
const errorMsg = Logger.getLogsBetweenDates( {
fromDate : new Date("2017-01-06"),
toDate : new Date("2017-01-05")});
expect(errorMsg).toThrowError("Time travel error: fromDate must be befor toDate");
});
And im getting "Error: Actual is not a function" with no extra details.
Actual?Logger.getLogsBetweenDates function is acutely throw the error, and the test is always fail. what am i doing wrong?What is that Actual?
As its name suggest, the Actual is the variable that contain the actual result from the tested function. what's your tested function actually returned.
Then, Jasmine take that Actual value and compare it with your expect value.
It's easier to understand when you see the source code here.
Its happen in the code becuse the Logger.getLogsBetweenDates is throw an error, and errorMsg get no result; so the Actual is undefined, and the expect function compare an undefined to the error message.
what am i doing wrong?
You need to call the tested function inside of the expect function, like so:
it("Should give time travel error", () => {
expect(() => {
Logger.getLogsBetweenDates( {
fromDate : new Date("2017-01-06"),
toDate : new Date("2017-01-05")})
}).toThrowError("Time travel error: fromDate must be befor toDate");
});
As shown here.
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