我有一个对象可以根据我的被测行为进行扩展,但我想确保原始属性仍然存在.
I have an object that may be extended along my behavior under test, but I want to make sure that the original properties are still there.
var example = {'foo':'bar', 'bar':'baz'}
var result = extendingPipeline(example)
// {'foo':'bar', 'bar':'baz', 'extension': Function}
expect(result).toEqual(example) //fails miserably
我想要一个匹配器,在这种情况下可以通过,如下所示:
I'd like to have a matcher that would pass in this case, along the lines of:
expect(result).toInclude(example)
我知道我可以编写一个自定义匹配器,但在我看来,这是一个非常普遍的问题,应该已经有了解决方案.我应该在哪里寻找它?
I know that I can write a custom matcher, but it seems to me that this is such a common problem that a solution should be out there already. Where should I look for it?
Jasmine 2.0
Jasmine 2.0
expect(result).toEqual(jasmine.objectContaining(example))
自从这个修复:https://github.com/pivotal/jasmine/commit/47884032ad255e8e15144dcd3545c3267795de/一>它甚至适用于嵌套对象,您只需将要部分匹配的每个对象包装在 jasmine.objectContaining()
简单示例:
it('can match nested partial objects', function ()
{
var joc = jasmine.objectContaining;
expect({
a: {x: 1, y: 2},
b: 'hi'
}).toEqual(joc({
a: joc({ x: 1})
}));
});
这篇关于是否有茉莉花匹配器来比较对象的属性子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 javascript 认为文档“准备好"之前,如何让How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 认为文档“准备好
jasmine 运行和等待实际上是做什么的?What do jasmine runs and waitsFor actually do?(jasmine 运行和等待实际上是做什么的?)
如何提供模拟文件来更改 <input type='filHow to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模拟文件来更改 lt;input type=filegt; 的事
如何使用 Jasmine 对链式方法进行单元测试How to unit test a chained method using Jasmine(如何使用 Jasmine 对链式方法进行单元测试)
如何将 $rootScope 注入 AngularJS 单元测试?How do I inject $rootScope into an AngularJS unit test?(如何将 $rootScope 注入 AngularJS 单元测试?)
Jasmine - 如何监视函数中的函数调用?Jasmine - How to spy on a function call within a function?(Jasmine - 如何监视函数中的函数调用?)