filter object and return count in jasmine -
i'm new jasmine-karma. trying figure out how execute below scenario.
this works fine
describe("jasmine.objectcontaining", function() { var foo; beforeeach(function() { foo = { a: 1, b: 2, bar: "baz" }; }); it("matches objects expect key/value pairs", function() { expect(foo).toequal(jasmine.objectcontaining({ bar: "baz" })); }); });
but if change object array of objects doesn't work. so, how filter array of objects , return count.
eg.
describe("jasmine.objectcontaining", function() { var foo; beforeeach(function() { foo = [{ a: 1, b: 2, bar: "baz" }, { a: 1, b: 2, bar: "bdd" } ]; }); it("matches objects expect key/value pairs", function() { expect(foo).//find object(s) containing bar:"baz" , should return count=1 })); }); });
without jasmine.objectcontaining
can implemented us:
describe("array.filter returns entries", function() { var foo; beforeeach(function() { foo = [{ a: 1, b: 2, bar: "baz" }, { a: 1, b: 2, bar: "bdd" } ]; }); it("matched key/value", function() { expect(foo.filter(function(element) { return element.bar === 'baz' }).length).tobe(1); }); });
<link href="//safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine.css" rel="stylesheet" /> <script src="//safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine-2.0.3-concated.js"></script>
Comments
Post a Comment