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 doesn't support array syntax #937

Closed
6 tasks done
kalvenschraut opened this issue Mar 14, 2022 · 0 comments
Closed
6 tasks done

toHaveProperty doesn't support array syntax #937

kalvenschraut opened this issue Mar 14, 2022 · 0 comments

Comments

@kalvenschraut
Copy link
Contributor

kalvenschraut commented Mar 14, 2022

Describe the bug

Not sure if this is really a bug or not, but since docs talk about jest and vitest compability this is one area I ran into that seems to be the exception. Basically jest allows you to specify the keys in an array instead as talked about here. The edge case I ran into is mainly the fact that a key has a dot in it (key is a domain name) so when we pass the domain name to the toHaveProperty function it tries to get the property deeply that doesn't exist. Solution Jest has is to wrap it in an array but then we get, the argument to property must be string when using nested syntax which seems to be from chai itself.

Reproduction

test('to Have Property can receive an error', () => {
  const domainKey = 'somedomain.com'
  const object = {
    [domainKey]: 'foo'
  }
  expect(object).toHaveProperty([domainKey], 'foo')
});

System Info

OS: Linux 5.10 Gentoo/Linux
                                                                                                                                                                                       
 CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
                                                                                                                                                                                    
 Memory: 4.72 GB / 31.33 GB
                                                                                                                                                                                     
 Container: Yes
                                                                                                                                                                                     
 Shell: 5.1.8 - /bin/bash
                                                                                                                                                                                     Binaries:
                                                                                                                                                                                    
  Node: 16.10.0 - /usr/bin/node
                                                                                                                                                                                    
  npm: 6.14.15 - /usr/bin/npm
                                                                                                                                                                                     
  Watchman: 4.9.0 - /usr/bin/watchman
                                                                                                                                                                                    Browsers:
                                                                                                                                                                                     
  Chromium: 95.0.4638.69
                                                                                                                                                                                    
   Firefox: 91.3.0esr

Used Package Manager

pnpm

Validations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant