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

"Expected 1 arguments, but got 2." except with mysterious workarounds #65

Open
dskloetd opened this issue Feb 23, 2023 · 4 comments
Open

Comments

@dskloetd
Copy link

Bug

  • package version: 1.1.3
  • node version: 16.16.0
  • npm (or yarn) version: npm 8.11.0

What I tried initially

Initially the only things I did before using messages in expect were

  1. npm install --save-dev jest-expect-message
  2. Add import "jest-expect-message"; to jest-setup.ts.

This worked initially but after change the test and running the test again, I started getting:

> @dfinity/nns-dapp@2.0.17 test
> TZ=UTC jest "feature-flags.store.spec.ts"

 FAIL  src/tests/lib/stores/feature-flags.store.spec.ts
  ● Test suite failed to run

    src/tests/lib/stores/feature-flags.store.spec.ts:24:9 - error TS2554: Expected 1 arguments, but got 2.

    24         `FeatureFlag ${feature} should be exported from feature-flags.store.ts`
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.076 s
Ran all test suites matching /feature-flags.store.spec.ts/i.

What didn't work

I tried of all the following but the issue remained:

  1. Add "jest-expect-message", to setupFilesAfterEnv: in jest.config.cjs.
  2. Add "files": ["node_modules/jest-expect-message/types/index.d.ts"], to tsconfig.json
  3. Add "jest/valid-expect": "off", in rules: in .eslintrc.cjs.

What worked

  1. After running jest --clearCache the issue would go away, but return after making some changes and running the test again.
  2. npm install --save-dev @types/jest-expect-message made the issue go away consistently. However, the package is deprecated and when I look inside the package it looks basically empty. So I don't understand how this can have an effect.
  3. Using import "jest-expect-message"; in the test file itself rather than in jest-setup.ts works. Is this the intended way to use it?

Any insight into what might be going on would be greatly appreciated.

If you want, you can see our entire setup at dfinity/nns-dapp@main...kloet/jem3

@iessa-pragg-ctct
Copy link

I had some luck by adding the package to my tsconfig types.

{
  "compilerOptions": {
    "types": ["jest", "jest-expect-message"]
  }
}

@mrazauskas
Copy link

There is an alternative to explicitly declared "types". You can declare jest-expect-message as an @types/* package in package.json:

{
  "devDependencies": {
    "@types/jest-expect-message": "npm:jest-expect-message@*",
  }
}

Run yarn install after adding the line. All will work as if you have @types/jest-expect-message installed, but the typings will come from jest-expect-message package.

@edeesis
Copy link

edeesis commented Mar 1, 2024

The suggestion from @mrazauskas worked for me. I was also able to remove the files key from tsconfig.json. Maybe a documentation update is in order?

@Marty-Byrde
Copy link

Marty-Byrde commented Dec 30, 2024

I am using:

  • jest-expect-message version: 1.1.3
  • node version: v22.11.0
  • typescript version: 5.3.3

Following the config steps proposed in the ReadMe of this package didn't work for me either. More specifically, the step where the tsconfig.json should be modified with "files": ["node_modules/jest-expect-message/types/index.d.ts"] led to errors in my test files.

To get it working I had to do the following:

  • (Install jest-expect-messages@1.1.3 package)
  • (Add "jest-expect-message" to setupFilesAfterEnv in jest.config.*)
  • install @types/jest-expect-message version: 1.1.0
  • add the jest-expect-message types to the tsconfig.json like @iessa-pragg-ctct proposed:
{
  "compilerOptions": {
    "types": ["jest", "jest-expect-message"]
  }
}

Doing these steps allowed me to use the jest-expect-message package without further issues.

PS: Adding the import "jest-expect-message" statement to each test-suite worked too, but to remove this overhead I have modified the types property in the tsconfig.json worked, as mentioned above.

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

No branches or pull requests

5 participants