@shellygo/cypress-test-utils - v4.1.3 / Modules
@shellygo/cypress-test-utils - v4.1.3
Table of contents
Classes
- Assertable
- CypressAngularComponentHelper
- CypressHelper
- CypressHelperOptions
- CypressLitComponentHelper
- CypressReactComponentHelper
Type Aliases
Functions
Type Aliases
A11yOptions
Ƭ A11yOptions: { skipFailures?
: boolean
; violationCallback?
: (violations
: axe.Result
[]) => void
} & AxeOptions
SnapshotOptions
Ƭ SnapshotOptions: { dataTestID?
: string
; index?
: number
} & CypressImageSnapshotOptions
StubbedInstance
Ƭ StubbedInstance<T
>: GenericStubbedInstance
<T
, SinonStub
>
Type parameters
Name |
---|
T |
Functions
match
▸ match(value
): SinonMatcher
Sinon matcher for stubs/spy comparison
Parameters
Name | Type |
---|---|
value |
number |
Returns
SinonMatcher
Example
// partial match of spy function params called with
let { given, when, get } = new CypressHelper();
it("should partially match spy params", () => {
const obj = {
func: (param: Object) => {}
};
given.spyOnObject(obj, "func");
obj.func({ shelly: "go", inner: { attr: "value" } });
then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
match({ inner: { attr: "value" } })
);
});
▸ match(value
): SinonMatcher
Sinon matcher for stubs/spy comparison
Parameters
Name | Type |
---|---|
value |
string |
Returns
SinonMatcher
Example
// partial match of spy function params called with
let { given, when, get } = new CypressHelper();
it("should partially match spy params", () => {
const obj = {
func: (param: Object) => {}
};
given.spyOnObject(obj, "func");
obj.func({ shelly: "go", inner: { attr: "value" } });
then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
match({ inner: { attr: "value" } })
);
});
▸ match(expr
): SinonMatcher
Sinon matcher for stubs/spy comparison
Parameters
Name | Type |
---|---|
expr |
RegExp |
Returns
SinonMatcher
Example
// partial match of spy function params called with
let { given, when, get } = new CypressHelper();
it("should partially match spy params", () => {
const obj = {
func: (param: Object) => {}
};
given.spyOnObject(obj, "func");
obj.func({ shelly: "go", inner: { attr: "value" } });
then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
match({ inner: { attr: "value" } })
);
});
▸ match(callback
, message?
): SinonMatcher
Sinon matcher for stubs/spy comparison
Parameters
Name | Type |
---|---|
callback |
(value : any ) => boolean |
message? |
string |
Returns
SinonMatcher
Example
// partial match of spy function params called with
let { given, when, get } = new CypressHelper();
it("should partially match spy params", () => {
const obj = {
func: (param: Object) => {}
};
given.spyOnObject(obj, "func");
obj.func({ shelly: "go", inner: { attr: "value" } });
then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
match({ inner: { attr: "value" } })
);
});
▸ match(obj
): SinonMatcher
Sinon matcher for stubs/spy comparison
Parameters
Name | Type |
---|---|
obj |
object |
Returns
SinonMatcher
Example
// partial match of spy function params called with
let { given, when, get } = new CypressHelper();
it("should partially match spy params", () => {
const obj = {
func: (param: Object) => {}
};
given.spyOnObject(obj, "func");
obj.func({ shelly: "go", inner: { attr: "value" } });
then(get.spyFromFunction(obj.func)).shouldHaveBeenCalledWithMatch(
match({ inner: { attr: "value" } })
);
});
then
▸ then(subject
): Assertable
<unknown
>
Wraps Cypress.Chainable and returns Assertable, decoupling test code form cypress 'should' assertions. This way you can add assertions of your own, by extending Assertable class.
Parameters
Name | Type |
---|---|
subject |
any |
Returns
Assertable
<unknown
>
Example
Example
import { Assertable, then } from "@shellygo/cypress-test-utils/assertable";
class MyAssertable<T> extends Assertable<T> {
private styleFromWindow = (win: Window) => {
const styleItem = win.localStorage.getItem(`style`);
const obj = JSON.parse(styleItem || "");
return obj;
};
public shouldEqualToStoredStyle = () =>
then(
new CypressHelper().get.window().then((win) => {
const style = styleFromWindow(win);
then(this.chainable).shouldDeepNestedInclude(style);
})
);
}
class Driver {
public given = {
// methods for setting test pre-conditions
};
public when = {
// methods for test "actions", such as click, darg & drop, etc.
};
public get = {
// getter, for exploring the outcome, such as getting a text color a span
};
public then = (chainable: Cypress.Chainable<any>) => new MyAssertable(chainable);
}