You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
I have been working mockery for some time but since the core API is verbose we have create a wrapper to simplify the use of mockery but i think it would be nicer to have something like that merged in the official repo.
// This is the wrapper we use to mockfunctionmockRequire(mocks,callback){mockery.enable({warnOnUnregistered: mocks.warnOnUnregistered,useCleanCache: !mocks.useCache});Object.keys(mocks).forEach(function(lib){mockery.registerMock(lib,mocks[lib]);});try{callback(mocks);}finally{mockery.deregisterAll();mockery.disable();}}// This are the tests for this featuredescribe('#mockReqire',function(){it('mocks some libs',function(){vartdMocked;varfsMocked;mockRequire({'../index': 'I am Mocked!','fs': 'I am NOT real!'},function(){tdMocked=require('../index');fsMocked=require('fs');});assert.equal(tdMocked,'I am Mocked!');assert.equal(fsMocked,'I am NOT real!');assert.notDeepEqual(tdMocked,require('../index'));assert.notDeepEqual(fsMocked,require('fs'));});});// Usecase Example describe('SomeComponent',function(){varSomeComponent;mockRequire({'../services': mockServices,'api': mockAPI},function(){SomeComponent=require('../../services/yFinLists/trending_tickers');});it('tests stuff on the component',function(){
...
});
The advantage is because you can mock several modules at once and there is not need to use before/after hocks. This feature is very useful for the projects I am working and I would be glad to submit a PR.
The text was updated successfully, but these errors were encountered:
I never tried proxyquire but it looks very similar to what i am currently doing with mockery the main difference is that proxyquire returns an object with the mocked stuff and the mockRequire gives you a callback to do whatever you want.
I think that implementing something like what was suggested above on mockery would still be helpful. But thanks for the suggestion 👍
I have been working mockery for some time but since the core API is verbose we have create a wrapper to simplify the use of mockery but i think it would be nicer to have something like that merged in the official repo.
The advantage is because you can mock several modules at once and there is not need to use before/after hocks. This feature is very useful for the projects I am working and I would be glad to submit a PR.
The text was updated successfully, but these errors were encountered: