Skip to content

Commit

Permalink
Merge pull request #19 from ShellyDCMS/add-types-for-spies-and-stubs
Browse files Browse the repository at this point in the history
add types for stubbing and spying
  • Loading branch information
ShellyDCMS committed Aug 27, 2023
2 parents ea3f82b + 8526ea3 commit 5613fe7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 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.30](../README.md) / [Modules](../modules.md) / CypressAngularComponentHelper
[@shellygo/cypress-test-utils - v1.0.32](../README.md) / [Modules](../modules.md) / CypressAngularComponentHelper

# Class: CypressAngularComponentHelper<T\>

Expand Down
10 changes: 5 additions & 5 deletions documents/classes/CypressHelper.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@shellygo/cypress-test-utils - v1.0.30](../README.md) / [Modules](../modules.md) / CypressHelper
[@shellygo/cypress-test-utils - v1.0.32](../README.md) / [Modules](../modules.md) / CypressHelper

# Class: CypressHelper

Expand Down Expand Up @@ -262,8 +262,8 @@ This is a classic place to have methods which will set the inputs which are goin
| Name | Type |
| :------ | :------ |
| `interceptAndMockResponse` | (`options`: { `alias?`: `string` ; `method?`: `string` ; `response`: `Object` ; `url`: `StringMatcher` }) => `void` |
| `spy` | (`name`: `string`) => `Omit`<`SinonSpy`<`any`[], `any`\>, ``"withArgs"``\> & `SinonSpyAgent`<`SinonSpy`<`any`[], `any`\>\> & `SinonSpy`<`any`[], `any`\> |
| `spyOnObject` | <T\>(`obj`: `T`, `method`: keyof `T`) => `Omit`<`SinonSpy`<`any`[], `any`\>, ``"withArgs"``\> & `SinonSpyAgent`<`SinonSpy`<`any`[], `any`\>\> & `SinonSpy`<`any`[], `any`\> |
| `spy` | (`name`: `string`) => `Agent`<`SinonSpy`<`any`[], `any`\>\> |
| `spyOnObject` | <T\>(`obj`: `T`, `method`: keyof `T`) => `Agent`<`SinonSpy`<`any`[], `any`\>\> |
| `stub` | () => `Agent`<`SinonStub`<`any`[], `any`\>\> |
**interceptAndMockResponse**: (`options`: { `alias?`: `string` ; `method?`: `string` ; `response`: `Object` ; `url`: `StringMatcher` }) => `void`
Expand Down Expand Up @@ -327,13 +327,13 @@ helper.given.interceptAndMockResponse({
-----
**spy**: (`name`: `string`) => `Omit`<`SinonSpy`<`any`[], `any`\>, ``"withArgs"``\> & `SinonSpyAgent`<`SinonSpy`<`any`[], `any`\>\> & `SinonSpy`<`any`[], `any`\>
**spy**: (`name`: `string`) => `Agent`<`SinonSpy`<`any`[], `any`\>\>
Returns a new spy function, and creates an alias for the newly created spy
-----
**spyOnObject**: <T\>(`obj`: `T`, `method`: keyof `T`) => `Omit`<`SinonSpy`<`any`[], `any`\>, ``"withArgs"``\> & `SinonSpyAgent`<`SinonSpy`<`any`[], `any`\>\> & `SinonSpy`<`any`[], `any`\>
**spyOnObject**: <T\>(`obj`: `T`, `method`: keyof `T`) => `Agent`<`SinonSpy`<`any`[], `any`\>\>
Spy on a method and create an alias for the spy
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.30](../README.md) / [Modules](../modules.md) / CypressLitComponentHelper
[@shellygo/cypress-test-utils - v1.0.32](../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.30](../README.md) / [Modules](../modules.md) / CypressReactComponentHelper
[@shellygo/cypress-test-utils - v1.0.32](../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.30](README.md) / Modules
[@shellygo/cypress-test-utils - v1.0.32](README.md) / Modules

# @shellygo/cypress-test-utils - v1.0.30
# @shellygo/cypress-test-utils - v1.0.32

## 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.31",
"version": "1.0.32",
"author": "Shelly Goldblit",
"private": false,
"license": "MIT",
Expand Down
19 changes: 14 additions & 5 deletions src/cypress-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,27 @@ export class CypressHelper {
},
/**
* Replace a function, record its usage and control its behavior.
* @returns {Cypress.Agent<sinon.SinonStub<any[], any>>}
*/
stub: () => cy.stub(),
stub: (): Cypress.Agent<sinon.SinonStub<any[], any>> => cy.stub(),
/**
* Returns a new spy function, and creates an alias for the newly created spy
* @param name - spy name
* @returns {Cypress.Agent<sinon.SinonSpy<any[], any>>}
*/
spy: (name: string) => cy.spy().as(`${name}Spy`),
spy: (name: string): Cypress.Agent<sinon.SinonSpy<any[], any>> =>
cy.spy().as(`${name}Spy`),
/**
* Spy on a method and create an alias for the spy
*
*/
spyOnObject: <T>(obj: T, method: keyof T) =>
* @param obj - object containing function to spy on
* @param method function to spy on
* @returns {Cypress.Agent<sinon.SinonSpy<any[], any>>}
*/
spyOnObject: <T>(
obj: T,
method: keyof T
): Cypress.Agent<sinon.SinonSpy<any[], any>> =>
cy.spy(obj, method).as(`${String(method)}Spy`)
};

Expand Down

0 comments on commit 5613fe7

Please sign in to comment.