Protected
Readonly
chainableAsserts that the target is a number or a date greater than the given number or date n respectively. However, it's often best to assert that the target is equal to its expected value.
then(get.numberOfElements("radio")).shouldBeGreaterThan(5);
Asserts that the target is a number or a date greater than or equal to the given number or date n respectively. However, it's often best to assert that the target is equal to its expected value.
then(get.numberOfElements("radio")).shouldBeGreaterThanOrEqual(5);
Asserts that the target is a number or a n date less than or equal to the given number or date n respectively. However, it's often best to assert that the target is equal to its expected value.
then(get.numberOfElements("radio")).shouldBeLessThen(5);
Asserts that the target is a number or a date less than or equal to the given number or date n respectively. However, it's often best to assert that the target is equal to its expected value.
then(get.numberOfElements('list-item')).shouldBeLessThanOrEqual(5)
Causes all .equal
, .include
, .members
, .keys
, and .property
assertions that follow in the chain to use deep equality instead of strict (===
) equality. See the deep-eql
project page for info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
then(
get.fixture("user")).shouldDeepEqual({
name: "Jane Doe",
id: "1234"
})
Asserts that the target has a property with the given key name
.
then(
get.fixture("user")).shouldDeepNestedInclude({
name: "Jane Doe",
id: "1234",
nested: {
attr1: "something",
attr2: "the other thing"
}
})
Assert that the selection is not empty. Note that this overrides the built-in chai assertion. If the object asserted against is not a jQuery object, the original implementation will be called.
then(get.elementByTestId("selector")).shouldExist()
Assert that the first element of the selection has the given attribute, using .attr()
.
Optionally, assert a particular value as well. The return value is available for chaining.
then(get.elementByTestId("selector")).shouldHaveAttribute("test")
Assert spy was called with matching arguments (and possibly others).
Rest
...args: any[]then(get.spy("onSomething")).shouldHaveBeenCalledWithMatch(match({ id: 1 }))
it('should call the get method of the HTTP client with a URL with query param filter = status', () => {
healthService.fetchHealthResults(status);
then(get.mock.httpClientService().get).shouldHaveBeenCalledWith(
match(baseURL),
match.hasNested(
'params.updates[0]',
match({ param: 'filter', value: `status eq ${status}` })
)
);
});
Assert that the selection is empty. Note that this overrides the built-in chai assertion. If the object asserted against is not a jQuery object, the original implementation will be called.
then(get.elementByTestId("selector")).shouldNotExist()
When no arguments are provided, shouldThrow invokes the target function and asserts that no error is thrown. When one argument is provided, and it's a string, shouldThrow invokes the target function and asserts that no error is thrown with a message that contains that string.
Optional
value: string | RegExpfunction badFn() { console.log('Illegal salmon!') }
then(() => badFn()).shouldNotThrow()
then(() => badFn()).shouldNotThrow('salmon')
then(() => badFn()).shouldNotThrow(/salmon/)
When no arguments are provided, shouldThrow invokes the target function and asserts that an error is thrown. When one argument is provided, and it's a string, shouldThrow invokes the target function and asserts that an error is thrown with a message that contains that string.
Optional
value: string | RegExpfunction badFn() { throw new TypeError('Illegal salmon!') }
then(() => badFn()).shouldThrow()
then(() => badFn()).shouldThrow('salmon')
then(() => badFn()).shouldThrow(/salmon/)
Generated using TypeDoc
Assertable wraps Cypress.Chainable so that your tests are as decoupled as possible from Cypress. By using the Assertable class, you can use the same assertions in your tests, regardless of the testing framework you use. All you need to do if you wish to replace Cypress with another testing framework and keep your tests, is to replace the implementation of the Assertable class. You can also add assertions of your own, by extending Assertable class.
Example