question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.toExcludeKeys not working as expected

See original GitHub issue

Hey,

thanks for this great library.

I just came across .toExcludeKeys. And for me it feels that something is wrong here. The docs say:

does not contain any of the provided keys

Which sounds to me, if there is at least one key in the provided keys which is contained in the given object, it should fail.

But then on the other side there is even a test like this

it('does not throw when even one key does not exist', () => {
  expect(() => {
    expect({ a: 1, c: 3 }).toExcludeKeys([ 'a', 'b', 'c' ])
  }).toNotThrow()
})

That looks more like, there needs to be at least on key in keys which is not in object and then it’s fine.

Thanks.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:15

github_iconTop GitHub Comments

2reactions
wilkesreidcommented, Dec 20, 2016

expect([a: 0, c: 0]).toExcludeAnyKeys(['a', 'b', 'c'])

Could be read as:

Expect [ a: 0, c: 0 ] to be missing at least one of the following keys: [ ‘a’, ‘b’, ‘c’ ]

This should pass, because [ a: 0, b: 0 ] excludes the key b.


expect([a: 0, c: 0]).toExcludeAllKeys(['a', 'b', 'c'])

Could be read as:

Expect [ a: 0, c: 0 ] to be missing all of the following keys: [ ‘a’, ‘b’, ‘c’ ]

Should throw (not pass), because [ a: 0, c: 0 ] only excludes b, but does not exclude a or c

1reaction
sfrdmncommented, Jan 12, 2017

@ljharb For sure 😃 I was just trying to sort out how we’re defining toExcludeAnyKeys and toExcludeAllKeys

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bountysource
toExcludeKeys not working as expected.
Read more >
Issues · mjackson/expect - GitHub
Contribute to mjackson/expect development by creating an account on GitHub. ... mjackson / expect Public ... toExcludeKeys not working as expected.
Read more >
Expect-legacy NPM | npm.io
Asserts that a given value is not included (or "contained") within another. The actual value may be an array, object, or a string....
Read more >
Array Assertions - dylanparry/ceylon GitHub Wiki - GitHub Wiki SEE
expect (item: T[]).toExcludeKey(key: number, message?: string): this;. Asserts that the array item does not include the key . Outputs an optional message in...
Read more >
mjackson/expect - Github repository analysis (Apr 2022)
What is mjackson/expect diagnostic on project size, quality, productivity, ... on an npm tag that is not "latest", to avoid causing problems for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found