Skip to content

Commit

Permalink
was [always] called with [exactly]: console.warn an error on the firs…
Browse files Browse the repository at this point in the history
…t invocation
  • Loading branch information
papandreou committed Jan 19, 2019
1 parent 550b961 commit 8d6493a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/unexpected-sinon.js
Expand Up @@ -1072,9 +1072,16 @@
}
);

var deprecationWarningDisplayed = false;
expect.addAssertion(
'<spy> was [always] called with [exactly] <any*>',
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) {
Expand Down
20 changes: 20 additions & 0 deletions test/unexpected-sinon.spec.js
Expand Up @@ -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);
Expand Down

0 comments on commit 8d6493a

Please sign in to comment.