Skip to content

Commit

Permalink
stop allowing name as second argument
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Jun 15, 2024
1 parent 29aa99a commit a6f22b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/_api-mocking/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ parameters:
- String
content: |
More options to configure matching and responding behaviour.
Alternatively, use this parameter to specify a name for the route in order to make retrieving he calls it handles a little more intuitive
Alternatively, use this parameter to pass a string to use as a name for the route in order to make using the call inspection API easier.
content_markdown: |-
Alternatively a single parameter, `options`, an Object with `matcher`, `response` and other options defined, can be passed in.
Expand Down
23 changes: 10 additions & 13 deletions src/Route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,19 @@ class Route {
Object.assign(routeConfig, matcher);
}

let options = nameOrOptions;
if (typeof response !== 'undefined') {
routeConfig.response = response;
}

if ('response' in routeConfig) {
if (args.length === 2 && typeof response === 'string') {
options = nameToOptions(response);
}
} else {
if (typeof response !== 'undefined') {
routeConfig.response = response;
}
if (typeof nameOrOptions === 'string') {
options = nameToOptions(nameOrOptions);
}
if (nameOrOptions) {
Object.assign(
routeConfig,
typeof nameOrOptions === 'string'
? nameToOptions(nameOrOptions)
: nameOrOptions,
);
}

Object.assign(routeConfig, options);
Object.assign(this, routeConfig);
}

Expand Down
6 changes: 0 additions & 6 deletions test/specs/routing/naming-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,4 @@ describe('multiple routes', () => {
fm.fetchHandler('http://a.com');
expect(fm.called('my-name')).toBe(true);
});

it('string in second parameter if only one other parameters supplied', () => {
fm.mock({ url: 'http://a.com', response: 200 }, 'my-name');
fm.fetchHandler('http://a.com');
expect(fm.called('my-name')).toBe(true);
});
});

0 comments on commit a6f22b5

Please sign in to comment.