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

toHaveProperty returning unexpected result #5495

Closed
evictor opened this issue Feb 8, 2018 · 3 comments
Closed

toHaveProperty returning unexpected result #5495

evictor opened this issue Feb 8, 2018 · 3 comments

Comments

@evictor
Copy link

evictor commented Feb 8, 2018

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Oddly, toHaveProperty is incorrectly marking a failure. As you can see in the error details below, it should be passing:

19:15:04     Expected the object:
19:15:04       {"_id": "5a7bc0b6d44d9300287bc66b", "examAnswerSpecId": "ageGroup14AndUnder", "examQuestionSpecId": "ageGroup"}
19:15:04     To have a nested property:
19:15:04       "examQuestionSpecId"
19:15:04     With a value of:
19:15:04       "ageGroup"
19:15:04 
19:15:04       59 |     expect(exam.answers).toHaveLength(1)
19:15:04       60 |     const retrievedAnswer = exam.answers[0]
19:15:04     > 61 |     expect(retrievedAnswer).toHaveProperty('examQuestionSpecId', q.id)
19:15:04       62 |     expect(retrievedAnswer).toHaveProperty('examAnswerSpecId', a.id)
19:15:04       63 |   })
19:15:04       64 | })

The test passes when I convert the expect from using toHaveProperty to an 'ordinary' expectation:

expect(retrievedAnswer.examQuestionSpecId).toEqual(q.id)

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Jest version: v22.1.4
Node version: v9.4.0
npm version: 5.6.0
OS: Linux e902ac7b5568 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 GNU/Linux

Jest configuration is vanilla—verbose mode on, and a setup file specified that does app-specific stuff.

@SimenB
Copy link
Member

SimenB commented Feb 8, 2018

Can you create a reproduction case we can pull down?

@evictor
Copy link
Author

evictor commented Feb 8, 2018

I created this repo but it's not reproducing... So going to close this for now.

@evictor evictor closed this as completed Feb 8, 2018
@github-actions
Copy link

This issue 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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants