Skip to content

Commit

Permalink
implement requested changes from PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
peburrows committed Apr 30, 2020
1 parent 1a62da2 commit 3fbca94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
13 changes: 12 additions & 1 deletion cypress/types/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ cy.waitUntil(() => Promise.resolve(false), { timeout: 500 });
cy.waitUntil(() => true, { errorMsg: "Custom error message" });
cy.waitUntil(() => false, { errorMsg: "Custom error message" });
cy.waitUntil(() => Promise.resolve(true), { errorMsg: "Custom error message" });
cy.waitUntil(() => Promise.resolve(false), { errorMsg: "Custom error message" });
cy.waitUntil(() => Promise.resolve(false), {
errorMsg: "Custom error message",
});

cy.waitUntil(() => true, { errorMsg: () => "Custom error message" });
cy.waitUntil(() => false, { errorMsg: () => "Custom error message" });
cy.waitUntil(() => Promise.resolve(true), {
errorMsg: () => "Custom error message",
});
cy.waitUntil(() => Promise.resolve(false), {
errorMsg: () => "Custom error message",
});

cy.waitUntil(() => true, { description: "Custom description" });

Expand Down
9 changes: 7 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/// <reference types="Cypress" />

type WaitUntilLog = Pick<Cypress.LogConfig, "name" | "message" | "consoleProps">;
type WaitUntilLog = Pick<
Cypress.LogConfig,
"name" | "message" | "consoleProps"
>;

type ErrorMsgCallback = (result: any, options: any) => string;

interface WaitUntilOptions {
timeout?: number;
interval?: number;
errorMsg?: string;
errorMsg?: string | ErrorMsgCallback;
description?: string;
customMessage?: string;
verbose?: boolean;
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const waitUntil = (subject, checkFunction, originalOptions = {}) => {
return result;
}
if (retries < 1) {
const msg = options.errorMsg.call ? options.errorMsg() : options.errorMsg;
const msg =
options.errorMsg instanceof Function
? options.errorMsg({ result, options: originalOptions })
: options.errorMsg;
throw new Error(msg);
}
cy.wait(options.interval, { log: false }).then(() => {
Expand Down

0 comments on commit 3fbca94

Please sign in to comment.