I'm doing expect(ClassUnderTest.someMethod(withSomeParams)).toThrow() and I'm getting:-
Error: <toThrow> : Actual is not a Function
Usage: expect(function() {<expectation>}).toThrow(<ErrorConstructor>, <message>)
and I don't understand the usage example.
I tried expect(() => ClassUnderTest.someMethod(withSomeParams)).toThrow() I got Expected function to throw an exception.. And tried:-
ClassUnderTest.someMethod(withSomeParams)
.subscribe( res => res,
err => console.log(err))
and I got Error: 1 periodic timer(s) still in the queue.
I don't understand how to write this expectation for when the error is thrown.
You need to pass the function itself into expect. The way you have it, you're passing the result of ClassUnderTest.someMethod(withSomeParams) in.
You are actually doing it correctly in expect(() => ClassUnderTest.someMethod(withSomeParams)).toThrow(). The error is either due to an actual error in your implementation, or because of this binding with arrow functions.
To fix this, you can try:
expect(function () { ClassUnderTest.someMethod(withSomeParams) };).toThrow()
or:
expect(ClassUnderTest.someMethod.bind(null, withSomeParams)).toThrow()
See this StackOverflow post and the .toThrow section in the Jasmine docs.
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