This describes how to build enzyme as a UMD (Universal Module Definition) module so it can be used in systems with legacy module loaders like RequireJS.
Browserify with the --standalone
option will be used to build the standalone Enzyme UMD module. This is a good post describing Browserify's --standalone
option: http://www.forbeslindesay.co.uk/post/46324645400/standalone-browserify-builds.
- Install npm dependencies
npm install --save-dev browserify
npm install --save-dev enzyme
npm install --save-dev react
npm install --save-dev react-addons-test-utils
npm install --save-dev react-dom
- Build using Browserify
From the command line:
./node_modules/.bin/browserify --standalone enzyme --out-dir -x 'react/addons' -x 'react/lib/ReactContext' -x 'react/lib/ExecutionEnvironment' node_modules/enzyme/build/index.js -o app_dir
Where app_dir
is the name of your require_js app dir. Alternatively, you could create a node script.
- Use in your App
define(["enzyme"], function(enzyme) {
let mount = enzyme.mount;
//...
});
What does
app_dir
mean in this case? Whatever I seem to put as argument to -o seems to be the bundled file. If I put the directory to my client-application, I get this errormessage:I tried putting
-o enzyme.js
, and then requiring that file. But then, all I got was a dependency that wasundefined
unfortunatly.It feels like I'm missing something here.