Skip to content

Commit

Permalink
Improve 'Could not find mock for' message by providing headers and pa…
Browse files Browse the repository at this point in the history
…rams context
  • Loading branch information
marcbachmann committed Aug 5, 2024
1 parent f45c074 commit 99cf5e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ function convertDataAndConfigToConfig (method, data, config) {
if (methodsWithConfigsAsSecondArg.includes(method)) {
return validateconfig(method, data || {});
} else {
return validateconfig(method, Object.assign({}, config || {}, { data: data }));
return validateconfig(method, Object.assign({}, config, { data: data }));
}
}

var allowedConfigs = ['headers', 'params', 'data'];
var allowedConfigProperties = ['headers', 'params', 'data'];
function validateconfig (method, config) {
for (var key in config) {
if (!allowedConfigs.includes(key)) {
if (!allowedConfigProperties.includes(key)) {
throw new Error(
'Invalid config attribute ' +
key +
'Invalid config property ' +
JSON.stringify(key) +
' provided to ' +
toMethodName(method) +
'. Config: ' +
Expand Down
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ function createAxiosError(message, config, response, code) {
function createCouldNotFindMockError(config) {
var message =
"Could not find mock for: \n" +
JSON.stringify(config, ["method", "url"], 2);
JSON.stringify({
method: config.method,
url: config.url,
params: config.params,
headers: config.headers
}, null, 2);
var error = new Error(message);
error.isCouldNotFindMockError = true;
error.url = config.url;
Expand Down

0 comments on commit 99cf5e9

Please # to comment.