Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Regression: Allow toHaveBeenCalledWith and related functions to test calls with no arguments #1951

Merged
merged 3 commits into from Oct 19, 2016

Conversation

benmccormick
Copy link
Contributor

Summary

This PR adds a failing test for the issue identified in #1899 to help expose the issue and prevent future regressions.

Test plan

running npm test in the repo with this change causes tests to fail for now, as expected since Jest16 regresses when testing functions that have been called without arguments.

Ben McCormick added 2 commits October 18, 2016 21:40
arguments

This behavior broke in Jest 16, so adding a test to document it for the
future.  Also renamed another test that appeared to cover this case but
did not.
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions.

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@benmccormick
Copy link
Contributor Author

I would love some pointers in terms of fixing this issue. I dug into it a bit last week, but the code around the spy matchers seems to have been heavily refactored in the past release, and I couldn't trace down the regression. I'd be happy to take a pointer to where the code determines which arguments are passed to the matcher, and try to flesh this PR out from there

@cpojer
Copy link
Member

cpojer commented Oct 19, 2016

@benmccormick
Copy link
Contributor Author

@cpojer yeah, I got to that point earlier. When that function is called in my basic test

it('can check that a function is called without arguments', () => {
    let fn = jasmine.createSpy();

    fn();
    expect(fn).toHaveBeenCalledWith();
});

calls is set to [ [] ] and expected is set to [undefined] .

What I'm unclear on is where the matcher is called from and what would cause expected to be [undefined] rather than []. That seemed to be in Jasmine land when I looked, but Jasmine didn't change in the version bump, and this worked in v15.

@cpojer
Copy link
Member

cpojer commented Oct 19, 2016

That should be somewhere around here: https://github.com/facebook/jest/blob/master/packages/jest-matchers/src/index.js#L55

we rewrote this matcher completely as we are trying to kill parts of Jasmine that we don't like :)

Code was previously assuming at least one argument, but that
assumption failed when a function was called with no args.
@benmccormick
Copy link
Contributor Author

benmccormick commented Oct 19, 2016

@cpojer Ah perfect, code was assuming at least one expected argument (function signature of (expected, ...rest) so I've refactored it to just pass all args along to the matcher and things seem fine now. Thanks so much for the help!

@benmccormick benmccormick changed the title Add failing test for expecting a function to have been called with no arguments Fix Regression: Allow toHaveBeenCalledWith and related functions to test calls with no arguments Oct 19, 2016
@cpojer
Copy link
Member

cpojer commented Oct 19, 2016

that makes sense! Thank you.

@cpojer cpojer merged commit 88cfb88 into jestjs:master Oct 19, 2016
okonet pushed a commit to okonet/jest that referenced this pull request Nov 11, 2016
…est calls with no arguments (jestjs#1951)

* Add failing test for expecting a function to have been called with no
arguments

This behavior broke in Jest 16, so adding a test to document it for the
future.  Also renamed another test that appeared to cover this case but
did not.

* Allow testing whether a test has been called with 0 arguments

Code was previously assuming at least one argument, but that
assumption failed when a function was called with no args.
nickpresta pushed a commit to nickpresta/jest that referenced this pull request Nov 15, 2016
…est calls with no arguments (jestjs#1951)

* Add failing test for expecting a function to have been called with no
arguments

This behavior broke in Jest 16, so adding a test to document it for the
future.  Also renamed another test that appeared to cover this case but
did not.

* Allow testing whether a test has been called with 0 arguments

Code was previously assuming at least one argument, but that
assumption failed when a function was called with no args.
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
…est calls with no arguments (jestjs#1951)

* Add failing test for expecting a function to have been called with no
arguments

This behavior broke in Jest 16, so adding a test to document it for the
future.  Also renamed another test that appeared to cover this case but
did not.

* Allow testing whether a test has been called with 0 arguments

Code was previously assuming at least one argument, but that
assumption failed when a function was called with no args.
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants