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

toMatchObject(): Error: [vitest] No "Symbol(Symbol.toStringTag)" export is defined #2859

Closed
6 tasks done
yuliankarapetkov opened this issue Feb 13, 2023 · 0 comments · Fixed by #3036
Closed
6 tasks done

Comments

@yuliankarapetkov
Copy link

yuliankarapetkov commented Feb 13, 2023

Describe the bug

I am mocking a module:

vi.mock("country-region-data", () => {
    return {
        allCountries: ["UK"],
        UK: "UK",
    }
})

Then, testing it:

// getCountries just imports the module - import("country-region-data")
const result = await getCountries()

expect(result).toMatchObject({
  allCountries: ["UK"],
  UK: "UK",
})

When I run the test, I get the following error:

Error: [vitest] No "Symbol(Symbol.iterator)" export is defined on the "country-region-data" mock. 
Did you forget to return it from "vi.mock"?

If I spread the object in expect (expect({ ...result })), the test succeeds.

I think it shouldn't expect an iterator in this case.

Reproduction

https://stackblitz.com/edit/node-pnfxmw?file=test%2Fcountries.test.ts,package.json

System Info

System:
    OS: macOS 13.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 1.06 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.2.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.13.1 - 
  Browsers:
    Brave Browser: 110.1.48.158
    Chrome: 109.0.5414.119
    Firefox: 105.0.1
    Safari: 16.2
  npmPackages:
    vite: ^4.1.1 => 4.1.1 
    vitest: ^0.28.4 => 0.28.4

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
Development

Successfully merging a pull request may close this issue.

2 participants