GithubHelp home page GithubHelp logo

gerhobbelt / jasmine-matchers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from uxebu/jasmine-matchers

0.0 1.0 0.0 238 KB

A set of jasmine matchers that allow for more explicit test writing and better error reporting.

License: Other

JavaScript 100.00%

jasmine-matchers's Introduction

Under MIT License

Overview

This project contains a set of matchers for the jasmine test library that are very handy for more explicit test writing and especially more explicit error reportings. It contains matchers such as

  • toBeArray
  • toBeInstanceOf
  • toThrowInstanceOf
  • toHaveBeenCalledXTimes and more.

Usage

Either you use in your browser jasmine test runner by adding it after the script-tag jasmine.js:

// Since v0.2.0 you have to include every matcher on demand
<script src="jasmine-matchers/src/toBe.js"></script>
<script src="jasmine-matchers/src/toHave.js"></script>
<script src="jasmine-matchers/src/toContain.js"></script>
<script src="jasmine-matchers/src/toThrow.js"></script>
<script src="jasmine-matchers/src/toStartEndWith.js"></script>

Or when using jasmine-node you can simply install the matchers via:

npm install jasmine-matchers

And make them available in your spec-file:

require('jasmine-matchers');
describe(...);

// or via requirejs (assuming your specs are within PROJECT_ROOT/test):
require([
  '../node_modules/jasmine-matchers/src/toBe.js',
  '../node_modules/jasmine-matchers/src/toHave.js',
  '../node_modules/jasmine-matchers/src/toContain.js',
  '../node_modules/jasmine-matchers/src/toThrow.js',
  '../node_modules/jasmine-matchers/src/toStartEndWith.js',
], function() {
  describe(...);
});

Features

The Jasmine testing framework from Pivotal Labs comes with this default set of matchers:

expect(function(){fn();}).toThrow(e);
expect(x).toBe(y);
expect(x).toBeDefined();
expect(x).toBeFalsy();
expect(x).toBeGreaterThan(y);
expect(x).toBeLessThan(y);
expect(x).toBeNull();
expect(x).toBeTruthy();
expect(x).toBeUndefined();
expect(x).toContain(y);
expect(x).toEqual(y);
expect(x).toMatch(pattern);

jasmine-matchers adds:

expect(x).toBeArray();
expect(x).toBeInstanceOf(Constructor);
expect(x).toBeNan();
expect(x).toBeOfType(type);
expect(x).toHaveLength(length);
expect(x).toHaveLengthGreaterThan(length);
expect(x).toHaveLengthSmallerThan(length);
expect(x).toHaveProperties(...properties);
expect(x).toHaveMethods(...methods);
expect(x).toHaveOwnMethods(...methods);
expect(x).toHaveOwnProperties(...properties);
expect(x).toEachHave(attr, val);
expect(x).toBeCloneOf(source);
expect(x).toNotBeCloneOf(source);
expect(x).toHavePropertieValue(attr, val);
expect(x).toIncludeObject(object);
expect(x).toMatchObject(object);
expect(x).toNotMatchObject(object); //not.toMatchObject(object);
expect(x).toNotMatch(object);
expect(x).toMatchLengthOf(object);
expect(x).toThrowInstanceOf(ExceptionType);
expect(x).toHaveBeenCalledXTimes(count);
expect(x).toContainOnce(value);
expect(x).toEndWith(value);
expect(x).toEachEndWith(value);
expect(x).toSomeEndWith(value);

History

This used to be our (uxebu's) collection of matchers that moved from project to project, got extended here and there, let's share it.

Build

Use make build to create one file, that lands in dist/matchers.js that you can include, if you don't like to handle multiple files.

TODO

  • integrate with travis

jasmine-matchers's People

Contributors

gerhobbelt avatar goliatone avatar jwark avatar sideshowcoder avatar

Watchers

 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.