I don't like my code here, is there a proper way to use chai, something like expect([1,2]).to.contain.any.members([2,3])
? I only care if intersection exists, not the exact values.
mocha.setup("bdd");
var intersection = function(arr1, arr2) {
return arr1.filter(function(n) {
return arr2.indexOf(n) != -1;
});
};
describe("Test suite", function() {
it("should find if arrays intersect", function() {
chai.expect(intersection([1, 2], [2, 3])).not.to.be.empty;
});
});
mocha.run();
<link href="http://ift.tt/1O7xjv0" rel="stylesheet"/>
<script src="http://ift.tt/1NKbVZ4"></script>
<script src="http://ift.tt/1O7xjv2"></script>
<div id="mocha"></div>
Aucun commentaire:
Enregistrer un commentaire