1

When I run yarn test Jest throws an error that says

'Const declarations' require an initialization value.

Which is not what I'm doing!

> 4 | const config: HardhatUserConfig = {
    |             ^
  5 |   solidity: "0.8.9",
  6 |   paths: {
  7 |     artifacts: "./src/artifects",

I think it is obvious that jest is having problem with TS syntax.
How can I fix that?

Yaya
  • 4,402
  • 4
  • 19
  • 43
  • https://stackoverflow.com/q/58261143/438992, https://stackoverflow.com/q/56631104/438992, etc? – Dave Newton Jul 18 '22 at 22:54
  • Does this answer your question? [Jest configure typescript without webpack](https://stackoverflow.com/questions/56631104/jest-configure-typescript-without-webpack) – Terry Jul 18 '22 at 22:55

1 Answers1

1

You need to use ts-jest.

  • Install ts-jest: npm install ts-jest -D
  • Update your jest config to use: preset: 'ts-jest'

You still run your tests the same way - just run jest.

Ryan Wheale
  • 26,022
  • 8
  • 76
  • 96
  • I got `TypeError: Jest: a transform must export a "process" function.` – Yaya Jul 18 '22 at 23:04
  • Hmm, I'm not sure why that would be happening. Make sure to follow the instructions on the ts-jest project page and report back here (if you don't mind). – Ryan Wheale Jul 18 '22 at 23:07
  • Sure!‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎ – Yaya Jul 18 '22 at 23:08
  • 1
    Thanks it worked! The problem with the second error was that I should use major versions for both `Jest` and `ts-jest` – Yaya Jul 18 '22 at 23:25