expect-element is an extension for expect that lets you write better assertions for DOM nodes.
Installation
Using npm:
$ npm install --save expect expect-element
Then, use as you would anything else:
// using an ES6 transpiler, like babelexpect // not using an ES6 transpilervar expect = var expectElement = expect
The UMD build is also available on npmcdn:
You can find the library on window.expectElement
.
Assertions
toHaveAttribute
expect(element).toHaveAttribute(name, [value, [message]])
Asserts the given DOM element
has an attribute with the given name
. If value
is given, asserts the value of the attribute as well.
toNotHaveAttribute
expect(object).toNotHaveAttribute(name, [value, [message]])
Asserts the given DOM element
does not have an attribute with the given name
. If value
is given, asserts the value of the attribute as well.
toHaveAttributes
expect(element).toHaveAttribute(attributes, [message])
Asserts the given DOM element
has attributes with the names and values in attributes
.
toNotHaveAttributes
expect(element).toNotHaveAttribute(attributes, [message])
Asserts the given DOM element
does not have attributes with the names and values in attributes
.
toHaveText
expect(element).toHaveText(text, [message])
Asserts the textContent
of the given DOM element
is text
.
toNotHaveText
expect(element).toNotHaveText(text, [message])
Asserts the textContent
of the given DOM element
is not text
.