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 not working with semi-complex (but legal) property names #1792

Closed
6 tasks done
CodexHere opened this issue Aug 4, 2022 · 0 comments · Fixed by #1795 or #1958
Closed
6 tasks done

toHaveProperty not working with semi-complex (but legal) property names #1792

CodexHere opened this issue Aug 4, 2022 · 0 comments · Fixed by #1795 or #1958

Comments

@CodexHere
Copy link

CodexHere commented Aug 4, 2022

Describe the bug

On an object (logged before assertion), we can see some properties defined correctly, however when testing via expects assertions it fails incorrectly expecting undefined

expect(fixture).toHaveProperty('plugin-behavior-v1.0.0');

Returns Error:

ssertionError: expected { …(5) } to have property undefined

It seems either having more than 1 hyphen, or a combination of hyphen and period seems to break it?

Workaround is explicitly check toBeDefined like so:

  expect(fixture['plugin-behavior-v1.0.0']).toBeDefined();

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-bdcj2g?file=test%2Fbasic.test.ts&initialPath=__vitest__

System Info

(Running in Docker)

  System:
    OS: Linux 5.18 Alpine Linux
    CPU: (16) x64 AMD Ryzen 7 1700X Eight-Core Processor
    Memory: 19.72 GB / 31.28 GB
    Container: Yes
    Shell: 1.35.0 - /bin/ash
  Binaries:
    Node: 16.16.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.11.0 - /usr/local/bin/npm
  npmPackages:
    vitest: ^0.20.3 => 0.20.3

Used Package Manager

npm

Validations

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