Skip to main content

mockClearAll

Overview

Use the mockClearAll command to reset all stored information in registered mocks. Mocks are registered using the mock command.

Usage

await browser.mockClearAll();

Usage Examples

it("should clear all mocks", async ({ browser }) => {
const docMock = await browser.mock("**", {
headers: { "Content-Type": "text/html" },
});
const jsMock = await browser.mock("**", {
headers: { "Content-Type": "application/javascript" },
});

await browser.url("http://guinea-pig.webdriver.io/");
console.log(docMock.calls.length, jsMock.calls.length); // returns "1 4"

await browser.url("http://guinea-pig.webdriver.io/");
console.log(docMock.calls.length, jsMock.calls.length); // returns "2 4" (JavaScript comes from cache)

await browser.mockClearAll();
console.log(docMock.calls.length, jsMock.calls.length); // returns "0 0"
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.