【问题标题】:PhantomJS - Test failed when comparing identical objectsPhantomJS - 比较相同对象时测试失败
【发布时间】:2017-05-02 16:16:53
【问题描述】:

我正在使用 Bootstrap(和 jQuery)开发 Angular.js 应用程序。我正在使用 Karma Jasmine 和 PhantomJS 进行测试。

我编写了一个测试,它从我的控制器运行一个方法并比较两个相同的对象。

it('should have a showDialog method which prompts a crud dialog', function () {
  ctrl.showDialog({
    id: 123,
  });
  expect(ctrl.crudDialogData).toBe({
    id: 123,
  });
});

showDialog() 方法存储传入crudDialogData 属性的参数。

在运行我的测试时,我收到以下错误:

Expected Object({ id: 123 }) to be Object({ id: 123 }).

据我所知,这应该是通行证。有什么帮助吗?

【问题讨论】:

  • 将 toBe 替换为 toEqual

标签: jquery angularjs twitter-bootstrap phantomjs karma-jasmine


【解决方案1】:

toBe 匹配 referencetoEqual匹配。看起来你想使用toEqual

相关SO回答:https://stackoverflow.com/a/27929503/803739

【讨论】:

  • 啊,是的,做到了。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多