Skip to content

Commit

Permalink
Merge pull request #21 from ShellyDCMS/add-get-slot-text
Browse files Browse the repository at this point in the history
Get text from slot
  • Loading branch information
ShellyDCMS committed Sep 30, 2023
2 parents accd48f + 6c07c67 commit 4e84496
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 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.33](../README.md) / [Modules](../modules.md) / CypressAngularComponentHelper
[@shellygo/cypress-test-utils - v1.0.34](../README.md) / [Modules](../modules.md) / CypressAngularComponentHelper

# Class: CypressAngularComponentHelper<T\>

Expand Down
15 changes: 14 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.33](../README.md) / [Modules](../modules.md) / CypressHelper
[@shellygo/cypress-test-utils - v1.0.34](../README.md) / [Modules](../modules.md) / CypressHelper

# Class: CypressHelper

Expand Down Expand Up @@ -69,6 +69,7 @@ The get property will hold methods which will give our tests access to the “ou
| `requestHeader` | (`alias`: `string`) => `Chainable`<{ `[key: string]`: `string` \| `string`[]; }\> |
| `requestQueryParams` | (`alias`: `string`) => `Chainable`<{ `[k: string]`: `string`; }\> |
| `requestUrl` | (`alias`: `string`) => `Chainable`<`string`\> |
| `slotText` | (`selector`: `string`, `index?`: `number`) => `Chainable`<``null`` \| `JQuery`<`HTMLSlotElement`\>\> \| `Chainable`<`string` \| `JQuery`<`HTMLSlotElement`\>\> |
| `spy` | (`name`: `string`) => `Chainable`<`JQuery`<`HTMLElement`\>\> |
| `spyFromFunction` | (`func`: `Function`) => `Chainable`<`JQuery`<`HTMLElement`\>\> |
| `stub` | (`name`: `string`) => `Chainable`<`JQuery`<`HTMLElement`\>\> |
Expand Down Expand Up @@ -237,6 +238,18 @@ Get intercepted request's url
-----
**slotText**: (`selector`: `string`, `index?`: `number`) => `Chainable`<``null`` \| `JQuery`<`HTMLSlotElement`\>\> \| `Chainable`<`string` \| `JQuery`<`HTMLSlotElement`\>\>
To be used with shadow DOM only
**`Example`**
```ts
expect(helper.get.slotText("main-cta-button", 2).should("include", "CTA"))
```
-----
**spy**: (`name`: `string`) => `Chainable`<`JQuery`<`HTMLElement`\>\>
Get spy by alias
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.33](../README.md) / [Modules](../modules.md) / CypressLitComponentHelper
[@shellygo/cypress-test-utils - v1.0.34](../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.33](../README.md) / [Modules](../modules.md) / CypressReactComponentHelper
[@shellygo/cypress-test-utils - v1.0.34](../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.33](README.md) / Modules
[@shellygo/cypress-test-utils - v1.0.34](README.md) / Modules

# @shellygo/cypress-test-utils - v1.0.33
# @shellygo/cypress-test-utils - v1.0.34

## 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.33",
"version": "1.0.34",
"author": "Shelly Goldblit",
"private": false,
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions src/cypress-helper-spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ describe("cypress helper tests", () => {
get.elementsText("header").should("eq", "My First Heading");
});

it.skip("should get slot's text", () => {
get.slotText("with-slot").should("eq", "Text in Slot");
});

it("should get env variable", () => {
expect(get.env("env1")).to.eq("value1");
});
Expand Down
15 changes: 15 additions & 0 deletions src/cypress-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,21 @@ export class CypressHelper {
index: number = 0
): Cypress.Chainable<string> =>
this.get.nthBySelector(selector, index).invoke("text"),
/**
* To be used with shadow DOM only
* @example
* ```ts
* expect(helper.get.slotText("main-cta-button", 2).should("include", "CTA"))
* ```
* @param selector
* @param [index = 0]
* @returns {Cypress.Chainable<string>}
*/
slotText: (selector: string, index: number = 0) =>
this.get
.nthBySelector(selector, index)
.find("slot")
.then(slot => slot.get(0).assignedNodes()[0].textContent),
/**
* Get value of input element
* @example
Expand Down

0 comments on commit 4e84496

Please sign in to comment.