MCPcopy Create free account
hub / github.com/ampproject/amphtml / installBrowserWrappers

Function installBrowserWrappers

build-system/tasks/e2e/expect.js:270–302  ·  view source on GitHub ↗

* @param {Chai.ChaiStatic} chai * @param {Chai.ChaiUtils} utils

(chai, utils)

Source from the content-addressed store, hash-verified

268 * @param {Chai.ChaiUtils} utils
269 */
270function installBrowserWrappers(chai, utils) {
271 const {Assertion} = chai;
272
273 // Assert that a request with a testUrl was sent
274 // Example usage: await expect(testUrl).to.have.been.sent;
275 utils.addProperty(Assertion.prototype, 'sent', async function () {
276 // @ts-ignore
277 const that = this;
278 const url = that._obj;
279 const requests = await networkLogger.getSentRequests(url);
280 that.assert(0 < requests.length, 'expected #{this} to have been sent');
281 });
282 Assertion.overwriteProperty(
283 'sent',
284 /** @type {any} */ (overwriteAlwaysUseSuper(utils))
285 );
286
287 // Assert that a request was sent n number of times
288 // Example usage: await expect(testUrl).to.have.sentCount(n);
289 utils.addMethod(Assertion.prototype, 'sentCount', async function (count) {
290 // @ts-ignore
291 const that = this;
292 const url = that._obj;
293 const requests = await networkLogger.getSentRequests(url);
294 that.assert(
295 count === requests.length,
296 `expected #{this} to have been sent ${
297 count == 1 ? 'once' : count + ' times'
298 }`
299 );
300 });
301 Assertion.overwriteMethod('sentCount', overwriteAlwaysUseSuper(utils));
302}
303
304module.exports = {
305 clearLastExpectError,

Callers

nothing calls this directly

Calls 3

overwriteAlwaysUseSuperFunction · 0.85
getSentRequestsMethod · 0.80
assertMethod · 0.80

Tested by

no test coverage detected