All Projects → JamieMason → Jasmine Matchers

JamieMason / Jasmine Matchers

Licence: mit
Write Beautiful Specs with Custom Matchers for Jest and Jasmine

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jasmine Matchers

Public
Repository for wallaby.js questions and issues
Stars: ✭ 662 (+19.93%)
Mutual labels:  jest, tdd, bdd, jasmine
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-77.54%)
Mutual labels:  jest, tdd, bdd, jasmine
angular-unit-testing-examples
Showroom for different Angular unit testing concepts
Stars: ✭ 19 (-96.56%)
Mutual labels:  unit-testing, jasmine, jest, karma
Enzyme Matchers
Jasmine/Jest assertions for enzyme
Stars: ✭ 881 (+59.6%)
Mutual labels:  jest, unit-testing, tdd, jasmine
Karma
Spectacular Test Runner for JavaScript
Stars: ✭ 11,591 (+1999.82%)
Mutual labels:  tdd, bdd, karma, jasmine
Spectrum
A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber.
Stars: ✭ 142 (-74.28%)
Mutual labels:  unit-testing, bdd, jasmine
Ut
UT: C++20 μ(micro)/Unit Testing Framework
Stars: ✭ 507 (-8.15%)
Mutual labels:  unit-testing, tdd, bdd
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (-34.06%)
Mutual labels:  jest, tdd, bdd
Karmatic
🦑 Easy automatic (headless) browser testing with Jest's API, but powered by Karma & Webpack.
Stars: ✭ 1,178 (+113.41%)
Mutual labels:  jest, karma, jasmine
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (-41.67%)
Mutual labels:  jest, unit-testing, jasmine
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-94.02%)
Mutual labels:  unit-testing, tdd, bdd
angular-material-boilerplate
A straightforward and well structured boilerplate based on Google's Angular Material project.
Stars: ✭ 28 (-94.93%)
Mutual labels:  unit-testing, jasmine, karma
Semaphore Ng2 Webpack
Stars: ✭ 81 (-85.33%)
Mutual labels:  unit-testing, karma, jasmine
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (-95.29%)
Mutual labels:  unit-testing, jest, tdd
Testdeck
Object oriented testing
Stars: ✭ 206 (-62.68%)
Mutual labels:  jest, tdd, jasmine
tropic
🍍 Test Runner Library
Stars: ✭ 29 (-94.75%)
Mutual labels:  unit-testing, jest, karma
respect
RSpec inspired test framework for Reason/OCaml/Bucklescript.
Stars: ✭ 28 (-94.93%)
Mutual labels:  unit-testing, tdd, bdd
List Of Testing Tools And Frameworks For .net
✅ List of Automated Testing (TDD/BDD/ATDD/SBE) Tools and Frameworks for .NET
Stars: ✭ 303 (-45.11%)
Mutual labels:  tdd, bdd
Everydayrails Rspec 2017
Sample source for the 2017 edition of Everyday Rails Testing with RSpec.
Stars: ✭ 280 (-49.28%)
Mutual labels:  tdd, bdd
Doctest
The fastest feature-rich C++11/14/17/20 single-header testing framework
Stars: ✭ 3,568 (+546.38%)
Mutual labels:  unit-testing, tdd

Jasmine-Matchers

Write Beautiful Specs with Custom Matchers

NPM version NPM downloads Build Status Maintainability

Table of Contents

Overview

What

A huge library of test matchers for a range of common use-cases, compatible with all versions of Jasmine and Jest.

Why

Custom Matchers make tests easier to read and produce relevant and useful messages when they fail.

How

By avoiding vague messages such as "expected false to be true" in favour of useful cues such as "expected 3 to be even number" and avoiding implementation noise such as expect(cycleWheels % 2 === 0).toEqual(true) in favour of simply stating that you expect(cycleWheels).toBeEvenNumber().

Sponsors
Sponsored by BrowserStack

🌩 Installation

npm
npm install jasmine-expect --save-dev
Bower
bower install jasmine-expect --save-dev
Manual

Downloads are available on the releases page.

📝 API

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

expect().nothing()
expect().toBe(expected)
expect().toBeCloseTo(expected, precisionopt)
expect().toBeDefined()
expect().toBeFalse()
expect().toBeFalsy()
expect().toBeGreaterThan(expected)
expect().toBeGreaterThanOrEqual(expected)
expect().toBeInstanceOf(expected)
expect().toBeLessThan(expected)
expect().toBeLessThanOrEqual(expected)
expect().toBeNaN()
expect().toBeNegativeInfinity()
expect().toBeNull()
expect().toBePositiveInfinity()
expect().toBeTrue()
expect().toBeTruthy()
expect().toBeUndefined()
expect().toContain(expected)
expect().toEqual(expected)
expect().toHaveBeenCalled()
expect().toHaveBeenCalledBefore(expected)
expect().toHaveBeenCalledOnceWith()
expect().toHaveBeenCalledTimes(expected)
expect().toHaveBeenCalledWith()
expect().toHaveClass(expected)
expect().toHaveSize(expected)
expect().toMatch(expected)
expect().toThrow(expectedopt)
expect().toThrowError(expectedopt, messageopt)
expect().toThrowMatching(predicate)
expect().withContext(message)

and this default set of asymmetric matchers;

jasmine.any(Constructor);
jasmine.anything(mixed);
jasmine.arrayContaining(mixed);
jasmine.objectContaining(mixed);
jasmine.stringMatching(pattern);

Matchers

Jasmine-Matchers adds the following matchers:

expect(array).toBeArray();
expect(array).toBeArrayOfBooleans();
expect(array).toBeArrayOfNumbers();
expect(array).toBeArrayOfObjects();
expect(array).toBeArrayOfSize(number);
expect(array).toBeArrayOfStrings();
expect(array).toBeEmptyArray();
expect(array).toBeNonEmptyArray();
expect(boolean).toBeBoolean();
expect(date).toBeAfter(otherDate);
expect(date).toBeBefore(otherDate);
expect(date).toBeDate();
expect(date).toBeValidDate();
expect(fn).toBeFunction();
expect(fn).toThrowAnyError();
expect(fn).toThrowErrorOfType(constructorName);
expect(mixed).toBeCalculable();
expect(number).toBeEvenNumber();
expect(number).toBeGreaterThanOrEqualTo(otherNumber);
expect(number).toBeLessThanOrEqualTo(otherNumber);
expect(number).toBeNear(otherNumber, epsilon);
expect(number).toBeNumber();
expect(number).toBeOddNumber();
expect(number).toBeWholeNumber();
expect(number).toBeWithinRange(floor, ceiling);
expect(object).toBeEmptyObject();
expect(object).toBeNonEmptyObject();
expect(object).toBeObject();
expect(object).toHaveArray(memberName);
expect(object).toHaveArrayOfBooleans(memberName);
expect(object).toHaveArrayOfNumbers(memberName);
expect(object).toHaveArrayOfObjects(memberName);
expect(object).toHaveArrayOfSize(memberName, size);
expect(object).toHaveArrayOfStrings(memberName);
expect(object).toHaveBoolean(memberName);
expect(object).toHaveCalculable(memberName);
expect(object).toHaveDate(memberName);
expect(object).toHaveDateAfter(memberName, date);
expect(object).toHaveDateBefore(memberName, date);
expect(object).toHaveEmptyArray(memberName);
expect(object).toHaveEmptyObject(memberName);
expect(object).toHaveEmptyString(memberName);
expect(object).toHaveEvenNumber(memberName);
expect(object).toHaveFalse(memberName);
expect(object).toHaveHtmlString(memberName);
expect(object).toHaveIso8601(memberName);
expect(object).toHaveJsonString(memberName);
expect(object).toHaveMember(memberName);
expect(object).toHaveMethod(memberName);
expect(object).toHaveNonEmptyArray(memberName);
expect(object).toHaveNonEmptyObject(memberName);
expect(object).toHaveNonEmptyString(memberName);
expect(object).toHaveNumber(memberName);
expect(object).toHaveNumberWithinRange(memberName, floor, ceiling);
expect(object).toHaveObject(memberName);
expect(object).toHaveOddNumber(memberName);
expect(object).toHaveString(memberName);
expect(object).toHaveStringLongerThan(memberName, string);
expect(object).toHaveStringSameLengthAs(memberName, string);
expect(object).toHaveStringShorterThan(memberName, string);
expect(object).toHaveTrue(memberName);
expect(object).toHaveUndefined(memberName);
expect(object).toHaveWhitespaceString(memberName);
expect(object).toHaveWholeNumber(memberName);
expect(regexp).toBeRegExp();
expect(string).toBeEmptyString();
expect(string).toBeHtmlString();
expect(string).toBeIso8601();
expect(string).toBeJsonString();
expect(string).toBeLongerThan(otherString);
expect(string).toBeNonEmptyString();
expect(string).toBeSameLengthAs(otherString);
expect(string).toBeShorterThan(otherString);
expect(string).toBeString();
expect(string).toBeWhitespace();
expect(string).toEndWith(substring);
expect(string).toStartWith(substring);

Asymmetric Matchers

any.after(date);
any.arrayOfBooleans();
any.arrayOfNumbers();
any.arrayOfObjects();
any.arrayOfSize(number);
any.arrayOfStrings();
any.before(date);
any.calculable();
any.emptyArray();
any.emptyObject();
any.endingWith(string);
any.evenNumber();
any.greaterThanOrEqualTo(number);
any.iso8601();
any.jsonString();
any.lessThanOrEqualTo(number);
any.longerThan(string);
any.nonEmptyArray();
any.nonEmptyObject();
any.nonEmptyString();
any.oddNumber();
any.regExp();
any.sameLengthAs(string);
any.shorterThan(string);
any.startingWith(string);
any.whitespace();
any.wholeNumber();
any.withinRange(floor, ceiling);

🕹 Usage

Browser

Embed jasmine-matchers.js after Jasmine but before your tests.

Jest

Include the following in your package.json:

"unmockedModulePathPatterns": ["jasmine-expect"]

And the following at the top of your test suite:

import JasmineExpect from "jasmine-expect";

Karma

Integration is easy with the karma-jasmine-matchers plugin.

Node.js

Use the Jasmine CLI and include the path to where Jasmine Matchers is installed in the helpers array of your spec/support/jasmine.json.

{
  "spec_dir": "spec",
  "spec_files": ["../src/**/*.spec.js"],
  "helpers": ["../node_modules/jasmine-expect/index.js"],
  "stopSpecOnExpectationFailure": false,
  "random": false
}

TypeScript and Angular CLI Projects

If you are using TypeScript, you might want to npm install @types/jasmine-expect --save-dev in order to prevent your IDE from complaining about the new Matchers.

Also, if you run into TypeScript compilation errors when running your tests, add "jasmine-expect" to the "types" array in your tests' tsconfig file.

As an example, for an Angular CLI based project, this would be your tsconfig.spec.json file:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": ["jasmine", "node", "jasmine-expect"]
  },
  "files": ["test.ts"],
  "include": ["**/*.spec.ts", "**/*.d.ts"]
}

Sublime Text

Jasmine-Matchers-Snippets or Jasmine-Matchers-ES6-Snippets can be installed with Package Control to ease development with Jasmine Matchers in Sublime Text.

Tern

There is a Plugin for Tern to auto-complete matchers in your Text Editor.

🌍 Browser Support

Jasmine-Matchers is tested on Travis CI and BrowserStack against the following environments.

Browser Version Range
Android 9 - 11
Chrome 80 - 85
Edge 80 - 85
Firefox 76 - 80
iOS 10 - 14
Safari 10 - 13

🙋🏽‍♂️ Getting Help

Get help with issues by creating a Bug Report or discuss ideas by opening a Feature Request.

👀 Other Projects

If you find my Open Source projects useful, please share them ❤️

🤓 Author

I'm Jamie Mason from Leeds in England, I began Web Design and Development in 1999 and have been Contracting and offering Consultancy as Fold Left Ltd since 2012. Who I've worked with includes Sky Sports, Sky Bet, Sky Poker, The Premier League, William Hill, Shell, Betfair, and Football Clubs including Leeds United, Spurs, West Ham, Arsenal, and more.

Follow JamieMason on GitHub      Follow fold_left on Twitter

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].