Saturday, May 11, 2024
42
rated 0 times [  47] [ 5]  / answers: 1 / hits: 42371  / 14 Years ago, mon, january 10, 2011, 12:00:00

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


More From » unit-testing

 Answers
16

The answer seems to be ...



expect(A.NONEXISTINGPROP).not.toBeDefined(); 


ie remove the name bit


[#94296] Saturday, January 8, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
halleyb

Total Points: 604
Total Questions: 96
Total Answers: 115

Location: Tokelau
Member since Wed, Oct 14, 2020
4 Years ago
halleyb questions
;