test(phase6): align behavioural harness with client wrappers
This commit is contained in:
@@ -72,6 +72,24 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
source = source.replace(/export const\s+/g, "const ");
|
||||
source += `\nmodule.exports = { ${exportNames.join(", ")} };\n`;
|
||||
|
||||
const defaultGetJson = (url, config) => {
|
||||
if (!injected.axios || !injected.axios.get) {
|
||||
throw new Error("Missing axios.get for default getJson mock");
|
||||
}
|
||||
|
||||
return injected.axios
|
||||
.get(url, config)
|
||||
.then((response) => response.data);
|
||||
};
|
||||
|
||||
const defaultRequestJson = (config) => {
|
||||
if (!injected.axios) {
|
||||
throw new Error("Missing axios for default requestJson mock");
|
||||
}
|
||||
|
||||
return injected.axios(config).then((response) => response.data);
|
||||
};
|
||||
|
||||
const context = {
|
||||
module: { exports: {} },
|
||||
exports: {},
|
||||
@@ -85,6 +103,8 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
warn: () => {},
|
||||
error: () => {}
|
||||
},
|
||||
getJson: injected.getJson || defaultGetJson,
|
||||
requestJson: injected.requestJson || defaultRequestJson,
|
||||
...injected
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user