immutable-automock
Advanced tools
Comparing version 0.1.1 to 0.3.0
@@ -34,7 +34,11 @@ 'use strict' | ||
* | ||
* @param {object} immutable | ||
* @param {function} method | ||
*/ | ||
function automock (method) { | ||
// require function | ||
if (typeof method !== 'function') { | ||
throw new Error('automock error: automock must be called with function') | ||
} | ||
// create automock wrapper function | ||
var automockWrapper = function automockWrapper (args) { | ||
var automockWrapper = function coreAutomockWrapper (args) { | ||
// require args to be object | ||
@@ -41,0 +45,0 @@ args = requireValidOptionalObject(args) |
@@ -17,2 +17,3 @@ 'use strict' | ||
core: require('./automock/core'), | ||
httpClient: require('./automock/http-client') | ||
}, | ||
@@ -24,5 +25,14 @@ reset: reset, | ||
/* apply automock when required */ | ||
// apply automock when first required | ||
mock() | ||
// mapping table of mock data type names to modules | ||
const moduleNameByMockDataType = { | ||
moduleCall: 'core', | ||
moduleCallResolve: 'core', | ||
httpRequest: 'httpClient', | ||
httpRequestError: 'httpClient', | ||
httpResponse: 'httpClient', | ||
} | ||
/** | ||
@@ -112,3 +122,3 @@ * @function loadMock | ||
var library = require(module.libraryName) | ||
// set automock function on library | ||
// apply automock function on library | ||
library.automock(module.automock) | ||
@@ -118,3 +128,5 @@ // set success flag | ||
} | ||
catch (ex) {} | ||
catch (ex) { | ||
console.log(ex) | ||
} | ||
}) | ||
@@ -174,8 +186,6 @@ | ||
} | ||
// load mock data for core (immutable-core) mocks | ||
if (mockData.type === 'moduleCall' || mockData.type === 'moduleCallResolve') { | ||
automock.module.core.loadMock(mockData, options) | ||
} | ||
// mock data type not recognized | ||
else { | ||
// get automock module name by mock data type | ||
var moduleName = moduleNameByMockDataType[mockData.type] | ||
// require type to be defined with module name | ||
if (!moduleName) { | ||
if (options.ignoreInvalidMockDataType) { | ||
@@ -188,2 +198,4 @@ return | ||
} | ||
// load mock into target module | ||
automock.module[moduleName].loadMock(mockData, options) | ||
} |
@@ -12,3 +12,5 @@ { | ||
"chai-as-promised": "^6.0.0", | ||
"http-promise": "^0.1.4", | ||
"immutable-core": "^0.3.2", | ||
"immutable-http-client": "^0.3.0", | ||
"mocha": "^3.0.2" | ||
@@ -26,3 +28,3 @@ }, | ||
}, | ||
"version": "0.1.1" | ||
"version": "0.3.0" | ||
} |
@@ -29,3 +29,3 @@ 'use strict' | ||
// check that foo is wrapped with automock function | ||
assert.match(fooModule.foo.toString(), /automockWrapper/) | ||
assert.match(fooModule.foo.toString(), /coreAutomockWrapper/) | ||
}) | ||
@@ -32,0 +32,0 @@ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
46368
17
1215
6
1