diff --git a/README.md b/README.md
index 73fa3ee..6a42c42 100644
--- a/README.md
+++ b/README.md
@@ -127,14 +127,15 @@ A function that must return a truthy value when the wait is over.
Pass in an options object to change the default behavior of `cy.waitUntil()`.
-| Option | Default | Description |
-| ------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `errorMsg` | `Timed out retrying` | The error message to write. |
-| `timeout` | `5000` | Time to wait for the `checkFunction` to return a truthy value before throwing an error. |
-| `interval` | `200` | Time to wait between the `checkFunction` invocations. |
-| `description` | `waitUntil` | The name logged into the Cypress Test Runner. |
-| `logger` | `Cypress.log` | A custom logger in place of the default [Cypress.log](https://docs.cypress.io/api/cypress-api/cypress-log.html). It's useful just for debugging purposes. |
-| `log` | `true` | Enable/disable logging. |
+| Option | Default | Description |
+| --------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `errorMsg` | `Timed out retrying` | The error message to write. |
+| `timeout` | `5000` | Time to wait for the `checkFunction` to return a truthy value before throwing an error. |
+| `interval` | `200` | Time to wait between the `checkFunction` invocations. |
+| `description` | `waitUntil` | The name logged into the Cypress Test Runner. |
+| `logger` | `Cypress.log` | A custom logger in place of the default [Cypress.log](https://docs.cypress.io/api/cypress-api/cypress-log.html). It's useful just for debugging purposes. |
+| `log` | `true` | Enable/disable logging. |
+| `customMessage` | `undefined` | String logged after the `options.description`. |
diff --git a/cypress/integration/plugin.spec.js b/cypress/integration/plugin.spec.js
index 80cba6a..e38ecdf 100644
--- a/cypress/integration/plugin.spec.js
+++ b/cypress/integration/plugin.spec.js
@@ -234,6 +234,23 @@ context("Cypress Wait Until", () => {
});
});
+ it("Should accept a custom message", () => {
+ const checkFunction = () => true;
+ const customMessage = "custom message";
+
+ const logger = {
+ log: (...params) => Cypress.log(...params)
+ };
+ const spy = cy.spy(logger, "log");
+ const options = { logger: logger.log, customMessage };
+
+ cy.waitUntil(checkFunction, options).then(() => {
+ expect(spy).to.have.been.called;
+ const lastCallArgs = spy.lastCall.args[0];
+ expect(lastCallArgs.message).deep.include(customMessage);
+ });
+ });
+
it("Should allow to turn off logging", () => {
const checkFunction = () => true;
diff --git a/cypress/types/plugin.spec.js b/cypress/types/plugin.spec.js
index 441a944..9a3685b 100644
--- a/cypress/types/plugin.spec.js
+++ b/cypress/types/plugin.spec.js
@@ -95,3 +95,11 @@ cy.waitUntil(
log: false
}
);
+cy.waitUntil(
+ function() {
+ return true;
+ },
+ {
+ customMessage: "custom message"
+ }
+);
diff --git a/cypress/types/plugin.spec.ts b/cypress/types/plugin.spec.ts
index d5d8a6a..4b27808 100644
--- a/cypress/types/plugin.spec.ts
+++ b/cypress/types/plugin.spec.ts
@@ -29,3 +29,4 @@ cy.waitUntil(() => true, {
});
cy.waitUntil(() => true, { log: false });
+cy.waitUntil(() => true, { customMessage: "custom message" });
diff --git a/index.d.ts b/index.d.ts
index d816c5f..baefabd 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -7,6 +7,7 @@ interface WaitUntilOptions {
interval?: number;
errorMsg?: string;
description?: string;
+ customMessage?: string;
logger?: (WaitUntilLog) => any;
log?: boolean;
}
diff --git a/src/index.js b/src/index.js
index c4d1878..5a20b87 100644
--- a/src/index.js
+++ b/src/index.js
@@ -13,6 +13,7 @@ function waitUntil(subject, checkFunction, options) {
const ERROR_MSG = options.errorMsg || "Timed out retrying";
const LOG_DESCRIPTION = options.description || "waitUntil";
const LOG = options.log === false ? false : true;
+ const MESSAGE = [options.customMessage, options].filter(Boolean);
let retries = Math.floor(TIMEOUT / TIMEOUT_INTERVAL);
const logger = options.logger || Cypress.log;
@@ -20,7 +21,7 @@ function waitUntil(subject, checkFunction, options) {
if (LOG) {
logger({
name: LOG_DESCRIPTION,
- message: options,
+ message: MESSAGE,
consoleProps: () => ({
options
})