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

Cannot read properties of undefined (reading 'item') #97

Closed
jakeklassen opened this issue Oct 27, 2022 · 5 comments
Closed

Cannot read properties of undefined (reading 'item') #97

jakeklassen opened this issue Oct 27, 2022 · 5 comments
Labels
duplicate This issue or pull request already exists p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@jakeklassen
Copy link

Describe the bug
When leveraging test.each and running tests via the vscode extension I see this error:

TypeError: Cannot read properties of undefined (reading 'item')

The tests run just fine from the CLI.

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/jakeklassen/vitest-test-each-error
  2. Install via pnpm i or npm i - I tested both
  3. Run the tests from within visual studio code
  4. See error

Expected behavior
The tests to pass just as they do in the CLI.

Screenshots

image

Environment

(Paste info.txt content generated by the example project)

  • OS: Linux 5.15 Ubuntu 22.04.1 LTS (Jammy Jellyfish) (WSL2)
  • VSCode version: 1.72.2
  • Vitest version: 0.24.3
  • Vitest plugin version: v0.2.32

Additional context
Add any other context about the problem here.

@jakeklassen jakeklassen added the p3-minor-bug An edge case that only affects very specific usage (priority) label Oct 27, 2022
@mark-wiemer
Copy link

I'm getting the same error. When I run the sample project I get

[INFO 9:09:09 PM] [RUN.cwd] c:/Users/markw/repos/vitest-ext-basic-example
[Error 9:09:09 PM] Process exited with code 1
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] '.' is not recognized as an internal or external command,

operable program or batch file.

[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:09 PM] RECONNECT
[INFO 9:09:09 PM] WS Close
[INFO 9:09:10 PM] RECONNECT
[INFO 9:09:10 PM] WS Close

I also don't get any info.txt, running node setup.mjs gives me:

yarn install v1.22.19
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.12s.
Vitest settings updated
'C:\Users\markw\AppData\Local\Programs\Microsoft' is not recognized as an internal or external command,
operable program or batch file.
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, 
or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {     
  code: 'ERR_UNHANDLED_REJECTION'
}

@Maxim-Mazurok
Copy link

Same here, I think this is related to having multiple tests using it.each or test.each and same issue even when doing [].forEach(x => it())

This code fails when I click "run" button in test explorer next to the "isWarning":

import { describe, expect, test } from "vitest";

describe("isWarning", () => {
  test.each([
    [
      "Uncaught ReferenceError: angular is not defined in https://bla.bla/assets/vendor/angularjs-dropdown-multiselect/angularjs-dropdown-multiselect.min.js at 3:143",
      true,
    ],
    ["Cannot find default tariff with bookId '587dbb6986234155bd506185' in library books of country NZ", false],
  ])(`returns %s for %s`, (errorMessage, expected) => {
    expect(true).toBe(true);
  });
});

image

This is log:

[INFO 15:45:05] Vitest api process finished
[Error 15:45:05] [Workspace "vue-elements] Run error
[INFO 15:45:05] [Workspace vue-elements] Error: TypeError: Cannot read properties of undefined (reading 'item')
[INFO 15:45:05] Tests run end
[Error 15:45:05] Process exited with code null
[INFO 15:45:05] WS Close
[INFO 15:45:05]  ✓ src/__tests__/report-issue.spec.ts  (2 tests) 3ms

This is what I see when I click "run" button next to "returns %s for %s":

image

When I click "run" button next to the test file name - it doesn't show that error, but still shows test as not passed.

All I have to do to fix the issue is to use different test argument strings, this works fine:

import { describe, expect, test } from "vitest";

describe("isWarning", () => {
  test.each([
    ["a", true],
    ["b", false],
  ])(`returns %s for %s`, (errorMessage, expected) => {
    expect(true).toBe(true);
  });
});

and this doesn't:

import { describe, expect, test } from "vitest";

describe("isWarning", () => {
  test.each([
    ["angularjs-dropdown-multiselect/angularjs-dropdown-multiselect", true],
    ["b", false],
  ])(`returns %s for %s`, (errorMessage, expected) => {
    expect(true).toBe(true);
  });
});

I don't think it's because of the special characters, changing argument length seems to help, but that seems to be kinda random...

I also managed to do this:
image

Also all works fine in CLI.

@scarf005
Copy link

scarf005 commented Feb 8, 2023

would there be plans to address this issue later?
i'm getting same error, wish i could help solving the issue but error messages seem similar to me

@zxch3n zxch3n added the duplicate This issue or pull request already exists label Feb 9, 2023
@zxch3n
Copy link
Member

zxch3n commented Feb 9, 2023

Duplicate. Close in favor of #133

@zxch3n zxch3n closed this as completed Feb 9, 2023
@zxch3n
Copy link
Member

zxch3n commented Feb 9, 2023

@scarf005, maybe you're interested in #133 . But it's not an easy fix

@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

5 participants