nutra-mock
The "nutra-mock" module is a mocking library for the "N.U.T.R.A." unit test runner. Currently, it allows for mocking of all global imports and constants in the main execution context of a valid ES6 module file. It does this by statically analyzing the file with Espree 3+ and transforms the relevant globals in the deeper contexts into objects whose properties can be changed at any time — essentially allowing you to mock just about anything!
Installation
npm install --save-dev nutra nutra-mock
Add Plugin Configuration:
Create a "nutra.config.js" config file in the root of your project and populate it with the following:
// nutra.config.jsmodule { config // For more configuration options, please take a look at: // https://github.com/m-a-r-c-e-l-i-n-o/nutra#configuration-anatomy}
Usage
In your scripts:
const Foo = { Path // This will be made available for mocking return Path} const Bar = Foo // This will also be made available for mocking
In your tests:
const Mock = NutraMock// THe path is relative to current working directory, do not include "./" or "."