Skip to content

Commit

Permalink
chore(repo): intial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Jan 18, 2017
0 parents commit 51d4a85
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
*.log
dist
node_modules
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Jamie Mason

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
84 changes: 84 additions & 0 deletions README.md
@@ -0,0 +1,84 @@
# add-matchers

[![NPM version](http://img.shields.io/npm/v/add-matchers.svg?style=flat-square)](https://www.npmjs.com/package/add-matchers)
[![npm downloads](https://img.shields.io/npm/dm/add-matchers.svg?style=flat-square)](https://www.npmjs.com/package/add-matchers)
[![Dependency Status](http://img.shields.io/david/JamieMason/add-matchers.svg?style=flat-square)](https://david-dm.org/JamieMason/add-matchers)
[![Join the chat at https://gitter.im/JamieMason/Jasmine-Matchers](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/JamieMason/Jasmine-Matchers)
[![Analytics](https://ga-beacon.appspot.com/UA-45466560-5/jasmine-matchers?flat&useReferer)](https://github.com/igrigorik/ga-beacon)

|**What**|A JavaScript library to write test Matchers compatible with all versions of [Jest](http://facebook.github.io/jest/) and [Jasmine](https://jasmine.github.io/).|
|---|:---|
|**Why**|The way you write tests in Jasmine and Jest is _extremely_ similar, but the APIs for adding custom matchers vary wildly between Jasmine 1.x, Jasmine 2.x, and Jest. This library aims to remove those obstacles and encourage Developers to share useful matchers they've created with the community.|
|**How**|Developers use the API from this library, which converts them to be compatible with whichever test framework is running.|

## Installation

```
npm install --save-dev add-matchers
```

## Usage

Include this library after your test framework but before your tests, and register your matchers before your tests as well.

## API

The argument passed to `expect` is always the last argument passed to your Matcher, with any other arguments appearing before it in the order they were supplied. This means that, in the case of `expect(recieved).toBeAwesome(arg1, arg2, arg3)`, your function will be called with `fn(arg1, arg2, arg3, recieved)`.

Arguments are ordered in this way to support [partial application](http://ejohn.org/blog/partial-functions-in-javascript/) and increase re-use of matchers.

### Examples

If we wanted to use the following Matchers in our tests;

```js
// matcher with 0 arguments
expect(4).toBeEvenNumber();

// matcher with 1 argument
expect({}).toBeOfType('Object');

// matcher with Many arguments
expect([100, 14, 15, 2]).toContainItems(2, 15, 100);
```

We would create them as follows;

```js
var addMatchers = require('add-matchers');

addMatchers({
// matcher with 0 arguments
toBeEvenNumber: function(received) {
// received : 4
return received % 2 === 0;
},
// matcher with 1 argument
toBeOfType: function(type, received) {
// type : 'Object'
// received : {}
return Object.prototype.toString.call(received) === '[object ' + type + ']';
},
// matcher with many arguments
toContainItems: function(arg1, arg2, arg3, received) {
// arg1 : 2
// arg2 : 15
// arg3 : 100
// received : [100, 14, 15, 2]
return (
received.indexOf(arg1) !== -1 &&
received.indexOf(arg2) !== -1 &&
received.indexOf(arg3) !== -1
);
}
});
```

For more examples, see [Jasmine Matchers](https://github.com/JamieMason/Jasmine-Matchers/tree/master/src) which is built using this library.

## Related Projects

+ [Jasmine Matchers](https://github.com/JamieMason/Jasmine-Matchers): A huge library of test assertion matchers to improve readability.
+ [karma-benchmark](https://github.com/JamieMason/karma-benchmark): A Karma plugin to run [Benchmark.js](https://benchmarkjs.com/) over multiple browsers, with CI compatible output.
+ [karma-jasmine-matchers](https://github.com/JamieMason/karma-jasmine-matchers): A Karma plugin to inject Jasmine Matchers.
+ [karma-nested-reporter](https://github.com/JamieMason/karma-nested-reporter): Easy to read test output with nested `describe` and `it` blocks.
7 changes: 7 additions & 0 deletions jasmine.json
@@ -0,0 +1,7 @@
{
"spec_dir": "src",
"spec_files": ["./**/*.spec.js"],
"helpers": [],
"stopSpecOnExpectationFailure": false,
"random": true
}
51 changes: 51 additions & 0 deletions package.json
@@ -0,0 +1,51 @@
{
"name": "add-matchers",
"description": "Write useful test matchers compatible with Jest and Jasmine.",
"version": "0.1.0",
"author": "Jamie Mason (https://github.com/JamieMason)",
"bugs": {
"url": "https://github.com/JamieMason/add-matchers/issues"
},
"devDependencies": {
"browserify": "13.0.0",
"jasmine": "2.5.3",
"nodemon": "1.11.0",
"xo": "0.17.1"
},
"files": [
"dist/",
"index.js",
"src/"
],
"homepage": "https://github.com/JamieMason/add-matchers",
"keywords": [
"BDD",
"TDD",
"jasmine",
"testing"
],
"license": "MIT",
"main": "index.js",
"repository": {
"type": "git",
"url": "git://github.com/JamieMason/add-matchers.git"
},
"scripts": {
"build": "browserify index.js --standalone addMatchers --outfile dist/add-matchers.js",
"lint": "xo --fix",
"prepublish": "npm run build",
"test": "jasmine JASMINE_CONFIG_PATH=jasmine.json",
"watch": "nodemon --quiet --watch src/ --watch index.js ./node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=jasmine.json"
},
"xo": {
"envs": [
"jasmine",
"node"
],
"rules": {
"max-nested-callbacks": 0
},
"esnext": false,
"space": 2
}
}

0 comments on commit 51d4a85

Please sign in to comment.