Follow

Has anybody ever used Jest in a project which uses the import statement, and is willing to help me?

It’s very important that I add unit tests to my project because it’s becoming more and more stressful to publish new releases because of how easy it is to introduce regressions…

Boost appreciated. :)

I mean, both:
import { sidetab } from "../sidetab.js";

and:
const sidetab = require("../sidetab.js");

result in:
SyntaxError: Cannot use import statement outside a module

Why the Jest documentation is talking about how to use Jest with modules?? Or did I miss something obvious

@ariasuni this syntax isn't nativaly supported in Node (well it is but on .mjs files and behind a flag iirc) so you need ~something~ to do the transpiling for you.

You mentioned TypeScript earlier? Do you use it on that project? Because => kulshekhar.github.io/ts-jest/

@Eramdam well I found that I should install `@babel/present-env` and create a babel.config.js file with minimal content but damn the documentation is really terrible…

I guess they suppose everyone is using babel so I couldn’t find anything except this[1], which is not clear because I don’t (explicitely) want to use babel.

I hate how much implicit is in the documentation of almost every JavaScript library, I always lose a lot of time figuring out things that are not told… :/

[1]: jestjs.io/docs/en/getting-star

@Eramdam Even basic things like e.g. Jest documentation don’t tell you how Jest finds tests you wrote, you have to search on the web

@Eramdam Anyway I’ll try to concentrate on writing unit tests that covers most of the code before rewriting in TypeScript, because that’s really the absence of unit tests that’s slowing me down in the development (and well I’m getting tired of introducing regressions).

@ariasuni yeah no Jest’s doc is… not amazing. Feel free to hit me up if you struggle with those, that’s my daily life at work so I’m used to those tools (for better or worse ^^)

Sign in to participate in the conversation
Mastodon for Tech Folks

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!