Skip to content

Commit

Permalink
Add test with response.url
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Jun 28, 2023
1 parent 4cea127 commit e055b3e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re
hit(source);
try {
const origResponse = await Reflect.apply(target, thisArg, args);
// In the case of apps, the blocked request has status 500
// and no error is thrown, so it's necessary to check response.ok
// https://github.com/AdguardTeam/Scriptlets/issues/334
if (!origResponse.ok) {
return noopPromiseResolve(strResponseBody, fetchData.url, responseType);
}
Expand Down
1 change: 1 addition & 0 deletions tests/scriptlets/prevent-fetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ if (!isSupported) {
assert.strictEqual(response.ok, true, 'Request blocked');
done();
}
assert.ok(response.url.includes('/blocked_request.json'), 'Response URL is mocked');
assert.ok(isEmptyObject(parsedData), 'Response is mocked');
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
done();
Expand Down

0 comments on commit e055b3e

Please # to comment.