muk-prop
Mock object methods and properties.
Last updated 9 years ago by fent .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install muk-prop 
SYNC missed versions from official npm registry.

muk-prop.js

Build Status Dependency Status 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 props mocking with setter/getter.

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

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

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

Check if member 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

  • 1.2.1                                ...           latest (8 years ago)

7 Versions

  • 1.2.1                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.5.3                                ...           9 years ago
Maintainers (2)
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |