Coder Social home page Coder Social logo

jasmine-dom's Introduction

jasmine-dom

sloth

UNPUBLISHED - Under development

Custom Jasmine matchers to test the state of the DOM


Build Status Code Coverage version downloads MIT License

All Contributors

PRs Welcome Code of Conduct Discord

Watch on GitHub Star on GitHub Tweet

The problem

You want to use Jasmine to write tests that assert various things about the state of the DOM. As part of that goal, you want to avoid all the repetitive patterns that arise in doing so. Checking for an element's attributes, its text content, its css classes, you name it.

This solution

The jasmine-dom library provides a set of custom Jasmine matchers that you can use to extend Jasmine. These will make your tests more declarative, clear to read and to maintain.

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies.

Using npm:

npm install --save-dev jasmine-dom

or for installation using yarn package manager:

yarn add --dev jasmine-dom

Usage

You should have a directory for helpers specified inside the helpers array in your jasmine.json file. Example:

{
	"spec_dir": "src/__tests__",
	"spec_files": ["**/*.test.js"],
	"helpers": ["helpers/**/*.js"],
	"stopSpecOnExpectationFailure": false,
	"random": false
}

Make a new file inside that directory, import jasmine-dom and add the matchers like so:

import JasmineDOM from 'jasmine-dom';

beforeAll(() => {
	jasmine.getEnv().addMatchers(JasmineDOM);
});

That's it! You're good to go.

Documentation

This library is meant to be a Jasmine version of @testing-library/jest-dom library. As such, it provides the same set of matchers and the same functionality for each one.

You can find examples for each matcher on jest-dom's docs.

Inspiration

This library was heavily inspired by testing-library being jest-dom a part of its ecosystem, and Kent C. Dodds' guiding principles.

The intention is to make these matchers available to developers using Jasmine instead of Jest.

Other Solutions

I'm not aware of any, if you are please do make a PR and add it here!

For extending Jasmine's matchers outside the realm of DOM testing, Jasmine-Matchers is an option.

Guiding Principles

The more your tests resemble the way your software is used, the more confidence they can give you

Contributors

Thanks goes to these people (emoji key)

This project follows the all-contributors specification. Contributions of any kind are welcome!

LICENSE

MIT

jasmine-dom's People

Contributors

brrianalexis avatar

Stargazers

Roman 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.