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 f1abaa5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/unexpected-sinon.js
Expand Up @@ -1072,9 +1072,17 @@
}
);

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.\nPlease use 'to have a call satisfying' instead:\n" +
'http://unexpected.js.org/unexpected-sinon/assertions/spy/to-have-a-call-satisfying/'
);
deprecationWarningDisplayed = true;
}
expect.errorMode = 'defaultOrNested';
var args;
if (expect.flags.exactly) {
Expand Down
24 changes: 24 additions & 0 deletions test/unexpected-sinon.spec.js
Expand Up @@ -29,6 +29,30 @@ describe('unexpected-sinon', function() {
spy = sinon.spy().named('spy1');
});

describe('deprecation warning', function() {
beforeEach(function() {
sinon.stub(console, 'warn');
});

afterEach(function() {
console.warn.restore();
});

it('renders a deprecation warning when "was called with" 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.\nPlease use 'to have a call satisfying' instead:\n" +
'http://unexpected.js.org/unexpected-sinon/assertions/spy/to-have-a-call-satisfying/'
);
});
// Make sure that the warning isn't triggered again the second time it's used:
expect(spy, 'was called with', 123);
expect(console.warn, 'was called once');
});
});

it('should inspect a spy correctly', function() {
expect(spy, 'to inspect as', /^spy\d+$/);
});
Expand Down

0 comments on commit f1abaa5

Please sign in to comment.