Mock using CJS
You can use your favorite Mock framework or tool and Poku together π·β
By not locking you into a specific set of plugins or mocking/spying tools, Poku promotes an open ecosystem where developers are free to integrate the tools that best suit their needs.
For this example, let's use the quibble, then testing its results with Poku:
- ./test/withdraw.test.js
- ./lib/funds.js
- ./lib/withdraw.js
const { assert } = require('poku');
const quibble = require('quibble');
(async () => {
await quibble('../lib/funds.js', {
// Original: 100
getFunds: () => 200,
});
const { withdraw } = require('../lib/withdraw.js');
assert.strictEqual(withdraw(200), true, 'Mocking my funds to 200');
assert.strictEqual(withdraw(300), false, "I can't get more than I have");
await quibble.reset();
})();
const getFunds = () => 100;
module.exports = { getFunds };
const { getFunds } = require('./funds.js');
const withdraw = (value) => {
const wallet = getFunds();
return value <= wallet;
};
module.exports = { withdraw };
Then:
npx poku