pmock

0.2.3 • Public • Published

pmock

NPM

GitHub version Build Status Dependency Status devDependency Status Coverage Status

Mock any of the process properties of Node. Useful to mock things in tests, for example: environment variables, memory usage or the current working directory.

Any process property not used in the global scope (of a module) will can be mocked.

Example

Here is an example usage in a mocha test:

describe('pmock test', function() {
 
    before(function() {
        // Replace 'env' in this case.
        this.env = pmock.env({
            ENVMOCK_TEST: 'hello'
        });
        // Mock 'cwd()'
        this.cwd = pmock.cwd(__dirname + '/somelocation');
    });
 
    it('...', function() {
        // Some tests of functions that uses process.env and process.cwd()
    });
 
    after(function() {
        // Reset back to original value.
        this.env.reset();
        this.cwd.reset();
    });
 
});

Package Sidebar

Install

npm i pmock

Weekly Downloads

148

Version

0.2.3

License

MIT

Last publish

Collaborators

  • arjanfrans