Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #101 : fixed compare URL with query string #103

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/xhr-mock/src/createMockFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import MockRequest from './MockRequest';
import MockResponse from './MockResponse';
import {createResponseFromObject} from './createResponseFromObject';

const URL_SLIPT_QUERY_REGEX = /^([^\?]+)?/g;

const LAST_SLASH_URL_REGEX = /\/$/;

export default function(
method: string,
url: string | RegExp,
Expand All @@ -22,7 +26,17 @@ export default function(
return url.test(requestURL);
}

return requestURL === url; //TODO: should we use .startsWith()???
const matchRequestUrl = requestURL.match(URL_SLIPT_QUERY_REGEX);

if (matchRequestUrl) {
const [splitUrl] = matchRequestUrl;
return (
splitUrl.replace(LAST_SLASH_URL_REGEX, '') ===
url.replace(LAST_SLASH_URL_REGEX, '')
);
}

return false;
};

return (req, res) => {
Expand Down