Skip to content

Commit

Permalink
Merge pull request #15 from ShellyDCMS/add-wait-for-multiple-responses
Browse files Browse the repository at this point in the history
add waiting for multiple responses
  • Loading branch information
ShellyDCMS committed Aug 9, 2023
2 parents ce4b5bb + d6c9a2c commit 517ba2b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion documents/classes/CypressAngularComponentHelper.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@shellygo/cypress-test-utils - v1.0.25](../README.md) / [Modules](../modules.md) / CypressAngularComponentHelper
[@shellygo/cypress-test-utils - v1.0.27](../README.md) / [Modules](../modules.md) / CypressAngularComponentHelper

# Class: CypressAngularComponentHelper<T\>

Expand Down
9 changes: 8 additions & 1 deletion documents/classes/CypressHelper.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@shellygo/cypress-test-utils - v1.0.25](../README.md) / [Modules](../modules.md) / CypressHelper
[@shellygo/cypress-test-utils - v1.0.27](../README.md) / [Modules](../modules.md) / CypressHelper

# Class: CypressHelper

Expand Down Expand Up @@ -382,6 +382,7 @@ The when property will hold methods of “events” which will take place like r
| `wait` | (`ms`: `number`) => `Chainable`<`undefined`\> |
| `waitForLastCall` | (`alias`: `string`, `timeout`: `number`) => `Chainable`<`undefined` \| `Interception`\> |
| `waitForResponse` | (`alias`: `string`) => `Chainable`<`Interception`\> |
| `waitForResponses` | (`alias`: `string`, `responses`: `number`) => `Chainable`<`Interception`[]\> |
| `waitUntil` | <ReturnType\>(`checkFunction`: () => `Chainable`<`any`\> \| `ReturnType` \| `PromiseLike`<`ReturnType`\>, `options?`: `WaitUntilOptions`<`any`\>) => `Chainable`<`undefined`\> |
| `within` | (`fn`: () => `void`, `selector`: `string`, `index`: `number`) => `Chainable`<`JQuery`<`HTMLElement`\>\> |
Expand Down Expand Up @@ -576,6 +577,12 @@ Wait for a specific request to complete.
-----
**waitForResponses**: (`alias`: `string`, `responses`: `number`) => `Chainable`<`Interception`[]\>
Wait for multiples requests to complete.
-----
**waitUntil**: <ReturnType\>(`checkFunction`: () => `Chainable`<`any`\> \| `ReturnType` \| `PromiseLike`<`ReturnType`\>, `options?`: `WaitUntilOptions`<`any`\>) => `Chainable`<`undefined`\>
**`Example`**
Expand Down
2 changes: 1 addition & 1 deletion documents/classes/CypressLitComponentHelper.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@shellygo/cypress-test-utils - v1.0.25](../README.md) / [Modules](../modules.md) / CypressLitComponentHelper
[@shellygo/cypress-test-utils - v1.0.27](../README.md) / [Modules](../modules.md) / CypressLitComponentHelper

# Class: CypressLitComponentHelper

Expand Down
2 changes: 1 addition & 1 deletion documents/classes/CypressReactComponentHelper.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@shellygo/cypress-test-utils - v1.0.25](../README.md) / [Modules](../modules.md) / CypressReactComponentHelper
[@shellygo/cypress-test-utils - v1.0.27](../README.md) / [Modules](../modules.md) / CypressReactComponentHelper

# Class: CypressReactComponentHelper

Expand Down
4 changes: 2 additions & 2 deletions documents/modules.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[@shellygo/cypress-test-utils - v1.0.25](README.md) / Modules
[@shellygo/cypress-test-utils - v1.0.27](README.md) / Modules

# @shellygo/cypress-test-utils - v1.0.25
# @shellygo/cypress-test-utils - v1.0.27

## Table of contents

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shellygo/cypress-test-utils",
"description": "Test Automation Utilities",
"version": "1.0.26",
"version": "1.0.27",
"author": "Shelly Goldblit",
"private": false,
"license": "MIT",
Expand Down
33 changes: 32 additions & 1 deletion src/cypress-helper-spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,45 @@ describe("cypress helper tests", () => {

it("should intercept request and mock response", async () => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever",
url: "**/shellygo/whatever**",
response: { shelly: "go" }
});
expect(await (await fetch("https:/shellygo/whatever")).json()).to.include({
shelly: "go"
});
});

it("should wait for multiple responses", async () => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever**",
response: { shelly: "go" },
alias: "shellygo"
});
fetch("https:/shellygo/whatever");
fetch("https:/shellygo/whatever");
fetch("https:/shellygo/whatever?shelly=go");
when.waitForResponses("shellygo", 2);
expect(await get.requestQueryParam("shellygo", "shelly")).to.eq("go");
});

describe("when waiting for last call", () => {
beforeEach(() => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever**",
response: { shelly: "go" },
alias: "shellygo"
});
fetch("https:/shellygo/whatever");
fetch("https:/shellygo/whatever");
when.waitForLastCall("shellygo");
});

it("should wait for last call", async () => {
fetch("https:/shellygo/whatever?shelly=go");
expect(await get.requestQueryParam("shellygo", "shelly")).to.eq("go");
});
});

it("should intercept request and test query params", async () => {
fetch("https:/shellygo/whatever?shelly=go");
given.interceptAndMockResponse({
Expand Down
7 changes: 7 additions & 0 deletions src/cypress-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ export class CypressHelper {
wait: (ms: number) => cy.wait(ms),
/**
* Wait for a specific request to complete.
* @param alias
*/
waitForResponse: (alias: string) => cy.wait(`@${alias}`),
/**
* Wait for multiples requests to complete.
* @param alias
*/
waitForResponses: (alias: string, responses: number) =>
cy.wait(Array(responses).fill(`@${alias}`)),
/**
* Wait for a last request to complete.
*/
Expand Down

0 comments on commit 517ba2b

Please sign in to comment.