32

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
wmitchell
  • 5,665
  • 10
  • 37
  • 62
  • Cant seem to answer this question directly but the answer seems to be ... expect(A.["NONEXISTINGPROP"]).not.toBeDefined(); ie remove the name bit – wmitchell Jan 10 '11 at 16:09

2 Answers2

82

The answer seems to be ...

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

ie remove the name bit

Claudiu
  • 224,032
  • 165
  • 485
  • 680
wmitchell
  • 5,665
  • 10
  • 37
  • 62
2

As a follow-up, Jasmine has had toBeUndefined since v1.3.0 (see here).

expect(A.NONEXISTINGPROP).toBeUndefined();
jonathanGB
  • 1,500
  • 2
  • 16
  • 28