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: [kotest-assertions-json] shouldContainJsonKey should be true for keys with null values #3128

Merged

Conversation

msewell
Copy link
Contributor

@msewell msewell commented Jul 28, 2022

We noticed that for a JSON object which contains property with null values like this:

{
  "nullable": null
}

the shouldContainJsonKey("nullable") matcher would throw even though the key was present, which was against our expectations.

The changes in this PR will make shouldContainJsonKey(:) not throw for keys with null values. This is a breaking change ⚠️, as tests relying on the previous behavior may break.

@sksamuel
Copy link
Member

So the question is, should shouldContainJsonKey consider a null value as present or not.

@msewell
Copy link
Contributor Author

msewell commented Jul 29, 2022

So the question is, should shouldContainJsonKey consider a null value as present or not.

I think that's the wrong way to think about it, even if it does address the implementation issue. The question is (IMO): should someJsonString.shouldContainJsonKey(keyName) ever throw if keyName is present as a key in someJsonString? I don't think it should, regardless of the value belonging to that key; it is only the presence of the key itself that should be considered.

@sksamuel
Copy link
Member

sksamuel commented Jul 29, 2022 via email

@sksamuel sksamuel merged commit b4dc446 into kotest:master Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants