Skip to content

Commit

Permalink
add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Oct 31, 2022
1 parent dc8ab9d commit 9e76de8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/scriptlets/trusted-replace-fetch-response.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,58 @@ if (!isSupported) {
assert.deepEqual(actualJson, expectedJson, 'Content is intact');
done();
});

test('Forged response props are copied properly', async (assert) => {
const INPUT_JSON_PATH = `${FETCH_OBJECTS_PATH}/test01.json`;
const TEST_METHOD = 'GET';
const init = {
method: TEST_METHOD,
};

const done = assert.async();

const PATTERN = '';
const REPLACEMENT = '';
const PROPS_TO_MATCH = 'test01 method:GET';

const expectedResponse = await fetch(INPUT_JSON_PATH, init);

runScriptlet(name, [PATTERN, REPLACEMENT, PROPS_TO_MATCH]);

const actualResponse = await fetch(INPUT_JSON_PATH, init);

assert.strictEqual(window.hit, 'FIRED', 'hit function fired');

const {
bodyUsedExpected,
headersExpected,
okExpected,
redirectedExpected,
statusExpected,
statusTextExpected,
typeExpected,
urlExpected,
} = expectedResponse;

const {
bodyUsed,
headers,
ok,
redirected,
status,
statusText,
type,
url,
} = actualResponse;

assert.strictEqual(bodyUsed, bodyUsedExpected, 'response prop is copied');
assert.strictEqual(headers, headersExpected, 'response prop is copied');
assert.strictEqual(ok, okExpected, 'response prop is copied');
assert.strictEqual(redirected, redirectedExpected, 'response prop is copied');
assert.strictEqual(status, statusExpected, 'response prop is copied');
assert.strictEqual(statusText, statusTextExpected, 'response prop is copied');
assert.strictEqual(type, typeExpected, 'response prop is copied');
assert.strictEqual(url, urlExpected, 'response prop is copied');
done();
});
}

0 comments on commit 9e76de8

Please sign in to comment.