I have the following statement
expect(A.["BAR"].name).toEqual("foo");
which due to the fact my object A has the top level property "BAR" and bar has the value "foo" passes.
I'd like to test my structure to confirm a property "NONEXISTINGPROP" has not be defined. e.g.
expect(A.["NONEXISTINGPROP"].name).not.toBeDefined();
However I seem to get
"TypeError: A.[NONEXISTINGPROP] is undefined"
in the jasmine test runner this is exactly what I want to confirm. Any idea why Jasmine is crying. I was hoping for it to pass this.
Thanks SO
ToBeUndefined() This matcher helps to check whether any variable is previously undefined or not, basically it works simply opposite to the previous matcher that is toBeDefined. In the following example, we will learn how to use this matcher.
Using the done() Method in Your Jasmine-driven Asynchronous JavaScript Tests. Jasmine. Async is an add-on library for Jasmine that provides additional functionality to do asynchronous testing. Modeled after Mocha's async test support, it brings the done() function to the Jasmine unit testing environment.
Jasmine is one of the popular JavaScript unit testing frameworks which is capable of testing synchronous and asynchronous JavaScript code. It is used in BDD (behavior-driven development) programming which focuses more on the business value than on the technical details.
The answer seems to be ...
expect(A.NONEXISTINGPROP).not.toBeDefined();
ie remove the name bit
As a follow-up, Jasmine has had toBeUndefined
since v1.3.0 (see here).
expect(A.NONEXISTINGPROP).toBeUndefined();
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