const sinon = require('sinon');
const proxyquire = require('proxyquire');
describe('69759888', () => {
it('should pass', async () => {
const getCompanyStub = sinon.stub().resolves({});
const Handler = proxyquire('./handler', {
'./helper': {
getCompany: getCompanyStub,
},
});
const handler = new Handler();
await handler.init();
});
});
const sinon = require('sinon');
const proxyquire = require('proxyquire');
describe('69759888', () => {
it('should pass', async () => {
const getCompanyStub = sinon.stub().resolves({});
const Handler = proxyquire('./handler', {
getCompany: getCompanyStub,
});
const handler = new Handler();
await handler.init();
});
});
const sinon = require('sinon');
const proxyquire = require('proxyquire');
describe('69759888', () => {
it('should pass', async () => {
const getCompanyStub = sinon.stub().resolves({});
const Handler = proxyquire('./handler', {
'./helper': {
getCompany: getCompanyStub,
},
});
const handler = new Handler();
await handler.init();
});
});
The Handler class you are using is required by the require function rather than proxyquire.
handler.js:
const { getCompany } = require('./helper');
module.exports = class Handler {
async init() {
await getCompany();
}
};
helper.js:
exports.getCompany = async () => {
// async calls
};
handler.test.js:
const sinon = require('sinon');
const proxyquire = require('proxyquire');
describe('69759888', () => {
it('should pass', async () => {
const getCompanyStub = sinon.stub().resolves({});
const Handler = proxyquire('./handler', {
getCompany: getCompanyStub,
});
const handler = new Handler();
await handler.init();
});
});
test result:
69759888
✓ should pass (2478ms)
1 passing (2s)
------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
handler.js | 100 | 100 | 100 | 100 |
helper.js | 100 | 100 | 100 | 100 |
------------|---------|----------|---------|---------|-------------------
lang-js