UNPKG

mock-xmlhttprequest

Version:
47 lines (42 loc) 1.65 kB
/** * mock-xmlhttprequest v8.4.1 * (c) 2025 Bertrand Guay-Paquet * @license MIT */ 'use strict'; const HeadersContainer = require('./HeadersContainer.cjs'); const Utils = require('./Utils.cjs'); /** * Request parameters from MockXhr.send() */ class RequestData { constructor(requestHeaders, method, url, body = null, credentialsMode = false) { this._requestHeaders = requestHeaders; this._method = method; this._url = url; this._body = body; this._credentialsMode = credentialsMode; } /** * @returns Request headers container */ get requestHeaders() { return new HeadersContainer(this._requestHeaders); } get method() { return this._method; } get url() { return this._url; } // Changing the return type to unknown is a breaking change with little to no benefit to users // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-explicit-any get body() { return this._body; } get withCredentials() { return this._credentialsMode; } /** * Note: this isn't completely accurate for a multipart/form-data encoded FormData request body. * MockXhr not consider headers, encoding, and other factors that influence the request body size * of non-mocked XMLHttpRequest. You can consider the value returned by this method as a floor * value for the request body size. This can still be useful to simulate upload progress events. * * @returns Request body's total byte size */ getRequestBodySize() { return Utils.getBodyByteSize(this.body); } } module.exports = RequestData;