From 8d6493af8289317ed2c70b0559b8089b3167faba Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sat, 19 Jan 2019 17:38:59 +0100 Subject: [PATCH] was [always] called with [exactly]: console.warn an error on the first invocation --- lib/unexpected-sinon.js | 7 +++++++ test/unexpected-sinon.spec.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/unexpected-sinon.js b/lib/unexpected-sinon.js index d3e080b..d4f92de 100644 --- a/lib/unexpected-sinon.js +++ b/lib/unexpected-sinon.js @@ -1072,9 +1072,16 @@ } ); + var deprecationWarningDisplayed = false; expect.addAssertion( ' was [always] called with [exactly] ', function(expect, subject) { + if (!deprecationWarningDisplayed) { + console.warn( + "unexpected-sinon: The 'was [always] called with [exactly]' assertion is deprecated" + ); + deprecationWarningDisplayed = true; + } expect.errorMode = 'defaultOrNested'; var args; if (expect.flags.exactly) { diff --git a/test/unexpected-sinon.spec.js b/test/unexpected-sinon.spec.js index 2217751..74a86e5 100644 --- a/test/unexpected-sinon.spec.js +++ b/test/unexpected-sinon.spec.js @@ -442,6 +442,26 @@ describe('unexpected-sinon', function() { }); describe('was called with', function() { + beforeEach(function() { + sinon.spy(console, 'warn'); + }); + + afterEach(function() { + console.warn.restore(); + }); + + it('only renders the warning once when the assertion is called the first time', function() { + spy(123); + expect(spy, 'was called with', 123); + expect(console.warn, 'to have calls satisfying', function() { + console.warn( + "unexpected-sinon: The 'was [always] called with [exactly]' assertion is deprecated" + ); + }); + expect(spy, 'was called with', 123); + expect(console.warn, 'was called once'); + }); + it('passes if the spy was called with the provided arguments', function() { spy('something else'); spy({ foo: 'bar' }, 'baz', true, false);