_____ __
,____ (\=-, _/ ____\___________ ___.__._/ |_
\ "=.`'-.______/ /^ \ __\/ __ \_ __ < | |\ __\
`-._.-"(=====' / | | \ ___/| | \/\___ | | |
\<'--\( |__| \___ >__| / ____| |__|
^^ ^^ \/ \/
Feryts out DOM elements from css selectors and asserts facts about them.
This is particularly useful for testing components, templated email output, or smoke-testing entire websites.
Feryt works with browser DOM or in node with jsdom.
Examples
In browser simply pass the document object to feryt and start asseting facts:
// 1) page has a div element with a foo class// 2) which within which are 4 ul elements ;
Here is a simple test using jsdom and mocha:
var jsdom = ;var feryt = ; var html = ` <div> <div class='list'> <div class='item'>abc</div> <div class='item'>abc</div> <div class='item'>abc</div> <div class='item'>abc</div> </div> <img src='http://google.com/logo.png'/> </div>`; ;
API:
feryt(document) -> Feryt object
The feryt
constructor takes a DOM compatable document object and returns a
Feryt object.
Feryt object
The Feryt
object wraps a DOM document and provides the following methods:
Feryt.findOne(selector) -> FerytNode object
Given a valid CSS selector, will return the first match wrapped in a FerytNode, if no element can be found, throws an exception. In the simplest case this can be used to verify an element exists in the DOM.
;
Feryt.find(selector) -> FerytNodeList object
Given a valid CSS selector, will return all matches wrapped in a FerytNodeList, if no elements can be found, throws an exception.
; //finds all text inputs
FerytNode object
Several methods return a FerytNode object, which represents a single DOM element with the following chainable methods.
FerytNode.attr({ attr : value, ...}) -> self
Iterates through the provided attributes (keys) and asserts their values are equal.
;
FerytNode.classes(['foo', ...], ['bar', ...]) -> self
Asserts that classes are either present or absent. The first argument is an Array of classes to check exist, the second to check do not exist. Either are optional.
classes'logo';
FerytNode.content(string) -> self
Assert that the content (innerHTML) of an element matches string.
content'Green eggs and ham';
FerytNode.findOne(selector) -> FerytNode object
Simmilar to Feryt.findOne, however attempts to construct a unique selector for the current element and joins that with the passed in selector with ' > '. Useful for chaining further tests, especially combiled within a FerytNodeList.each function.
;
FerytNode.find(selector) -> FerytNodeList object
Simmilar to Feryt.find, however attempts to construct a unique selector for the current element and joins that with the passed in selector. Useful for chaining further tests, especially combiled within a FerytNodeList.each function.
FerytNode.raw() -> DOMElement
Returns the raw DOMElement wrapped by this FerytNode.
FerytNodeList object
Several methods return a FerytNodeList object, which represents an array of DOM elements with the following chainable methods.
FerytNode.count(n) -> self
Assert that the number of elements matched is n
.
;
FerytNode.each(function(FerytNode) { ... }) -> self
This takes a function which will be invoked once for each element in the list, this allows you to do branching and complext testing in a chainable way over many elements.
;
FerytNode.raw() -> DOMElement
Returns the javascript Array of DOMElement wrapped by this FerytNode.
Feryt is MIT software, the cool ascii ferret was created by JGS