From 42f9483edf1091855cc9c7d3a100ef02f6368ad3 Mon Sep 17 00:00:00 2001 From: Sergej Shafarenka Date: Tue, 5 Sep 2017 13:09:04 +0200 Subject: [PATCH] Adding a compare function to be used in expected object template (#66) * Adding compare function to be used in expected object template * Adding compare function example to README.md --- test/unit/chai-subset.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/chai-subset.spec.js b/test/unit/chai-subset.spec.js index 3fc4e282..042067d3 100644 --- a/test/unit/chai-subset.spec.js +++ b/test/unit/chai-subset.spec.js @@ -126,6 +126,20 @@ describe('circular objects', function() { }); }); +describe('object with compare function', function() { + it('should pass when function returns true', function () { + expect({a: 5}).to.containSubset({a: a => a}); + }); + + it('should fail when function returns false', function () { + expect({a: 5}).to.not.containSubset({a: a => !a}); + }); + + it('should pass for function with no arguments', function () { + expect({a: 5}).to.containSubset({a: () => true}); + }); +}); + describe('comparison of non objects', function () { it('should fail if actual subset is null', function () { expect(null).to.not.containSubset({a: 1});