茉莉花单元测试 - 测试对象的未定义属性 [英] jasmine unit testing - testing for an undefined property of an object

查看:169
本文介绍了茉莉花单元测试 - 测试对象的未定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下声明

expect(A.["BAR"].name).toEqual("foo"); 

由于我的对象A具有顶级属性BAR而bar具有值foo传递。

which due to the fact my object A has the top level property "BAR" and bar has the value "foo" passes.

我想测试我的结构以确认属性NONEXISTINGPROP尚未定义。
例如。

I'd like to test my structure to confirm a property "NONEXISTINGPROP" has not be defined. e.g.

expect(A.["NONEXISTINGPROP"].name).not.toBeDefined(); 

但我似乎得到了

  "TypeError: A.[NONEXISTINGPROP] is undefined" 

茉莉花测试跑步者这正是我想要确认的。知道为什么Jasmine在哭。我希望它能通过这个。

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.

谢谢SO

推荐答案

答案似乎是......

The answer seems to be ...

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

即删除名称位

这篇关于茉莉花单元测试 - 测试对象的未定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆