Moquire
mock the dependencies of AMD modules when testing
This is a simple JavaScript project for mocking AMD modules, which is useful when testing the functionality and behaviour of individual modules. Moquire is designed to work like the require method provided by require.js, taking an optional first argument which is an object of mocked modules.
Below are some example use cases. Have a look at the tests directory on how to set everything up to work for a large project.
Function exactly the same as require
The following shows how to use moquire as a drop in replacement for require.
;
Replace dependency with custom module
Simple modules which don't have any dependencies can be mocked inline:
//This module abstracts away the ajaxLib from the main application; //This module lets you increment a value and send the result to the server; ;
Replace dependency with another module
You can place the mock module in another file, and require will find it for you
//This could be in another file, named backendMock.js; ;
Replace dependency for only some objects
You can place the mock module in another file, and require will find it for you
;
Configuration
For the mocking to work correctly, moquire needs the same configuration as require. The best way to ensure this is to configure everything the following way:
require;