Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

add-matchers

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-matchers - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

src/add-asymmetric-matchers.js

12

CHANGELOG.md

@@ -0,3 +1,13 @@

<a name="0.5.0"></a>
# [0.5.0](https://github.com/JamieMason/add-matchers/compare/0.4.0...v0.5.0) (2017-03-09)
### Features
* **core:** support asymmetric jasmine and jest matchers ([e1e5c18](https://github.com/JamieMason/add-matchers/commit/e1e5c18))
<a name="0.4.0"></a>
# 0.4.0 (2017-01-18)
# [0.4.0](https://github.com/JamieMason/add-matchers/compare/39f4a46...0.4.0) (2017-01-18)

@@ -4,0 +14,0 @@

66

dist/add-matchers.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.addMatchers = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
// modules
var createRegister = require('./src/createRegister');
var createRegister = require('./src/create-register');
var jasmineV1 = require('./src/jasmine-v1');

@@ -17,4 +17,35 @@ var jasmineV2 = require('./src/jasmine-v2');

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./src/createRegister":2,"./src/jasmine-v1":3,"./src/jasmine-v2":4,"./src/jest":7}],2:[function(require,module,exports){
},{"./src/create-register":3,"./src/jasmine-v1":4,"./src/jasmine-v2":5,"./src/jest":8}],2:[function(require,module,exports){
(function (global){
// public
module.exports = addAsymmetricMatchers;
// implementation
function addAsymmetricMatchers(matchersByName) {
/* eslint guard-for-in: 0 */
global.any = global.any || {};
for (var name in matchersByName) {
addAsymmetricMatcher(name, matchersByName[name]);
}
}
function addAsymmetricMatcher(name, matcher) {
global.any[name] = function () {
var args = [].slice.call(arguments);
return {
asymmetricMatch: function (actual) {
var clone = args.slice();
clone.push(actual);
return matcher.apply(this, clone);
}
};
};
}
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
// modules
var addAsymmetricMatchers = require('./add-asymmetric-matchers');
// public
module.exports = createRegister;

@@ -36,3 +67,8 @@

return function (matchersByName) {
addMatchers.asymmetric = addAsymmetricMatchers;
return addMatchers;
function addMatchers(matchersByName) {
/* eslint guard-for-in: 0 */
for (var name in matchersByName) {

@@ -44,6 +80,6 @@ var matcherFunction = matchersByName[name];

}
};
}
}
},{}],3:[function(require,module,exports){
},{"./add-asymmetric-matchers":2}],4:[function(require,module,exports){
module.exports = {

@@ -95,5 +131,5 @@ getAdapters: function (globals) {

},{}],4:[function(require,module,exports){
var matcherFactory = require('./matcherFactory');
var memberMatcherFactory = require('./memberMatcherFactory');
},{}],5:[function(require,module,exports){
var matcherFactory = require('./matcher-factory');
var memberMatcherFactory = require('./member-matcher-factory');

@@ -133,3 +169,3 @@ module.exports = {

},{"./matcherFactory":5,"./memberMatcherFactory":6}],5:[function(require,module,exports){
},{"./matcher-factory":6,"./member-matcher-factory":7}],6:[function(require,module,exports){
module.exports = {

@@ -195,3 +231,3 @@ 1: forActual,

},{}],6:[function(require,module,exports){
},{}],7:[function(require,module,exports){
module.exports = {

@@ -262,5 +298,5 @@ 2: forKeyAndActual,

},{}],7:[function(require,module,exports){
var matcherFactory = require('./matcherFactory');
var memberMatcherFactory = require('./memberMatcherFactory');
},{}],8:[function(require,module,exports){
var matcherFactory = require('./matcher-factory');
var memberMatcherFactory = require('./member-matcher-factory');

@@ -298,3 +334,3 @@ module.exports = {

},{"./matcherFactory":8,"./memberMatcherFactory":9}],8:[function(require,module,exports){
},{"./matcher-factory":9,"./member-matcher-factory":10}],9:[function(require,module,exports){
module.exports = {

@@ -352,3 +388,3 @@ 1: adapterForActual,

},{}],9:[function(require,module,exports){
},{}],10:[function(require,module,exports){
module.exports = {

@@ -355,0 +391,0 @@ 2: forKeyAndActual,

// modules
var createRegister = require('./src/createRegister');
var createRegister = require('./src/create-register');
var jasmineV1 = require('./src/jasmine-v1');

@@ -4,0 +4,0 @@ var jasmineV2 = require('./src/jasmine-v2');

{
"name": "add-matchers",
"description": "Write useful test matchers compatible with Jest and Jasmine.",
"version": "0.4.0",
"version": "0.5.0",
"author": "Jamie Mason (https://github.com/JamieMason)",

@@ -36,2 +36,3 @@ "bugs": {

"lint": "xo --fix",
"prebuild": "mkdir -p dist",
"prepublish": "npm run build",

@@ -38,0 +39,0 @@ "test": "jasmine JASMINE_CONFIG_PATH=jasmine.json",

@@ -7,3 +7,3 @@ # 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)
[![Analytics](https://ga-beacon.appspot.com/UA-45466560-5/add-matchers?flat&useReferer)](https://github.com/igrigorik/ga-beacon)

@@ -15,2 +15,10 @@ |**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/).|

## Contents
* [Installation](#installation)
* [API](#api)
* [Writing Matchers](#writing-matchers)
* [Examples](#examples)
* [Related Projects](#related-projects)
## Installation

@@ -22,10 +30,34 @@

## Usage
Include add-matchers after your test framework but before your tests, and register your matchers before your tests as well.
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)`.
```
var addMatchers = require('add-matchers');
addMatchers({
toBeFoo: function() {},
toBeBar: function() {}
});
// expect('foo').toBeFoo();
// expect('bar').toBeBar();
addMatchers.asymmetric({
foo: function() {},
bar: function() {}
});
// expect({ key: 'foo', prop: 'bar' }).toEqual({
// key: any.foo(),
// prop: any.bar()
// });
```
## Writing Matchers
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(received).toBeAwesome(arg1, arg2, arg3)`, your function will be called with `fn(arg1, arg2, arg3, received)`.
Arguments are ordered in this way to support [partial application](http://ejohn.org/blog/partial-functions-in-javascript/) and increase re-use of matchers.

@@ -32,0 +64,0 @@

@@ -1,3 +0,3 @@

var matcherFactory = require('./matcherFactory');
var memberMatcherFactory = require('./memberMatcherFactory');
var matcherFactory = require('./matcher-factory');
var memberMatcherFactory = require('./member-matcher-factory');

@@ -4,0 +4,0 @@ module.exports = {

@@ -1,3 +0,3 @@

var matcherFactory = require('./matcherFactory');
var memberMatcherFactory = require('./memberMatcherFactory');
var matcherFactory = require('./matcher-factory');
var memberMatcherFactory = require('./member-matcher-factory');

@@ -4,0 +4,0 @@ module.exports = {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc