Expect
When you're writing tests, you often need to check that values meet certain conditions. expect
gives you access to a number of "matchers" that let you validate different things on the browser
, an element
or mock
object.
#
Default OptionsThese default options below are connected to the waitforTimeout and waitforInterval options set in the config.
Only set the options below if you want to wait for specific timeouts for your assertions.
Set options like this:
#
Matcher OptionsEvery matcher can take several options that allows you to modify the assertion:
#
Command OptionsName | Type | Details |
---|---|---|
wait | number | time in ms to wait for expectation to succeed. Default: 3000 |
interval | number | interval between attempts. Default: 100 |
message | string | user message to prepend before assertion error |
#
String OptionsThis options can be applied in addition to the command options when strings are being asserted.
Name | Type | Details |
---|---|---|
ignoreCase | boolean | apply toLowerCase to both actual and expected values |
trim | boolean | apply trim to actual value |
containing | boolean | expect actual value to contain expected value, otherwise strict equal. |
asString | boolean | might be helpful to force converting property value to string |
#
Number OptionsThis options can be applied in addition to the command options when numbers are being asserted.
Name | Type | Details |
---|---|---|
eq | number | equals |
lte | number | less then equals |
gte | number | greater than or equals |
#
Browser Matchers#
toHaveUrlChecks if browser is on a specific page.
#
Usage#
toHaveUrlContainingChecks if browser is on a page URL that contains a value.
#
Usage#
toHaveTitleChecks if website has a specific title.
#
Usage#
toHaveTitleContainingChecks if website has a specific title that contains a value.
#
Usage#
Element Matchers#
toBeDisplayedCalls isDisplayed
on given element.
#
Usage#
toBeVisibleSame as toBeDisplayed
.
#
Usage#
toExistCalls isExisting
on given element.
#
Usage#
toBePresentSame as toExist
.
#
Usage#
toBeExistingSame as toExist
.
#
Usage#
toBeFocusedChecks if element has focus. This assertion only works in a web context.
#
Usage#
toHaveAttributeChecks if an element has a certain attribute with a specific value.
#
Usage#
toHaveAttrSame as toHaveAttribute
.
#
Usage#
toHaveAttributeContainingChecks if an element has a certain attribute that contains a value.
#
Usage#
toHaveAttrContainingSame as toHaveAttributeContaining
.
#
Usage#
toHaveElementClassChecks if an element has a certain class name.
#
Usage#
toHaveElementClassContainingChecks if an element has a certain class name that contains provided value.
#
Usage#
toHaveElementPropertyChecks if an element has a certain property.
#
Usage#
toHaveValueChecks if an input element has a certain value.
#
Usage#
toHaveValueContainingChecks if an input element contains a certain value.
#
Usage#
toBeClickableChecks if an element can be clicked by calling isClickable
on the element.
#
Usage#
toBeDisabledChecks if an element is disabled by calling isEnabled
on the element.
#
Usage#
toBeEnabledChecks if an element is enabled by calling isEnabled
on the element.
#
Usage#
toBeSelectedChecks if an element is enabled by calling isSelected
on the element.
#
Usage#
toBeCheckedSame as toBeSelected
.
#
Usage#
toHaveHrefChecks if link element has a specific link target.
#
Usage#
toHaveLinkSame as toHaveHref
.
#
Usage#
toHaveHrefContainingChecks if link element contains a specific link target.
#
Usage#
toHaveLinkContainingSame as toHaveHrefContaining
.
#
Usage#
toHaveIdChecks if element has a specific id
attribute.
#
Usage#
toHaveTextChecks if element has a specific text. Can also be called with an array as parameter in the case where the element can have different texts.
#
Usage#
toHaveTextContainingChecks if element contains a specific text. Can also be called with an array as parameter in the case where the element can have different texts.
#
Usage#
toBeDisplayedInViewportChecks if an element is within the viewport by calling isDisplayedInViewport
on the element.
#
Usage#
toBeVisibleInViewportSame as toBeDisplayedInViewport
.
#
Usage#
toHaveChildrenChecks amount of the fetched element's children by calling element.$('./*')
command.
#
Usage#
toBeElementsArrayOfSizeChecks amount of fetched elements using $$
command.
#
Usage#
Network Matchers#
toBeRequestedChecks that mock was called
#
Usage#
toBeRequestedTimesChecks that mock was called for the expected amount of times
#
Usage#
toBeRequestedWithChecks that mock was called according to the expected options.
Most of the options supports expect/jasmine partial matchers like expect.objectContaining
#
Usage#
Default MatchersIn addition to the expect-webdriverio
matchers you can use builtin Jest's expect assertions or expect/expectAsync for Jasmine.