-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Document how expect().toHaveProperty works with a dot in the property name. #5653
Comments
Oh, I can see your confusion, we don't have a proper documentation for this usecase! expect(response).toHaveProperty(['TLS1.0'])
expect(response).toHaveProperty(['TLS1.1'])
expect(response).toHaveProperty(['TLS1.2'])
expect(response).toHaveProperty(['X.509Token']) |
The changes I'd like to see in the docs are following: const houseForSale = {
bath: true,
bedrooms: 4,
kitchen: {
amenities: ['oven', 'stove', 'washer'],
area: 20,
wallColor: 'white',
+ 'nice.oven': true,
},
}; expect(houseForSale).toHaveProperty(['kitchen', 'amenities', 0], 'oven');
+ expect(houseForSale).toHaveProperty(['kitchen', 'nice.oven'])
expect(houseForSale).not.toHaveProperty(['kitchen', 'open']); to be found here: https://github.com/facebook/jest/blob/master/docs/ExpectAPI.md#tohavepropertykeypath-value |
Thank you so much! That worked perfectly. Faith restored. ;) |
Oops! I see you changed the title, so I won't close this as it should be added to the documentation. Thanks! |
I can update documentation 👍 |
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. |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
toHaveProperty fails with nested property that has a dot (".") in the name.
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can
yarn install
andyarn test
.Here is the data. It was originally xml from a soap message, then converted to json via package xml2js.
let response = {"AccessPolicyConfig": "false", "DefaultAccessPolicy": "true", "Dot1X": "false", "HttpDigest": "false", "KerberosToken": "false", "OnboardKeyGeneration": "false", "RELToken": "false", "RemoteUserHandling": "false", "SAMLToken": "false", "SupportedEAPMethods": "0", "TLS1.0": "false", "TLS1.1": "false", "TLS1.2": "false", "UsernameToken": "true", "X.509Token": "false"}
These tests fail:
expect(response).toHaveProperty('TLS1.0')
expect(response).toHaveProperty('TLS1.1')
expect(response).toHaveProperty('TLS1.2')
expect(response).toHaveProperty('X.509Token')
REPL.IT example:
https://repl.it/@hawkeye64/dot-in-property-test-fail
What is the expected behavior?
The have
expect().toHaveProperty()
to not fail.Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Jest v22.1.2 node v7.4.0 linux/amd64
config.json:
{
"testRegex": ".*-test\.js$",
"testEnvironment": "node"
}
The text was updated successfully, but these errors were encountered: