muk-prop
Mock object methods and properties.
Last updated 20 days ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install muk-prop 
SYNC missed versions from official npm registry.

muk-prop.js

npm Node.js CI codecov

muk

Usage

Object method mocking.

const fs = require('fs');
const muk = require('muk-prop');

muk(fs, 'readFile', (path, callback) => {
  process.nextTick(callback.bind(null, null, 'file contents here'));
});

Object property mocking with getter/setter.

const muk = require('muk-prop');

const obj = { _a: 1 };
muk(obj, 'a', {
  get: (val) => obj._a,
  set: (val) => (obj._a = val * 2),
});

obj.a = 2;
console.log(obj.a); // 4

Check if property has been mocked.

muk.isMocked(fs, 'readFile'); // true

Restore all mocked methods/props after tests.

muk.restore();

fs.readFile(file, (err, data) => {
  // will actually read from `file`
});

Install

npm install muk-prop

Tests

Tests are written with mocha

npm test

Current Tags

  • 3.0.2                                ...           latest (20 days ago)

10 Versions

  • 3.0.2                                ...           20 days ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 1.2.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           10 years ago
  • 0.5.3                                ...           10 years ago
Maintainers (2)
Downloads
Total 31
Today 0
This Week 0
This Month 12
Last Day 0
Last Week 6
Last Month 7
Dependencies (0)
None
Dev Dependencies (11)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE