Unit Test Framework

Good Day

We are trying to implement unit tests and tried Jest which works beautifully. The problem started when we introduced a unit test which relied on a custom module build in npm. This module exports the code in two packages: commonjs and AMD. When we use the unit test with the commonjs module, then Jest works and the unit tests passes. If however we switch and want to use the AMD module, then Jest complains that “define is not defined”.

After spending some time on Google it seems like Jest does not support AMD (requirejs). There is an open ticket to support it but it is 4 years old. Ideally we would like to do unit tests with AMD modules as the application runs in a browser.

We also tried to get Karma working but has struggled to get it to see all the sources and 3rd party libraries.

Is there any other unit testing frameworks which support AMD (requirejs) or any other recommendations with regards to a unit testing framework?

These unit tests are not UI component specific and are more focused on business logic within the browser.

Any help appreciated

1 Like

If you take cli setup for requirejs+karma+jasmine, it actually bundles every thing before sending to browser, so you don’t have the missing 3rd party libs problem.

One suggestion: you actually do NOT need AMD build for your module to support browser. Every bundlers (webpack/browserify/cli-bundler) support commonjs module directly. cli-bundler wraps commonjs into AMD module automatically.