---
title: "Discussion on \"How to set up jest for es module\" | Hashnode"
description: "Discussion on \"How to set up jest for es module\". In this article, I will show a simple configuration to run jest tests for es module code.\nJest\nJest is a test framework developed by Facebook & often used in applications that use React. It's simple to set up & can be used to test any JS application...."
url: "https://hashnode.com/posts/how-to-set-up-jest-for-es-module/61210c18a5d08237f40e09d6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to set up jest for es module](https://how-to.dev/how-to-set-up-jest-for-es-module?utm_source=hashnode&utm_medium=feed)

In this article, I will show a simple configuration to run jest tests for es module code. Jest Jest is a test framework developed by Facebook & often used in applications that use React. It's simple to set up & can be used to test any JS application....

Aug 21, 2021 · 2 min read · how-to.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#testing](https://hashnode.com/tag/testing)

## Written by

[Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

@marcin-wosinek · Valencia, Spain

  
[View profile](https://hashnode.com/@marcin-wosinek)

JavaScript developer

I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.

## Responses 2

Markdown supported · ⌘↵ to post

[Elle K](https://hashnode.com/@DevElleUp)

[Oct 10, 2022](https://hashnode.com/posts/how-to-set-up-jest-for-es-module/61210c18a5d08237f40e09d6/comment/63445f466d64be07a724af21)

Great article! Note: I needed to assign "jest" to the "test" script in my package.json file in order for the `npm run test` script to work.

```
"scripts": {
    "test": "jest"
  },
```

Out of the box, that comes as

```
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
```

Also, I can confirm that in Oct '22, I did not need to create the .bablerc config file. I found this article because I was trying to use `spyOn` and getting the error: `SyntaxError: The requested module jest/globals does not provide an export named spyOn`. Installing the plugin to transform ES6 (modules) to CommonJS (`@babel/plugin-transform-modules-commonjs`) fixed this issue, exposing the spyOn function properly for use in my test files.

[Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

[Oct 11, 2022](https://hashnode.com/posts/how-to-set-up-jest-for-es-module/61210c18a5d08237f40e09d6/comment/63445f466d64be07a724af21#reply-63456ade07f4e412d7b028af)

Thank you so much for sharing all this information!

[Carlos Guevara](https://hashnode.com/@dejitaru)

[Jun 17, 2022](https://hashnode.com/posts/how-to-set-up-jest-for-es-module/61210c18a5d08237f40e09d6/comment/62acf0ca3d2cd8400b1bd770)

Hi, its worked! could you explain a little bit about why is the .babelrc config needed?

[Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

[Jun 18, 2022](https://hashnode.com/posts/how-to-set-up-jest-for-es-module/61210c18a5d08237f40e09d6/comment/62acf0ca3d2cd8400b1bd770#reply-62ad7e66cc6d8844e0df3d66)

Good question—I most likely added it based on some troubleshooting and advice I found online. It looks like Jest uses babel, but the configuration it has doesn't support a specific module structure.

It's almost a year ago, so maybe there are newer versions of tools available, and this configuration is not needed anymore. You can remove the plugin line from the `.babelrc`, and see if it breaks—if not, removing the plugin & the file should be fine too.

[Anonymous User](https://hashnode.com/@anonymous243)

[Feb 14, 2024](https://hashnode.com/posts/how-to-set-up-jest-for-es-module/61210c18a5d08237f40e09d6/comment/62acf0ca3d2cd8400b1bd770#reply-65cc8933818a596c36fc9462)

[Marcin Wosinek](https://hashnode.com/@marcin-wosinek) guess it is not required. its running fine even when i remove plugin property
