Code Monkey home page Code Monkey logo

expect-element's Introduction

expect-element Travis npm package

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 ES6 modules
import expect from 'expect'
import expectElement from 'expect-element'
expect.extend(expectElement)

// using CommonJS modules
var expect = require('expect')
var expectElement = require('expect-element')
expect.extend(expectElement)

The UMD build is also available on unpkg:

<script src="https://unpkg.com/expect-element/umd/expect-element.min.js"></script>

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.

expect(element).toHaveAttribute('id')
expect(element).toHaveAttribute('id', 'an-id')

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.

expect(element).toNotHaveAttribute('id')
expect(element).toNotHaveAttribute('id', 'an-id')

toHaveAttributes

expect(element).toHaveAttribute(attributes, [message])

Asserts the given DOM element has attributes with the names and values in attributes.

expect(element).toHaveAttributes({
  id: 'an-id',
  'class': 'a-class'
})

toNotHaveAttributes

expect(element).toNotHaveAttribute(attributes, [message])

Asserts the given DOM element does not have attributes with the names and values in attributes.

expect(element).toNotHaveAttributes({
  id: 'an-id',
  'class': 'a-class'
})

toHaveText

expect(element).toHaveText(text, [message])

Asserts the textContent of the given DOM element is text.

expect(element).toHaveText('hello world')

toNotHaveText

expect(element).toNotHaveText(text, [message])

Asserts the textContent of the given DOM element is not text.

expect(element).toNotHaveText('hello world')

expect-element's People

Contributors

greenkeeperio-bot avatar mjackson avatar npmcdn-to-unpkg-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.