Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Any JavaScript Test Frameworks Support ES Modules

Do any test frameworks support tests that use the new ES Modules syntax? I have a JS application which heavily uses .mjs files with ES Modules. I tried Jest and Jasmine, both of which throw errors when I try to write run tests for my app. I need to test this file:

math.mjs

export function add(a, b) {
  return a + b;
}
like image 771
Justin Avatar asked Jan 03 '20 19:01

Justin


People also ask

Does jest support ESM?

Jest ships with experimental support for ECMAScript Modules (ESM).

Is jest better than Mocha?

Jest is also faster than Mocha. It has built-in support for snapshot testing, which means tests are run automatically on each change to the code. This makes it easy to keep your tests up to date as you work. Mocha has more features out of the box since it is a more mature tool with a larger community of contributors.

What is JavaScript ES module?

ES modules are the standard for JavaScript, while CommonJS is the default in Node. js. The ES module format was created to standardize the JavaScript module system. It has become the standard format for encapsulating JavaScript code for reuse. The CommonJS module system, on the other hand, is built into Node.


1 Answers

Other test runners with support for ES Modules are:

  • AVA: AVA 4 explicitly mentions ESM, but I've also used AVA 3 with ES modules without problems
  • UVU: A lightweight test runner that supports ES Modules and does not pull tons of dependencies into the project
like image 71
laberning Avatar answered Oct 15 '22 12:10

laberning