Comparing version 1.10.0 to 1.11.0
@@ -8,2 +8,3 @@ /** | ||
exports.__esModule = true; | ||
function arrayContains(array, value, comparator) { | ||
@@ -17,2 +18,3 @@ if (comparator == null) return array.indexOf(value) !== -1; | ||
module.exports = arrayContains; | ||
exports["default"] = arrayContains; | ||
module.exports = exports["default"]; |
'use strict'; | ||
var deepEqual = require('deep-equal'); | ||
var isRegExp = require('is-regexp'); | ||
var invariant = require('./invariant'); | ||
var isFunction = require('./isFunction'); | ||
var functionThrows = require('./functionThrows'); | ||
var stringContains = require('./stringContains'); | ||
var arrayContains = require('./arrayContains'); | ||
var isA = require('./isA'); | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _deepEqual = require('deep-equal'); | ||
var _deepEqual2 = _interopRequireDefault(_deepEqual); | ||
var _isRegexp = require('is-regexp'); | ||
var _isRegexp2 = _interopRequireDefault(_isRegexp); | ||
var _invariant = require('./invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _isFunction = require('./isFunction'); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
var _functionThrows = require('./functionThrows'); | ||
var _functionThrows2 = _interopRequireDefault(_functionThrows); | ||
var _stringContains = require('./stringContains'); | ||
var _stringContains2 = _interopRequireDefault(_stringContains); | ||
var _arrayContains = require('./arrayContains'); | ||
var _arrayContains2 = _interopRequireDefault(_arrayContains); | ||
var _SpyUtils = require('./SpyUtils'); | ||
var _isA = require('./isA'); | ||
var _isA2 = _interopRequireDefault(_isA); | ||
var isArray = Array.isArray; | ||
@@ -18,209 +50,214 @@ | ||
*/ | ||
function Expectation(actual) { | ||
if (!(this instanceof Expectation)) return new Expectation(actual); | ||
this.actual = actual; | ||
var Expectation = (function () { | ||
function Expectation(actual) { | ||
_classCallCheck(this, Expectation); | ||
if (isFunction(actual)) { | ||
this.context = null; | ||
this.args = []; | ||
this.actual = actual; | ||
if (_isFunction2['default'](actual)) { | ||
this.context = null; | ||
this.args = []; | ||
} | ||
} | ||
} | ||
Expectation.prototype.toExist = function (message) { | ||
invariant(this.actual, message || 'Expected %s to exist', this.actual); | ||
Expectation.prototype.toExist = function toExist(message) { | ||
_invariant2['default'](this.actual, message || 'Expected %s to exist', this.actual); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotExist = function (message) { | ||
invariant(!this.actual, message || 'Expected %s to not exist', this.actual); | ||
Expectation.prototype.toNotExist = function toNotExist(message) { | ||
_invariant2['default'](!this.actual, message || 'Expected %s to not exist', this.actual); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBe = function (value, message) { | ||
invariant(this.actual === value, message || 'Expected %s to be %s', this.actual, value); | ||
Expectation.prototype.toBe = function toBe(value, message) { | ||
_invariant2['default'](this.actual === value, message || 'Expected %s to be %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotBe = function (value, message) { | ||
invariant(this.actual !== value, message || 'Expected %s to not be %s', this.actual, value); | ||
Expectation.prototype.toNotBe = function toNotBe(value, message) { | ||
_invariant2['default'](this.actual !== value, message || 'Expected %s to not be %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toEqual = function (value, message) { | ||
invariant(deepEqual(this.actual, value), message || 'Expected %s to equal %s', this.actual, value); | ||
Expectation.prototype.toEqual = function toEqual(value, message) { | ||
_invariant2['default'](_deepEqual2['default'](this.actual, value), message || 'Expected %s to equal %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotEqual = function (value, message) { | ||
invariant(!deepEqual(this.actual, value), message || 'Expected %s to not equal %s', this.actual, value); | ||
Expectation.prototype.toNotEqual = function toNotEqual(value, message) { | ||
_invariant2['default'](!_deepEqual2['default'](this.actual, value), message || 'Expected %s to not equal %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toThrow = function (value, message) { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).toThrow() must be a function, %s was given', this.actual); | ||
Expectation.prototype.toThrow = function toThrow(value, message) { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).toThrow() must be a function, %s was given', this.actual); | ||
invariant(functionThrows(this.actual, this.context, this.args, value), message || 'Expected %s to throw %s', this.actual, value); | ||
_invariant2['default'](_functionThrows2['default'](this.actual, this.context, this.args, value), message || 'Expected %s to throw %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotThrow = function (value, message) { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given', this.actual); | ||
Expectation.prototype.toNotThrow = function toNotThrow(value, message) { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given', this.actual); | ||
invariant(!functionThrows(this.actual, this.context, this.args, value), message || 'Expected %s to not throw %s', this.actual, value); | ||
_invariant2['default'](!_functionThrows2['default'](this.actual, this.context, this.args, value), message || 'Expected %s to not throw %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBeA = function (value, message) { | ||
invariant(isFunction(value) || typeof value === 'string', 'The "value" argument in toBeA(value) must be a function or a string'); | ||
Expectation.prototype.toBeA = function toBeA(value, message) { | ||
_invariant2['default'](_isFunction2['default'](value) || typeof value === 'string', 'The "value" argument in toBeA(value) must be a function or a string'); | ||
invariant(isA(this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
_invariant2['default'](_isA2['default'](this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotBeA = function (value, message) { | ||
invariant(isFunction(value) || typeof value === 'string', 'The "value" argument in toNotBeA(value) must be a function or a string'); | ||
Expectation.prototype.toNotBeA = function toNotBeA(value, message) { | ||
_invariant2['default'](_isFunction2['default'](value) || typeof value === 'string', 'The "value" argument in toNotBeA(value) must be a function or a string'); | ||
invariant(!isA(this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
_invariant2['default'](!_isA2['default'](this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toMatch = function (pattern, message) { | ||
invariant(typeof this.actual === 'string', 'The "actual" argument in expect(actual).toMatch() must be a string'); | ||
Expectation.prototype.toMatch = function toMatch(pattern, message) { | ||
_invariant2['default'](typeof this.actual === 'string', 'The "actual" argument in expect(actual).toMatch() must be a string'); | ||
invariant(isRegExp(pattern), 'The "value" argument in toMatch(value) must be a RegExp'); | ||
_invariant2['default'](_isRegexp2['default'](pattern), 'The "value" argument in toMatch(value) must be a RegExp'); | ||
invariant(pattern.test(this.actual), message || 'Expected %s to match %s', this.actual, pattern); | ||
_invariant2['default'](pattern.test(this.actual), message || 'Expected %s to match %s', this.actual, pattern); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotMatch = function (pattern, message) { | ||
invariant(typeof this.actual === 'string', 'The "actual" argument in expect(actual).toNotMatch() must be a string'); | ||
Expectation.prototype.toNotMatch = function toNotMatch(pattern, message) { | ||
_invariant2['default'](typeof this.actual === 'string', 'The "actual" argument in expect(actual).toNotMatch() must be a string'); | ||
invariant(isRegExp(pattern), 'The "value" argument in toNotMatch(value) must be a RegExp'); | ||
_invariant2['default'](_isRegexp2['default'](pattern), 'The "value" argument in toNotMatch(value) must be a RegExp'); | ||
invariant(!pattern.test(this.actual), message || 'Expected %s to not match %s', this.actual, pattern); | ||
_invariant2['default'](!pattern.test(this.actual), message || 'Expected %s to not match %s', this.actual, pattern); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBeLessThan = function (value, message) { | ||
invariant(typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeLessThan() must be a number'); | ||
Expectation.prototype.toBeLessThan = function toBeLessThan(value, message) { | ||
_invariant2['default'](typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeLessThan() must be a number'); | ||
invariant(typeof value === 'number', 'The "value" argument in toBeLessThan(value) must be a number'); | ||
_invariant2['default'](typeof value === 'number', 'The "value" argument in toBeLessThan(value) must be a number'); | ||
invariant(this.actual < value, message || 'Expected %s to be less than %s', this.actual, value); | ||
_invariant2['default'](this.actual < value, message || 'Expected %s to be less than %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBeGreaterThan = function (value, message) { | ||
invariant(typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeGreaterThan() must be a number'); | ||
Expectation.prototype.toBeGreaterThan = function toBeGreaterThan(value, message) { | ||
_invariant2['default'](typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeGreaterThan() must be a number'); | ||
invariant(typeof value === 'number', 'The "value" argument in toBeGreaterThan(value) must be a number'); | ||
_invariant2['default'](typeof value === 'number', 'The "value" argument in toBeGreaterThan(value) must be a number'); | ||
invariant(this.actual > value, message || 'Expected %s to be greater than %s', this.actual, value); | ||
_invariant2['default'](this.actual > value, message || 'Expected %s to be greater than %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toInclude = function (value, comparator, message) { | ||
invariant(isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toInclude() must be an array or a string'); | ||
Expectation.prototype.toInclude = function toInclude(value, comparator, message) { | ||
_invariant2['default'](isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toInclude() must be an array or a string'); | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
message = message || 'Expected %s to include %s'; | ||
message = message || 'Expected %s to include %s'; | ||
if (isArray(this.actual)) { | ||
invariant(arrayContains(this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
invariant(stringContains(this.actual, value), message, this.actual, value); | ||
} | ||
if (isArray(this.actual)) { | ||
_invariant2['default'](_arrayContains2['default'](this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
_invariant2['default'](_stringContains2['default'](this.actual, value), message, this.actual, value); | ||
} | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toExclude = function (value, comparator, message) { | ||
invariant(isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toExclude() must be an array or a string'); | ||
Expectation.prototype.toExclude = function toExclude(value, comparator, message) { | ||
_invariant2['default'](isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toExclude() must be an array or a string'); | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
message = message || 'Expected %s to exclude %s'; | ||
message = message || 'Expected %s to exclude %s'; | ||
if (isArray(this.actual)) { | ||
invariant(!arrayContains(this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
invariant(!stringContains(this.actual, value), message, this.actual, value); | ||
} | ||
if (isArray(this.actual)) { | ||
_invariant2['default'](!_arrayContains2['default'](this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
_invariant2['default'](!_stringContains2['default'](this.actual, value), message, this.actual, value); | ||
} | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toHaveBeenCalled = function (message) { | ||
var spy = this.actual; | ||
Expectation.prototype.toHaveBeenCalled = function toHaveBeenCalled(message) { | ||
var spy = this.actual; | ||
invariant(spy && spy.__isSpy, 'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy'); | ||
_invariant2['default'](_SpyUtils.isSpy(spy), 'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy'); | ||
invariant(spy.calls.length > 0, message || 'spy was not called'); | ||
_invariant2['default'](spy.calls.length > 0, message || 'spy was not called'); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toHaveBeenCalledWith = function () { | ||
var spy = this.actual; | ||
Expectation.prototype.toHaveBeenCalledWith = function toHaveBeenCalledWith() { | ||
var spy = this.actual; | ||
invariant(spy && spy.__isSpy, 'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy'); | ||
_invariant2['default'](_SpyUtils.isSpy(spy), 'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy'); | ||
var expectedArgs = Array.prototype.slice.call(arguments, 0); | ||
var expectedArgs = Array.prototype.slice.call(arguments, 0); | ||
invariant(spy.calls.some(function (call) { | ||
return deepEqual(call.arguments, expectedArgs); | ||
}), 'spy was never called with %s', expectedArgs); | ||
_invariant2['default'](spy.calls.some(function (call) { | ||
return _deepEqual2['default'](call.arguments, expectedArgs); | ||
}), 'spy was never called with %s', expectedArgs); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotHaveBeenCalled = function (message) { | ||
var spy = this.actual; | ||
Expectation.prototype.toNotHaveBeenCalled = function toNotHaveBeenCalled(message) { | ||
var spy = this.actual; | ||
invariant(spy && spy.__isSpy, 'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy'); | ||
_invariant2['default'](_SpyUtils.isSpy(spy), 'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy'); | ||
invariant(spy.calls.length === 0, message || 'spy was not supposed to be called'); | ||
_invariant2['default'](spy.calls.length === 0, message || 'spy was not supposed to be called'); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.withContext = function (context) { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).withContext() must be a function'); | ||
Expectation.prototype.withContext = function withContext(context) { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).withContext() must be a function'); | ||
this.context = context; | ||
this.context = context; | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.withArgs = function () { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).withArgs() must be a function'); | ||
Expectation.prototype.withArgs = function withArgs() { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).withArgs() must be a function'); | ||
if (arguments.length) this.args = this.args.concat(Array.prototype.slice.call(arguments, 0)); | ||
if (arguments.length) this.args = this.args.concat(Array.prototype.slice.call(arguments, 0)); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
return Expectation; | ||
})(); | ||
var aliases = { | ||
@@ -237,4 +274,5 @@ toBeAn: 'toBeA', | ||
for (var alias in aliases) Expectation.prototype[alias] = Expectation.prototype[aliases[alias]]; | ||
module.exports = Expectation; | ||
for (var alias in aliases) { | ||
Expectation.prototype[alias] = Expectation.prototype[aliases[alias]]; | ||
}exports['default'] = Expectation; | ||
module.exports = exports['default']; |
'use strict'; | ||
var isRegExp = require('is-regexp'); | ||
var isFunction = require('./isFunction'); | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _isRegexp = require('is-regexp'); | ||
var _isRegexp2 = _interopRequireDefault(_isRegexp); | ||
var _isFunction = require('./isFunction'); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
/** | ||
@@ -21,3 +30,3 @@ * Returns true if the given function throws the given value | ||
if (isFunction(value) && error instanceof value) return true; | ||
if (_isFunction2['default'](value) && error instanceof value) return true; | ||
@@ -27,3 +36,3 @@ var message = error.message || error; | ||
if (typeof message === 'string') { | ||
if (isRegExp(value) && value.test(error.message)) return true; | ||
if (_isRegexp2['default'](value) && value.test(error.message)) return true; | ||
@@ -37,2 +46,3 @@ if (typeof value === 'string' && message.indexOf(value) !== -1) return true; | ||
module.exports = functionThrows; | ||
exports['default'] = functionThrows; | ||
module.exports = exports['default']; |
'use strict'; | ||
var expect = require('./Expectation'); | ||
exports.__esModule = true; | ||
expect.createSpy = require('./SpyUtils').createSpy; | ||
expect.spyOn = require('./SpyUtils').spyOn; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
module.exports = expect; | ||
var _Expectation = require('./Expectation'); | ||
var _Expectation2 = _interopRequireDefault(_Expectation); | ||
var _SpyUtils = require('./SpyUtils'); | ||
function expect(actual) { | ||
return new _Expectation2['default'](actual); | ||
} | ||
expect.createSpy = _SpyUtils.createSpy; | ||
expect.spyOn = _SpyUtils.spyOn; | ||
expect.isSpy = _SpyUtils.isSpy; | ||
exports['default'] = expect; | ||
module.exports = exports['default']; |
'use strict'; | ||
var inspect = require('object-inspect'); | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _objectInspect = require('object-inspect'); | ||
var _objectInspect2 = _interopRequireDefault(_objectInspect); | ||
function invariant(condition, messageFormat) { | ||
@@ -11,9 +17,8 @@ if (condition) return; | ||
var message = messageFormat.replace(/%s/g, function () { | ||
return inspect(extraArgs[index++]); | ||
}); | ||
throw new Error(message); | ||
throw new Error(messageFormat.replace(/%s/g, function () { | ||
return _objectInspect2['default'](extraArgs[index++]); | ||
})); | ||
} | ||
module.exports = invariant; | ||
exports['default'] = invariant; | ||
module.exports = exports['default']; |
'use strict'; | ||
var isFunction = require('./isFunction'); | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _isFunction = require('./isFunction'); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
/** | ||
@@ -10,3 +16,3 @@ * Returns true if the given object is an instanceof value | ||
function isA(object, value) { | ||
if (isFunction(value)) return object instanceof value; | ||
if (_isFunction2['default'](value)) return object instanceof value; | ||
@@ -18,2 +24,3 @@ if (value === 'array') return Array.isArray(object); | ||
module.exports = isA; | ||
exports['default'] = isA; | ||
module.exports = exports['default']; |
@@ -6,2 +6,3 @@ /** | ||
exports.__esModule = true; | ||
function isFunction(object) { | ||
@@ -11,2 +12,3 @@ return typeof object === 'function'; | ||
module.exports = isFunction; | ||
exports['default'] = isFunction; | ||
module.exports = exports['default']; |
'use strict'; | ||
var invariant = require('./invariant'); | ||
var isFunction = require('./isFunction'); | ||
exports.__esModule = true; | ||
exports.createSpy = createSpy; | ||
exports.spyOn = spyOn; | ||
exports.isSpy = isSpy; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _invariant = require('./invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _isFunction = require('./isFunction'); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
function noop() {} | ||
@@ -11,5 +23,7 @@ | ||
invariant(isFunction(fn), 'createSpy needs a function'); | ||
_invariant2['default'](_isFunction2['default'](fn), 'createSpy needs a function'); | ||
var targetFn, thrownValue, returnValue; | ||
var targetFn = undefined, | ||
thrownValue = undefined, | ||
returnValue = undefined; | ||
@@ -75,5 +89,4 @@ var spy = function spy() { | ||
module.exports = { | ||
createSpy: createSpy, | ||
spyOn: spyOn | ||
}; | ||
function isSpy(object) { | ||
return object && object.__isSpy === true; | ||
} |
@@ -6,2 +6,3 @@ /** | ||
exports.__esModule = true; | ||
function stringContains(string, value) { | ||
@@ -11,2 +12,3 @@ return string.indexOf(value) !== -1; | ||
module.exports = stringContains; | ||
exports["default"] = stringContains; | ||
module.exports = exports["default"]; |
@@ -8,9 +8,9 @@ /** | ||
if (comparator == null) | ||
return array.indexOf(value) !== -1; | ||
return array.indexOf(value) !== -1 | ||
return array.some(function (item) { | ||
return comparator(item, value) !== false; | ||
}); | ||
return comparator(item, value) !== false | ||
}) | ||
} | ||
module.exports = arrayContains; | ||
export default arrayContains |
@@ -1,11 +0,13 @@ | ||
var deepEqual = require('deep-equal'); | ||
var isRegExp = require('is-regexp'); | ||
var invariant = require('./invariant'); | ||
var isFunction = require('./isFunction'); | ||
var functionThrows = require('./functionThrows'); | ||
var stringContains = require('./stringContains'); | ||
var arrayContains = require('./arrayContains'); | ||
var isA = require('./isA'); | ||
var isArray = Array.isArray; | ||
import deepEqual from 'deep-equal' | ||
import isRegExp from 'is-regexp' | ||
import invariant from './invariant' | ||
import isFunction from './isFunction' | ||
import functionThrows from './functionThrows' | ||
import stringContains from './stringContains' | ||
import arrayContains from './arrayContains' | ||
import { isSpy } from './SpyUtils' | ||
import isA from './isA' | ||
const isArray = Array.isArray | ||
/** | ||
@@ -16,369 +18,370 @@ * An Expectation is a wrapper around an assertion that allows it to be written | ||
*/ | ||
function Expectation(actual) { | ||
if (!(this instanceof Expectation)) | ||
return new Expectation(actual); | ||
class Expectation { | ||
this.actual = actual; | ||
constructor(actual) { | ||
this.actual = actual | ||
if (isFunction(actual)) { | ||
this.context = null; | ||
this.args = []; | ||
if (isFunction(actual)) { | ||
this.context = null | ||
this.args = [] | ||
} | ||
} | ||
} | ||
Expectation.prototype.toExist = function (message) { | ||
invariant( | ||
this.actual, | ||
(message || 'Expected %s to exist'), | ||
this.actual | ||
); | ||
toExist(message) { | ||
invariant( | ||
this.actual, | ||
(message || 'Expected %s to exist'), | ||
this.actual | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toNotExist = function (message) { | ||
invariant( | ||
!this.actual, | ||
(message || 'Expected %s to not exist'), | ||
this.actual | ||
); | ||
toNotExist(message) { | ||
invariant( | ||
!this.actual, | ||
(message || 'Expected %s to not exist'), | ||
this.actual | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toBe = function (value, message) { | ||
invariant( | ||
this.actual === value, | ||
(message || 'Expected %s to be %s'), | ||
this.actual, | ||
value | ||
); | ||
toBe(value, message) { | ||
invariant( | ||
this.actual === value, | ||
(message || 'Expected %s to be %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toNotBe = function (value, message) { | ||
invariant( | ||
this.actual !== value, | ||
(message || 'Expected %s to not be %s'), | ||
this.actual, | ||
value | ||
); | ||
toNotBe(value, message) { | ||
invariant( | ||
this.actual !== value, | ||
(message || 'Expected %s to not be %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toEqual = function (value, message) { | ||
invariant( | ||
deepEqual(this.actual, value), | ||
(message || 'Expected %s to equal %s'), | ||
this.actual, | ||
value | ||
); | ||
toEqual(value, message) { | ||
invariant( | ||
deepEqual(this.actual, value), | ||
(message || 'Expected %s to equal %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toNotEqual = function (value, message) { | ||
invariant( | ||
!deepEqual(this.actual, value), | ||
(message || 'Expected %s to not equal %s'), | ||
this.actual, | ||
value | ||
); | ||
toNotEqual(value, message) { | ||
invariant( | ||
!deepEqual(this.actual, value), | ||
(message || 'Expected %s to not equal %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toThrow = function (value, message) { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).toThrow() must be a function, %s was given', | ||
this.actual | ||
); | ||
toThrow(value, message) { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).toThrow() must be a function, %s was given', | ||
this.actual | ||
) | ||
invariant( | ||
functionThrows(this.actual, this.context, this.args, value), | ||
(message || 'Expected %s to throw %s'), | ||
this.actual, | ||
value | ||
); | ||
invariant( | ||
functionThrows(this.actual, this.context, this.args, value), | ||
(message || 'Expected %s to throw %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toNotThrow = function (value, message) { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given', | ||
this.actual | ||
); | ||
toNotThrow(value, message) { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given', | ||
this.actual | ||
) | ||
invariant( | ||
!functionThrows(this.actual, this.context, this.args, value), | ||
(message || 'Expected %s to not throw %s'), | ||
this.actual, | ||
value | ||
); | ||
invariant( | ||
!functionThrows(this.actual, this.context, this.args, value), | ||
(message || 'Expected %s to not throw %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toBeA = function (value, message) { | ||
invariant( | ||
isFunction(value) || typeof value === 'string', | ||
'The "value" argument in toBeA(value) must be a function or a string' | ||
); | ||
toBeA(value, message) { | ||
invariant( | ||
isFunction(value) || typeof value === 'string', | ||
'The "value" argument in toBeA(value) must be a function or a string' | ||
) | ||
invariant( | ||
isA(this.actual, value), | ||
(message || 'Expected %s to be a %s'), | ||
this.actual, | ||
value | ||
); | ||
invariant( | ||
isA(this.actual, value), | ||
(message || 'Expected %s to be a %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toNotBeA = function (value, message) { | ||
invariant( | ||
isFunction(value) || typeof value === 'string', | ||
'The "value" argument in toNotBeA(value) must be a function or a string' | ||
); | ||
toNotBeA(value, message) { | ||
invariant( | ||
isFunction(value) || typeof value === 'string', | ||
'The "value" argument in toNotBeA(value) must be a function or a string' | ||
) | ||
invariant( | ||
!isA(this.actual, value), | ||
(message || 'Expected %s to be a %s'), | ||
this.actual, | ||
value | ||
); | ||
invariant( | ||
!isA(this.actual, value), | ||
(message || 'Expected %s to be a %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toMatch = function (pattern, message) { | ||
invariant( | ||
typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toMatch() must be a string' | ||
); | ||
toMatch(pattern, message) { | ||
invariant( | ||
typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toMatch() must be a string' | ||
) | ||
invariant( | ||
isRegExp(pattern), | ||
'The "value" argument in toMatch(value) must be a RegExp' | ||
); | ||
invariant( | ||
isRegExp(pattern), | ||
'The "value" argument in toMatch(value) must be a RegExp' | ||
) | ||
invariant( | ||
pattern.test(this.actual), | ||
(message || 'Expected %s to match %s'), | ||
this.actual, | ||
pattern | ||
); | ||
invariant( | ||
pattern.test(this.actual), | ||
(message || 'Expected %s to match %s'), | ||
this.actual, | ||
pattern | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toNotMatch = function (pattern, message) { | ||
invariant( | ||
typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toNotMatch() must be a string' | ||
); | ||
toNotMatch(pattern, message) { | ||
invariant( | ||
typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toNotMatch() must be a string' | ||
) | ||
invariant( | ||
isRegExp(pattern), | ||
'The "value" argument in toNotMatch(value) must be a RegExp' | ||
); | ||
invariant( | ||
isRegExp(pattern), | ||
'The "value" argument in toNotMatch(value) must be a RegExp' | ||
) | ||
invariant( | ||
!pattern.test(this.actual), | ||
(message || 'Expected %s to not match %s'), | ||
this.actual, | ||
pattern | ||
); | ||
invariant( | ||
!pattern.test(this.actual), | ||
(message || 'Expected %s to not match %s'), | ||
this.actual, | ||
pattern | ||
) | ||
return this; | ||
}; | ||
return this | ||
} | ||
Expectation.prototype.toBeLessThan = function (value, message) { | ||
invariant( | ||
typeof this.actual === 'number', | ||
'The "actual" argument in expect(actual).toBeLessThan() must be a number' | ||
); | ||
toBeLessThan(value, message) { | ||
invariant( | ||
typeof this.actual === 'number', | ||
'The "actual" argument in expect(actual).toBeLessThan() must be a number' | ||
) | ||
invariant( | ||
typeof value === 'number', | ||
'The "value" argument in toBeLessThan(value) must be a number' | ||
); | ||
invariant( | ||
typeof value === 'number', | ||
'The "value" argument in toBeLessThan(value) must be a number' | ||
) | ||
invariant( | ||
this.actual < value, | ||
(message || 'Expected %s to be less than %s'), | ||
this.actual, | ||
value | ||
); | ||
invariant( | ||
this.actual < value, | ||
(message || 'Expected %s to be less than %s'), | ||
this.actual, | ||
value | ||
) | ||
return this; | ||
}; | ||
Expectation.prototype.toBeGreaterThan = function (value, message) { | ||
invariant( | ||
typeof this.actual === 'number', | ||
'The "actual" argument in expect(actual).toBeGreaterThan() must be a number' | ||
); | ||
invariant( | ||
typeof value === 'number', | ||
'The "value" argument in toBeGreaterThan(value) must be a number' | ||
); | ||
invariant( | ||
this.actual > value, | ||
(message || 'Expected %s to be greater than %s'), | ||
this.actual, | ||
value | ||
); | ||
return this; | ||
}; | ||
Expectation.prototype.toInclude = function (value, comparator, message) { | ||
invariant( | ||
isArray(this.actual) || typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toInclude() must be an array or a string' | ||
); | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
return this | ||
} | ||
message = message || 'Expected %s to include %s'; | ||
toBeGreaterThan(value, message) { | ||
invariant( | ||
typeof this.actual === 'number', | ||
'The "actual" argument in expect(actual).toBeGreaterThan() must be a number' | ||
) | ||
if (isArray(this.actual)) { | ||
invariant( | ||
arrayContains(this.actual, value, comparator), | ||
message, | ||
this.actual, | ||
value | ||
); | ||
} else { | ||
typeof value === 'number', | ||
'The "value" argument in toBeGreaterThan(value) must be a number' | ||
) | ||
invariant( | ||
stringContains(this.actual, value), | ||
message, | ||
this.actual > value, | ||
(message || 'Expected %s to be greater than %s'), | ||
this.actual, | ||
value | ||
); | ||
) | ||
return this | ||
} | ||
return this; | ||
}; | ||
toInclude(value, comparator, message) { | ||
invariant( | ||
isArray(this.actual) || typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toInclude() must be an array or a string' | ||
) | ||
Expectation.prototype.toExclude = function (value, comparator, message) { | ||
invariant( | ||
isArray(this.actual) || typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toExclude() must be an array or a string' | ||
); | ||
if (typeof comparator === 'string') { | ||
message = comparator | ||
comparator = null | ||
} | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
message = message || 'Expected %s to include %s' | ||
if (isArray(this.actual)) { | ||
invariant( | ||
arrayContains(this.actual, value, comparator), | ||
message, | ||
this.actual, | ||
value | ||
) | ||
} else { | ||
invariant( | ||
stringContains(this.actual, value), | ||
message, | ||
this.actual, | ||
value | ||
) | ||
} | ||
return this | ||
} | ||
message = message || 'Expected %s to exclude %s'; | ||
toExclude(value, comparator, message) { | ||
invariant( | ||
isArray(this.actual) || typeof this.actual === 'string', | ||
'The "actual" argument in expect(actual).toExclude() must be an array or a string' | ||
) | ||
if (isArray(this.actual)) { | ||
invariant( | ||
!arrayContains(this.actual, value, comparator), | ||
message, | ||
this.actual, | ||
value | ||
); | ||
} else { | ||
invariant( | ||
!stringContains(this.actual, value), | ||
message, | ||
this.actual, | ||
value | ||
); | ||
if (typeof comparator === 'string') { | ||
message = comparator | ||
comparator = null | ||
} | ||
message = message || 'Expected %s to exclude %s' | ||
if (isArray(this.actual)) { | ||
invariant( | ||
!arrayContains(this.actual, value, comparator), | ||
message, | ||
this.actual, | ||
value | ||
) | ||
} else { | ||
invariant( | ||
!stringContains(this.actual, value), | ||
message, | ||
this.actual, | ||
value | ||
) | ||
} | ||
return this | ||
} | ||
return this; | ||
}; | ||
toHaveBeenCalled(message) { | ||
const spy = this.actual | ||
Expectation.prototype.toHaveBeenCalled = function (message) { | ||
var spy = this.actual; | ||
invariant( | ||
isSpy(spy), | ||
'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy' | ||
) | ||
invariant( | ||
spy && spy.__isSpy, | ||
'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy' | ||
); | ||
invariant( | ||
spy.calls.length > 0, | ||
(message || 'spy was not called') | ||
) | ||
invariant( | ||
spy.calls.length > 0, | ||
(message || 'spy was not called') | ||
); | ||
return this | ||
} | ||
return this; | ||
}; | ||
toHaveBeenCalledWith() { | ||
const spy = this.actual | ||
Expectation.prototype.toHaveBeenCalledWith = function () { | ||
var spy = this.actual; | ||
invariant( | ||
isSpy(spy), | ||
'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy' | ||
) | ||
invariant( | ||
spy && spy.__isSpy, | ||
'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy' | ||
); | ||
const expectedArgs = Array.prototype.slice.call(arguments, 0) | ||
var expectedArgs = Array.prototype.slice.call(arguments, 0); | ||
invariant( | ||
spy.calls.some(function (call) { | ||
return deepEqual(call.arguments, expectedArgs) | ||
}), | ||
'spy was never called with %s', | ||
expectedArgs | ||
) | ||
invariant( | ||
spy.calls.some(function (call) { | ||
return deepEqual(call.arguments, expectedArgs); | ||
}), | ||
'spy was never called with %s', | ||
expectedArgs | ||
); | ||
return this | ||
} | ||
return this; | ||
}; | ||
toNotHaveBeenCalled(message) { | ||
const spy = this.actual | ||
Expectation.prototype.toNotHaveBeenCalled = function (message) { | ||
var spy = this.actual; | ||
invariant( | ||
isSpy(spy), | ||
'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy' | ||
) | ||
invariant( | ||
spy && spy.__isSpy, | ||
'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy' | ||
); | ||
invariant( | ||
spy.calls.length === 0, | ||
(message || 'spy was not supposed to be called') | ||
) | ||
invariant( | ||
spy.calls.length === 0, | ||
(message || 'spy was not supposed to be called') | ||
); | ||
return this | ||
} | ||
return this; | ||
}; | ||
withContext(context) { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).withContext() must be a function' | ||
) | ||
Expectation.prototype.withContext = function (context) { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).withContext() must be a function' | ||
); | ||
this.context = context | ||
this.context = context; | ||
return this | ||
} | ||
return this; | ||
}; | ||
withArgs() { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).withArgs() must be a function' | ||
) | ||
Expectation.prototype.withArgs = function () { | ||
invariant( | ||
isFunction(this.actual), | ||
'The "actual" argument in expect(actual).withArgs() must be a function' | ||
); | ||
if (arguments.length) | ||
this.args = this.args.concat(Array.prototype.slice.call(arguments, 0)) | ||
if (arguments.length) | ||
this.args = this.args.concat(Array.prototype.slice.call(arguments, 0)); | ||
return this | ||
} | ||
} | ||
return this; | ||
}; | ||
var aliases = { | ||
const aliases = { | ||
toBeAn: 'toBeA', | ||
@@ -392,7 +395,7 @@ toNotBeAn: 'toNotBeA', | ||
toNotContain: 'toExclude' | ||
}; | ||
} | ||
for (var alias in aliases) | ||
Expectation.prototype[alias] = Expectation.prototype[aliases[alias]]; | ||
for (let alias in aliases) | ||
Expectation.prototype[alias] = Expectation.prototype[aliases[alias]] | ||
module.exports = Expectation; | ||
export default Expectation |
@@ -1,3 +0,3 @@ | ||
var isRegExp = require('is-regexp'); | ||
var isFunction = require('./isFunction'); | ||
import isRegExp from 'is-regexp' | ||
import isFunction from './isFunction' | ||
@@ -15,24 +15,24 @@ /** | ||
try { | ||
fn.apply(context, args); | ||
fn.apply(context, args) | ||
} catch (error) { | ||
if (value == null) | ||
return true; | ||
return true | ||
if (isFunction(value) && error instanceof value) | ||
return true; | ||
return true | ||
var message = error.message || error; | ||
const message = error.message || error | ||
if (typeof message === 'string') { | ||
if (isRegExp(value) && value.test(error.message)) | ||
return true; | ||
return true | ||
if (typeof value === 'string' && message.indexOf(value) !== -1) | ||
return true; | ||
return true | ||
} | ||
} | ||
return false; | ||
return false | ||
} | ||
module.exports = functionThrows; | ||
export default functionThrows |
@@ -1,6 +0,12 @@ | ||
var expect = require('./Expectation'); | ||
import Expectation from './Expectation' | ||
import { createSpy, spyOn, isSpy } from './SpyUtils' | ||
expect.createSpy = require('./SpyUtils').createSpy; | ||
expect.spyOn = require('./SpyUtils').spyOn; | ||
function expect(actual) { | ||
return new Expectation(actual) | ||
} | ||
module.exports = expect; | ||
expect.createSpy = createSpy | ||
expect.spyOn = spyOn | ||
expect.isSpy = isSpy | ||
export default expect |
@@ -1,17 +0,17 @@ | ||
var inspect = require('object-inspect'); | ||
import inspect from 'object-inspect' | ||
function invariant(condition, messageFormat) { | ||
if (condition) | ||
return; | ||
return | ||
var extraArgs = Array.prototype.slice.call(arguments, 2); | ||
var index = 0; | ||
let extraArgs = Array.prototype.slice.call(arguments, 2) | ||
let index = 0 | ||
var message = messageFormat.replace(/%s/g, function () { | ||
return inspect(extraArgs[index++]); | ||
}); | ||
throw new Error(message); | ||
throw new Error( | ||
messageFormat.replace(/%s/g, function () { | ||
return inspect(extraArgs[index++]) | ||
}) | ||
) | ||
} | ||
module.exports = invariant; | ||
export default invariant |
@@ -1,2 +0,2 @@ | ||
var isFunction = require('./isFunction'); | ||
import isFunction from './isFunction' | ||
@@ -9,10 +9,10 @@ /** | ||
if (isFunction(value)) | ||
return object instanceof value; | ||
return object instanceof value | ||
if (value === 'array') | ||
return Array.isArray(object); | ||
return Array.isArray(object) | ||
return typeof object === value; | ||
return typeof object === value | ||
} | ||
module.exports = isA; | ||
export default isA |
@@ -5,5 +5,5 @@ /** | ||
function isFunction(object) { | ||
return typeof object === 'function'; | ||
return typeof object === 'function' | ||
} | ||
module.exports = isFunction; | ||
export default isFunction |
@@ -1,9 +0,9 @@ | ||
var invariant = require('./invariant'); | ||
var isFunction = require('./isFunction'); | ||
import invariant from './invariant' | ||
import isFunction from './isFunction' | ||
function noop() {} | ||
function createSpy(fn) { | ||
export function createSpy(fn) { | ||
if (fn == null) | ||
fn = noop; | ||
fn = noop | ||
@@ -13,70 +13,69 @@ invariant( | ||
'createSpy needs a function' | ||
); | ||
) | ||
var targetFn, thrownValue, returnValue; | ||
let targetFn, thrownValue, returnValue | ||
var spy = function () { | ||
const spy = function () { | ||
spy.calls.push({ | ||
context: this, | ||
arguments: Array.prototype.slice.call(arguments, 0) | ||
}); | ||
}) | ||
if (targetFn) | ||
return targetFn.apply(this, arguments); | ||
return targetFn.apply(this, arguments) | ||
if (thrownValue) | ||
throw thrownValue; | ||
throw thrownValue | ||
return returnValue; | ||
}; | ||
return returnValue | ||
} | ||
spy.calls = []; | ||
spy.calls = [] | ||
spy.andCall = function (fn) { | ||
targetFn = fn; | ||
return spy; | ||
}; | ||
targetFn = fn | ||
return spy | ||
} | ||
spy.andCallThrough = function () { | ||
return spy.andCall(fn); | ||
}; | ||
return spy.andCall(fn) | ||
} | ||
spy.andThrow = function (object) { | ||
thrownValue = object; | ||
return spy; | ||
}; | ||
thrownValue = object | ||
return spy | ||
} | ||
spy.andReturn = function (value) { | ||
returnValue = value; | ||
return spy; | ||
}; | ||
returnValue = value | ||
return spy | ||
} | ||
spy.getLastCall = function () { | ||
return spy.calls[spy.calls.length - 1]; | ||
}; | ||
return spy.calls[spy.calls.length - 1] | ||
} | ||
spy.__isSpy = true; | ||
spy.__isSpy = true | ||
return spy; | ||
return spy | ||
} | ||
function spyOn(object, methodName) { | ||
var original = object[methodName]; | ||
export function spyOn(object, methodName) { | ||
const original = object[methodName] | ||
if (original == null || !original.__isSpy) { | ||
var spy = createSpy(original); | ||
const spy = createSpy(original) | ||
spy.restore = spy.destroy = function () { | ||
object[methodName] = original; | ||
}; | ||
object[methodName] = original | ||
} | ||
object[methodName] = spy; | ||
object[methodName] = spy | ||
} | ||
return object[methodName]; | ||
return object[methodName] | ||
} | ||
module.exports = { | ||
createSpy: createSpy, | ||
spyOn: spyOn | ||
}; | ||
export function isSpy(object) { | ||
return object && object.__isSpy === true | ||
} |
@@ -5,5 +5,5 @@ /** | ||
function stringContains(string, value) { | ||
return string.indexOf(value) !== -1; | ||
return string.indexOf(value) !== -1 | ||
} | ||
module.exports = stringContains; | ||
export default stringContains |
{ | ||
"name": "expect", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "Write better assertions", | ||
@@ -27,7 +27,8 @@ "main": "lib/index", | ||
"scripts": { | ||
"build": "babel ./modules -d lib --ignore '__tests__'", | ||
"build": "babel ./modules -d lib --stage 0 --loose all --ignore '__tests__'", | ||
"build-umd": "NODE_ENV=production webpack modules/index.js umd/expect.js", | ||
"build-min": "NODE_ENV=production webpack -p modules/index.js umd/expect.min.js", | ||
"test": "eslint modules && mocha --reporter spec 'modules/**/__tests__/*-test.js'", | ||
"test-browser": "eslint modules && karma start" | ||
"lint": "eslint modules", | ||
"test": "npm run lint && mocha --compilers js:babel/register --reporter spec 'modules/**/__tests__/*-test.js'", | ||
"test-browser": "npm run lint && karma start" | ||
}, | ||
@@ -34,0 +35,0 @@ "keywords": [ |
173
README.md
[![build status](https://img.shields.io/travis/mjackson/expect.svg?style=flat-square)](https://travis-ci.org/mjackson/expect) | ||
[![npm package](https://img.shields.io/npm/v/expect.svg?style=flat-square)](https://www.npmjs.org/package/expect) | ||
[expect](https://github.com/mjackson/expect) is a thin wrapper around node's [assert](http://nodejs.org/api/assert.html) module that lets you write better assertions. | ||
[expect](https://github.com/mjackson/expect) lets you write better assertions. | ||
When you use expect, you write assertions similarly to how you would say them, e.g. "I expect this value to be equal to 3" or "I expect this array to contain 3". When you write assertions in this way, you don't need to remember the order of actual and expected arguments to functions like `assert.equal`, which helps you write better tests. | ||
### Usage | ||
### Installation | ||
Using [npm](https://www.npmjs.org/): | ||
$ npm install expect | ||
Then with a module bundler like webpack, use as you would anything else: | ||
```js | ||
// using an ES6 transpiler, like babel | ||
import expect, { createSpy, spyOn, isSpy } from 'expect' | ||
// not using an ES6 transpiler | ||
var expect = require('expect') | ||
var createSpy = expect.createSpy | ||
var spyOn = expect.spyOn | ||
var isSpy = expect.isSpy | ||
``` | ||
There is a UMD build in the npm package in the `umd` directory. Use it like: | ||
```js | ||
var expect = require('expect/umd/expect.min') | ||
``` | ||
### Assertions | ||
##### expect(object).toExist([message]) | ||
Asserts the given `object` is truthy. | ||
```js | ||
expect('something truthy').toExist() | ||
``` | ||
##### expect(object).toNotExist([message]) | ||
Asserts the given `object` is falsy. | ||
```js | ||
expect(null).toNotExist() | ||
``` | ||
##### expect(object).toBe(value, [message]) | ||
Asserts that `object` is strictly equal to `value` using [assert.strictEqual](http://nodejs.org/api/assert.html#assert_assert_strictequal_actual_expected_message). | ||
Asserts that `object` is strictly equal to `value` using `===`. | ||
##### expect(object).toNotBe(value, [message]) | ||
Asserts that `object` is not strictly equal to `value` using [assert.notStrictEqual](http://nodejs.org/api/assert.html#assert_assert_notstrictequal_actual_expected_message). | ||
Asserts that `object` is not strictly equal to `value` using `===`. | ||
##### expect(object).toEqual(value, [message]) | ||
Asserts that the given `object` equals `value` using [assert.deepEqual](http://nodejs.org/api/assert.html#assert_assert_deepequal_actual_expected_message). | ||
Asserts that the given `object` equals `value` using [deep-equal](https://www.npmjs.com/package/deep-equal). | ||
##### expect(object).toNotEqual(value, [message]) | ||
Asserts that the given `object` is not equal to `value` using [assert.notDeepEqual](http://nodejs.org/api/assert.html#assert_assert_notdeepequal_actual_expected_message). | ||
Asserts that the given `object` is not equal to `value` using [deep-equal](https://www.npmjs.com/package/deep-equal). | ||
##### expect(block).toThrow([error], [message]) | ||
Asserts that the given `block` throws an error using [assert.throws](http://nodejs.org/api/assert.html#assert_assert_throws_block_error_message). The `error` argument may be a constructor, `RegExp`, or validation function. | ||
Asserts that the given `block` `throw`s an error. The `error` argument may be a constructor (to test using `instanceof`), or a string/`RegExp` to test against `error.message`. | ||
```js | ||
expect(function () { | ||
throw new Error('boom!'); | ||
}).toThrow(/boom/); | ||
throw new Error('boom!') | ||
}).toThrow(/boom/) | ||
``` | ||
##### expect(block).withArgs(arg1[,arg2...]).toThrow([error], [message]) | ||
##### expect(block).withArgs(...args).toThrow([error], [message]) | ||
Asserts that the given `block` throws an error, when called `args`, using [assert.throws](http://nodejs.org/api/assert.html#assert_assert_throws_block_error_message). The `error` argument may be a constructor, `RegExp`, or validation function. | ||
Asserts that the given `block` `throw`s an error when called with `args`. The `error` argument may be a constructor (to test using `instanceof`), or a string/`RegExp` to test against `error.message`. | ||
```js | ||
expect(function (check) { | ||
if (check === 'bad') { | ||
throw new Error('boom!'); | ||
} | ||
}).withArgs('bad').toThrow(/boom/); | ||
if (check === 'bad') | ||
throw new Error('boom!') | ||
}).withArgs('bad').toThrow(/boom/) | ||
``` | ||
@@ -50,10 +90,9 @@ | ||
Asserts that the given `block` throws an error, when called on `context`, using [assert.throws](http://nodejs.org/api/assert.html#assert_assert_throws_block_error_message). The `error` argument may be a constructor, `RegExp`, or validation function. | ||
Asserts that the given `block` `throw`s an error when called in the given `context`. The `error` argument may be a constructor (to test using `instanceof`), or a string/`RegExp` to test against `error.message`. | ||
```js | ||
expect(function () { | ||
if (this.check === 'bad') { | ||
throw new Error('boom!'); | ||
} | ||
}).withContext({ check: 'bad' }).toThrow(/boom/); | ||
if (this.check === 'bad') | ||
throw new Error('boom!') | ||
}).withContext({ check: 'bad' }).toThrow(/boom/) | ||
``` | ||
@@ -63,20 +102,4 @@ | ||
Asserts that the given `block` does not throw using [assert.doesNotThrow](http://nodejs.org/api/assert.html#assert_assert_doesnotthrow_block_message). | ||
Asserts that the given `block` does not `throw`. | ||
##### expect(object).toExist([message]) | ||
Asserts the given `object` is truthy. | ||
```js | ||
expect('something truthy').toExist(); | ||
``` | ||
##### expect(object).toNotExist([message]) | ||
Asserts the given `object` is falsy. | ||
```js | ||
expect(null).toNotExist(); | ||
``` | ||
##### expect(object).toBeA(constructor, [message]) | ||
@@ -88,4 +111,4 @@ ##### expect(object).toBeAn(constructor, [message]) | ||
```js | ||
expect(new User).toBeA(User); | ||
expect(new Asset).toBeAn(Asset); | ||
expect(new User).toBeA(User) | ||
expect(new Asset).toBeAn(Asset) | ||
``` | ||
@@ -98,3 +121,3 @@ | ||
```js | ||
expect(2).toBeA('number'); | ||
expect(2).toBeA('number') | ||
``` | ||
@@ -108,4 +131,4 @@ | ||
```js | ||
expect(new User).toBeA(User); | ||
expect(new Asset).toBeAn(Asset); | ||
expect(new User).toBeA(User) | ||
expect(new Asset).toBeAn(Asset) | ||
``` | ||
@@ -118,3 +141,3 @@ | ||
```js | ||
expect(2).toBeA('number'); | ||
expect(2).toBeA('number') | ||
``` | ||
@@ -127,3 +150,3 @@ | ||
```js | ||
expect('a string').toMatch(/string/); | ||
expect('a string').toMatch(/string/) | ||
``` | ||
@@ -137,3 +160,3 @@ | ||
```js | ||
expect(2).toBeLessThan(3); | ||
expect(2).toBeLessThan(3) | ||
``` | ||
@@ -147,3 +170,3 @@ | ||
```js | ||
expect(3).toBeGreaterThan(2); | ||
expect(3).toBeGreaterThan(2) | ||
``` | ||
@@ -157,3 +180,3 @@ | ||
```js | ||
expect([ 1, 2, 3 ]).toInclude(3); | ||
expect([ 1, 2, 3 ]).toInclude(3) | ||
``` | ||
@@ -167,3 +190,3 @@ | ||
```js | ||
expect([ 1, 2, 3 ]).toExclude(4); | ||
expect([ 1, 2, 3 ]).toExclude(4) | ||
``` | ||
@@ -177,4 +200,4 @@ | ||
```js | ||
expect('hello world').toInclude('world'); | ||
expect('hello world').toContain('world'); | ||
expect('hello world').toInclude('world') | ||
expect('hello world').toContain('world') | ||
``` | ||
@@ -188,28 +211,6 @@ | ||
```js | ||
expect('hello world').toExclude('goodbye'); | ||
expect('hello world').toNotContain('goodbye'); | ||
expect('hello world').toExclude('goodbye') | ||
expect('hello world').toNotContain('goodbye') | ||
``` | ||
### Spies | ||
expect.js also includes the ability to create spy functions that can track the calls that are made to other functions and make various assertions based on the arguments and context that were used. | ||
```js | ||
var video = { | ||
play: function () {}, | ||
pause: function () {}, | ||
rewind: function () {} | ||
}; | ||
var spy = expect.spyOn(video, 'play'); | ||
video.play('some', 'args'); | ||
expect(spy.calls.length).toEqual(1); | ||
expect(spy.calls[0].context).toBe(video); | ||
expect(spy.calls[0].arguments).toEqual([ 'some', 'args' ]); | ||
expect(spy).toHaveBeenCalled(); | ||
expect(spy).toHaveBeenCalledWith('some', 'args'); | ||
``` | ||
### Chaining Assertions | ||
@@ -223,15 +224,25 @@ | ||
.toBeLessThan(4) | ||
.toBeGreaterThan(3); | ||
.toBeGreaterThan(3) | ||
``` | ||
### Installation | ||
### Spies | ||
Using [npm](https://www.npmjs.org/): | ||
expect also includes the ability to create spy functions that can track the calls that are made to other functions and make various assertions based on the arguments and context that were used. | ||
$ npm install expect | ||
```js | ||
var video = { | ||
play: function () {}, | ||
pause: function () {}, | ||
rewind: function () {} | ||
} | ||
There is a UMD build in the npm package in the `umd` directory. Use it like: | ||
var spy = expect.spyOn(video, 'play') | ||
```js | ||
var expect = require('expect/umd/expect.min'); | ||
video.play('some', 'args') | ||
expect(spy.calls.length).toEqual(1) | ||
expect(spy.calls[0].context).toBe(video) | ||
expect(spy.calls[0].arguments).toEqual([ 'some', 'args' ]) | ||
expect(spy).toHaveBeenCalled() | ||
expect(spy).toHaveBeenCalledWith('some', 'args') | ||
``` | ||
@@ -238,0 +249,0 @@ |
@@ -59,9 +59,23 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var expect = __webpack_require__(1); | ||
exports.__esModule = true; | ||
expect.createSpy = __webpack_require__(13).createSpy; | ||
expect.spyOn = __webpack_require__(13).spyOn; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
module.exports = expect; | ||
var _Expectation = __webpack_require__(1); | ||
var _Expectation2 = _interopRequireDefault(_Expectation); | ||
var _SpyUtils = __webpack_require__(12); | ||
function expect(actual) { | ||
return new _Expectation2['default'](actual); | ||
} | ||
expect.createSpy = _SpyUtils.createSpy; | ||
expect.spyOn = _SpyUtils.spyOn; | ||
expect.isSpy = _SpyUtils.isSpy; | ||
exports['default'] = expect; | ||
module.exports = exports['default']; | ||
/***/ }, | ||
@@ -73,10 +87,42 @@ /* 1 */ | ||
var deepEqual = __webpack_require__(2); | ||
var isRegExp = __webpack_require__(5); | ||
var invariant = __webpack_require__(6); | ||
var isFunction = __webpack_require__(8); | ||
var functionThrows = __webpack_require__(9); | ||
var stringContains = __webpack_require__(10); | ||
var arrayContains = __webpack_require__(11); | ||
var isA = __webpack_require__(12); | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _deepEqual = __webpack_require__(2); | ||
var _deepEqual2 = _interopRequireDefault(_deepEqual); | ||
var _isRegexp = __webpack_require__(5); | ||
var _isRegexp2 = _interopRequireDefault(_isRegexp); | ||
var _invariant = __webpack_require__(6); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _isFunction = __webpack_require__(8); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
var _functionThrows = __webpack_require__(9); | ||
var _functionThrows2 = _interopRequireDefault(_functionThrows); | ||
var _stringContains = __webpack_require__(10); | ||
var _stringContains2 = _interopRequireDefault(_stringContains); | ||
var _arrayContains = __webpack_require__(11); | ||
var _arrayContains2 = _interopRequireDefault(_arrayContains); | ||
var _SpyUtils = __webpack_require__(12); | ||
var _isA = __webpack_require__(13); | ||
var _isA2 = _interopRequireDefault(_isA); | ||
var isArray = Array.isArray; | ||
@@ -89,209 +135,214 @@ | ||
*/ | ||
function Expectation(actual) { | ||
if (!(this instanceof Expectation)) return new Expectation(actual); | ||
this.actual = actual; | ||
var Expectation = (function () { | ||
function Expectation(actual) { | ||
_classCallCheck(this, Expectation); | ||
if (isFunction(actual)) { | ||
this.context = null; | ||
this.args = []; | ||
this.actual = actual; | ||
if (_isFunction2['default'](actual)) { | ||
this.context = null; | ||
this.args = []; | ||
} | ||
} | ||
} | ||
Expectation.prototype.toExist = function (message) { | ||
invariant(this.actual, message || 'Expected %s to exist', this.actual); | ||
Expectation.prototype.toExist = function toExist(message) { | ||
_invariant2['default'](this.actual, message || 'Expected %s to exist', this.actual); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotExist = function (message) { | ||
invariant(!this.actual, message || 'Expected %s to not exist', this.actual); | ||
Expectation.prototype.toNotExist = function toNotExist(message) { | ||
_invariant2['default'](!this.actual, message || 'Expected %s to not exist', this.actual); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBe = function (value, message) { | ||
invariant(this.actual === value, message || 'Expected %s to be %s', this.actual, value); | ||
Expectation.prototype.toBe = function toBe(value, message) { | ||
_invariant2['default'](this.actual === value, message || 'Expected %s to be %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotBe = function (value, message) { | ||
invariant(this.actual !== value, message || 'Expected %s to not be %s', this.actual, value); | ||
Expectation.prototype.toNotBe = function toNotBe(value, message) { | ||
_invariant2['default'](this.actual !== value, message || 'Expected %s to not be %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toEqual = function (value, message) { | ||
invariant(deepEqual(this.actual, value), message || 'Expected %s to equal %s', this.actual, value); | ||
Expectation.prototype.toEqual = function toEqual(value, message) { | ||
_invariant2['default'](_deepEqual2['default'](this.actual, value), message || 'Expected %s to equal %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotEqual = function (value, message) { | ||
invariant(!deepEqual(this.actual, value), message || 'Expected %s to not equal %s', this.actual, value); | ||
Expectation.prototype.toNotEqual = function toNotEqual(value, message) { | ||
_invariant2['default'](!_deepEqual2['default'](this.actual, value), message || 'Expected %s to not equal %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toThrow = function (value, message) { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).toThrow() must be a function, %s was given', this.actual); | ||
Expectation.prototype.toThrow = function toThrow(value, message) { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).toThrow() must be a function, %s was given', this.actual); | ||
invariant(functionThrows(this.actual, this.context, this.args, value), message || 'Expected %s to throw %s', this.actual, value); | ||
_invariant2['default'](_functionThrows2['default'](this.actual, this.context, this.args, value), message || 'Expected %s to throw %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotThrow = function (value, message) { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given', this.actual); | ||
Expectation.prototype.toNotThrow = function toNotThrow(value, message) { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given', this.actual); | ||
invariant(!functionThrows(this.actual, this.context, this.args, value), message || 'Expected %s to not throw %s', this.actual, value); | ||
_invariant2['default'](!_functionThrows2['default'](this.actual, this.context, this.args, value), message || 'Expected %s to not throw %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBeA = function (value, message) { | ||
invariant(isFunction(value) || typeof value === 'string', 'The "value" argument in toBeA(value) must be a function or a string'); | ||
Expectation.prototype.toBeA = function toBeA(value, message) { | ||
_invariant2['default'](_isFunction2['default'](value) || typeof value === 'string', 'The "value" argument in toBeA(value) must be a function or a string'); | ||
invariant(isA(this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
_invariant2['default'](_isA2['default'](this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotBeA = function (value, message) { | ||
invariant(isFunction(value) || typeof value === 'string', 'The "value" argument in toNotBeA(value) must be a function or a string'); | ||
Expectation.prototype.toNotBeA = function toNotBeA(value, message) { | ||
_invariant2['default'](_isFunction2['default'](value) || typeof value === 'string', 'The "value" argument in toNotBeA(value) must be a function or a string'); | ||
invariant(!isA(this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
_invariant2['default'](!_isA2['default'](this.actual, value), message || 'Expected %s to be a %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toMatch = function (pattern, message) { | ||
invariant(typeof this.actual === 'string', 'The "actual" argument in expect(actual).toMatch() must be a string'); | ||
Expectation.prototype.toMatch = function toMatch(pattern, message) { | ||
_invariant2['default'](typeof this.actual === 'string', 'The "actual" argument in expect(actual).toMatch() must be a string'); | ||
invariant(isRegExp(pattern), 'The "value" argument in toMatch(value) must be a RegExp'); | ||
_invariant2['default'](_isRegexp2['default'](pattern), 'The "value" argument in toMatch(value) must be a RegExp'); | ||
invariant(pattern.test(this.actual), message || 'Expected %s to match %s', this.actual, pattern); | ||
_invariant2['default'](pattern.test(this.actual), message || 'Expected %s to match %s', this.actual, pattern); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotMatch = function (pattern, message) { | ||
invariant(typeof this.actual === 'string', 'The "actual" argument in expect(actual).toNotMatch() must be a string'); | ||
Expectation.prototype.toNotMatch = function toNotMatch(pattern, message) { | ||
_invariant2['default'](typeof this.actual === 'string', 'The "actual" argument in expect(actual).toNotMatch() must be a string'); | ||
invariant(isRegExp(pattern), 'The "value" argument in toNotMatch(value) must be a RegExp'); | ||
_invariant2['default'](_isRegexp2['default'](pattern), 'The "value" argument in toNotMatch(value) must be a RegExp'); | ||
invariant(!pattern.test(this.actual), message || 'Expected %s to not match %s', this.actual, pattern); | ||
_invariant2['default'](!pattern.test(this.actual), message || 'Expected %s to not match %s', this.actual, pattern); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBeLessThan = function (value, message) { | ||
invariant(typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeLessThan() must be a number'); | ||
Expectation.prototype.toBeLessThan = function toBeLessThan(value, message) { | ||
_invariant2['default'](typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeLessThan() must be a number'); | ||
invariant(typeof value === 'number', 'The "value" argument in toBeLessThan(value) must be a number'); | ||
_invariant2['default'](typeof value === 'number', 'The "value" argument in toBeLessThan(value) must be a number'); | ||
invariant(this.actual < value, message || 'Expected %s to be less than %s', this.actual, value); | ||
_invariant2['default'](this.actual < value, message || 'Expected %s to be less than %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toBeGreaterThan = function (value, message) { | ||
invariant(typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeGreaterThan() must be a number'); | ||
Expectation.prototype.toBeGreaterThan = function toBeGreaterThan(value, message) { | ||
_invariant2['default'](typeof this.actual === 'number', 'The "actual" argument in expect(actual).toBeGreaterThan() must be a number'); | ||
invariant(typeof value === 'number', 'The "value" argument in toBeGreaterThan(value) must be a number'); | ||
_invariant2['default'](typeof value === 'number', 'The "value" argument in toBeGreaterThan(value) must be a number'); | ||
invariant(this.actual > value, message || 'Expected %s to be greater than %s', this.actual, value); | ||
_invariant2['default'](this.actual > value, message || 'Expected %s to be greater than %s', this.actual, value); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toInclude = function (value, comparator, message) { | ||
invariant(isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toInclude() must be an array or a string'); | ||
Expectation.prototype.toInclude = function toInclude(value, comparator, message) { | ||
_invariant2['default'](isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toInclude() must be an array or a string'); | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
message = message || 'Expected %s to include %s'; | ||
message = message || 'Expected %s to include %s'; | ||
if (isArray(this.actual)) { | ||
invariant(arrayContains(this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
invariant(stringContains(this.actual, value), message, this.actual, value); | ||
} | ||
if (isArray(this.actual)) { | ||
_invariant2['default'](_arrayContains2['default'](this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
_invariant2['default'](_stringContains2['default'](this.actual, value), message, this.actual, value); | ||
} | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toExclude = function (value, comparator, message) { | ||
invariant(isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toExclude() must be an array or a string'); | ||
Expectation.prototype.toExclude = function toExclude(value, comparator, message) { | ||
_invariant2['default'](isArray(this.actual) || typeof this.actual === 'string', 'The "actual" argument in expect(actual).toExclude() must be an array or a string'); | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
if (typeof comparator === 'string') { | ||
message = comparator; | ||
comparator = null; | ||
} | ||
message = message || 'Expected %s to exclude %s'; | ||
message = message || 'Expected %s to exclude %s'; | ||
if (isArray(this.actual)) { | ||
invariant(!arrayContains(this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
invariant(!stringContains(this.actual, value), message, this.actual, value); | ||
} | ||
if (isArray(this.actual)) { | ||
_invariant2['default'](!_arrayContains2['default'](this.actual, value, comparator), message, this.actual, value); | ||
} else { | ||
_invariant2['default'](!_stringContains2['default'](this.actual, value), message, this.actual, value); | ||
} | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toHaveBeenCalled = function (message) { | ||
var spy = this.actual; | ||
Expectation.prototype.toHaveBeenCalled = function toHaveBeenCalled(message) { | ||
var spy = this.actual; | ||
invariant(spy && spy.__isSpy, 'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy'); | ||
_invariant2['default'](_SpyUtils.isSpy(spy), 'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy'); | ||
invariant(spy.calls.length > 0, message || 'spy was not called'); | ||
_invariant2['default'](spy.calls.length > 0, message || 'spy was not called'); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toHaveBeenCalledWith = function () { | ||
var spy = this.actual; | ||
Expectation.prototype.toHaveBeenCalledWith = function toHaveBeenCalledWith() { | ||
var spy = this.actual; | ||
invariant(spy && spy.__isSpy, 'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy'); | ||
_invariant2['default'](_SpyUtils.isSpy(spy), 'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy'); | ||
var expectedArgs = Array.prototype.slice.call(arguments, 0); | ||
var expectedArgs = Array.prototype.slice.call(arguments, 0); | ||
invariant(spy.calls.some(function (call) { | ||
return deepEqual(call.arguments, expectedArgs); | ||
}), 'spy was never called with %s', expectedArgs); | ||
_invariant2['default'](spy.calls.some(function (call) { | ||
return _deepEqual2['default'](call.arguments, expectedArgs); | ||
}), 'spy was never called with %s', expectedArgs); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.toNotHaveBeenCalled = function (message) { | ||
var spy = this.actual; | ||
Expectation.prototype.toNotHaveBeenCalled = function toNotHaveBeenCalled(message) { | ||
var spy = this.actual; | ||
invariant(spy && spy.__isSpy, 'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy'); | ||
_invariant2['default'](_SpyUtils.isSpy(spy), 'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy'); | ||
invariant(spy.calls.length === 0, message || 'spy was not supposed to be called'); | ||
_invariant2['default'](spy.calls.length === 0, message || 'spy was not supposed to be called'); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.withContext = function (context) { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).withContext() must be a function'); | ||
Expectation.prototype.withContext = function withContext(context) { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).withContext() must be a function'); | ||
this.context = context; | ||
this.context = context; | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
Expectation.prototype.withArgs = function () { | ||
invariant(isFunction(this.actual), 'The "actual" argument in expect(actual).withArgs() must be a function'); | ||
Expectation.prototype.withArgs = function withArgs() { | ||
_invariant2['default'](_isFunction2['default'](this.actual), 'The "actual" argument in expect(actual).withArgs() must be a function'); | ||
if (arguments.length) this.args = this.args.concat(Array.prototype.slice.call(arguments, 0)); | ||
if (arguments.length) this.args = this.args.concat(Array.prototype.slice.call(arguments, 0)); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
return Expectation; | ||
})(); | ||
var aliases = { | ||
@@ -308,6 +359,7 @@ toBeAn: 'toBeA', | ||
for (var alias in aliases) Expectation.prototype[alias] = Expectation.prototype[aliases[alias]]; | ||
for (var alias in aliases) { | ||
Expectation.prototype[alias] = Expectation.prototype[aliases[alias]]; | ||
}exports['default'] = Expectation; | ||
module.exports = exports['default']; | ||
module.exports = Expectation; | ||
/***/ }, | ||
@@ -470,4 +522,10 @@ /* 2 */ | ||
var inspect = __webpack_require__(7); | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _objectInspect = __webpack_require__(7); | ||
var _objectInspect2 = _interopRequireDefault(_objectInspect); | ||
function invariant(condition, messageFormat) { | ||
@@ -479,10 +537,9 @@ if (condition) return; | ||
var message = messageFormat.replace(/%s/g, function () { | ||
return inspect(extraArgs[index++]); | ||
}); | ||
throw new Error(message); | ||
throw new Error(messageFormat.replace(/%s/g, function () { | ||
return _objectInspect2['default'](extraArgs[index++]); | ||
})); | ||
} | ||
module.exports = invariant; | ||
exports['default'] = invariant; | ||
module.exports = exports['default']; | ||
@@ -651,2 +708,3 @@ /***/ }, | ||
exports.__esModule = true; | ||
function isFunction(object) { | ||
@@ -656,3 +714,4 @@ return typeof object === 'function'; | ||
module.exports = isFunction; | ||
exports['default'] = isFunction; | ||
module.exports = exports['default']; | ||
@@ -665,5 +724,14 @@ /***/ }, | ||
var isRegExp = __webpack_require__(5); | ||
var isFunction = __webpack_require__(8); | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _isRegexp = __webpack_require__(5); | ||
var _isRegexp2 = _interopRequireDefault(_isRegexp); | ||
var _isFunction = __webpack_require__(8); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
/** | ||
@@ -684,3 +752,3 @@ * Returns true if the given function throws the given value | ||
if (isFunction(value) && error instanceof value) return true; | ||
if (_isFunction2['default'](value) && error instanceof value) return true; | ||
@@ -690,3 +758,3 @@ var message = error.message || error; | ||
if (typeof message === 'string') { | ||
if (isRegExp(value) && value.test(error.message)) return true; | ||
if (_isRegexp2['default'](value) && value.test(error.message)) return true; | ||
@@ -700,3 +768,4 @@ if (typeof value === 'string' && message.indexOf(value) !== -1) return true; | ||
module.exports = functionThrows; | ||
exports['default'] = functionThrows; | ||
module.exports = exports['default']; | ||
@@ -712,2 +781,3 @@ /***/ }, | ||
exports.__esModule = true; | ||
function stringContains(string, value) { | ||
@@ -717,3 +787,4 @@ return string.indexOf(value) !== -1; | ||
module.exports = stringContains; | ||
exports["default"] = stringContains; | ||
module.exports = exports["default"]; | ||
@@ -731,2 +802,3 @@ /***/ }, | ||
exports.__esModule = true; | ||
function arrayContains(array, value, comparator) { | ||
@@ -740,3 +812,4 @@ if (comparator == null) return array.indexOf(value) !== -1; | ||
module.exports = arrayContains; | ||
exports["default"] = arrayContains; | ||
module.exports = exports["default"]; | ||
@@ -749,27 +822,17 @@ /***/ }, | ||
var isFunction = __webpack_require__(8); | ||
exports.__esModule = true; | ||
exports.createSpy = createSpy; | ||
exports.spyOn = spyOn; | ||
exports.isSpy = isSpy; | ||
/** | ||
* Returns true if the given object is an instanceof value | ||
* or its typeof is the given value. | ||
*/ | ||
function isA(object, value) { | ||
if (isFunction(value)) return object instanceof value; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
if (value === 'array') return Array.isArray(object); | ||
var _invariant = __webpack_require__(6); | ||
return typeof object === value; | ||
} | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
module.exports = isA; | ||
var _isFunction = __webpack_require__(8); | ||
/***/ }, | ||
/* 13 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
'use strict'; | ||
var invariant = __webpack_require__(6); | ||
var isFunction = __webpack_require__(8); | ||
function noop() {} | ||
@@ -780,5 +843,7 @@ | ||
invariant(isFunction(fn), 'createSpy needs a function'); | ||
_invariant2['default'](_isFunction2['default'](fn), 'createSpy needs a function'); | ||
var targetFn, thrownValue, returnValue; | ||
var targetFn = undefined, | ||
thrownValue = undefined, | ||
returnValue = undefined; | ||
@@ -844,7 +909,35 @@ var spy = function spy() { | ||
module.exports = { | ||
createSpy: createSpy, | ||
spyOn: spyOn | ||
}; | ||
function isSpy(object) { | ||
return object && object.__isSpy === true; | ||
} | ||
/***/ }, | ||
/* 13 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _isFunction = __webpack_require__(8); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
/** | ||
* Returns true if the given object is an instanceof value | ||
* or its typeof is the given value. | ||
*/ | ||
function isA(object, value) { | ||
if (_isFunction2['default'](value)) return object instanceof value; | ||
if (value === 'array') return Array.isArray(object); | ||
return typeof object === value; | ||
} | ||
exports['default'] = isA; | ||
module.exports = exports['default']; | ||
/***/ } | ||
@@ -851,0 +944,0 @@ /******/ ]) |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.expect=e():t.expect=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";var r=n(5);r.createSpy=n(2).createSpy,r.spyOn=n(2).spyOn,t.exports=r},function(t,e){"use strict";function n(t){return"function"==typeof t}t.exports=n},function(t,e,n){"use strict";function r(){}function o(t){null==t&&(t=r),u(i(t),"createSpy needs a function");var e,n,o,a=function c(){if(c.calls.push({context:this,arguments:Array.prototype.slice.call(arguments,0)}),e)return e.apply(this,arguments);if(n)throw n;return o};return a.calls=[],a.andCall=function(t){return e=t,a},a.andCallThrough=function(){return a.andCall(t)},a.andThrow=function(t){return n=t,a},a.andReturn=function(t){return o=t,a},a.getLastCall=function(){return a.calls[a.calls.length-1]},a.__isSpy=!0,a}function a(t,e){var n=t[e];if(null==n||!n.__isSpy){var r=o(n);r.restore=r.destroy=function(){t[e]=n},t[e]=r}return t[e]}var u=n(3),i=n(1);t.exports={createSpy:o,spyOn:a}},function(t,e,n){"use strict";function r(t,e){if(!t){var n=Array.prototype.slice.call(arguments,2),r=0,a=e.replace(/%s/g,function(){return o(n[r++])});throw new Error(a)}}var o=n(13);t.exports=r},function(t,e){"use strict";t.exports=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)}},function(t,e,n){"use strict";function r(t){return this instanceof r?(this.actual=t,void(i(t)&&(this.context=null,this.args=[]))):new r(t)}var o=n(10),a=n(4),u=n(3),i=n(1),c=n(7),s=n(9),l=n(6),p=n(8),f=Array.isArray;r.prototype.toExist=function(t){return u(this.actual,t||"Expected %s to exist",this.actual),this},r.prototype.toNotExist=function(t){return u(!this.actual,t||"Expected %s to not exist",this.actual),this},r.prototype.toBe=function(t,e){return u(this.actual===t,e||"Expected %s to be %s",this.actual,t),this},r.prototype.toNotBe=function(t,e){return u(this.actual!==t,e||"Expected %s to not be %s",this.actual,t),this},r.prototype.toEqual=function(t,e){return u(o(this.actual,t),e||"Expected %s to equal %s",this.actual,t),this},r.prototype.toNotEqual=function(t,e){return u(!o(this.actual,t),e||"Expected %s to not equal %s",this.actual,t),this},r.prototype.toThrow=function(t,e){return u(i(this.actual),'The "actual" argument in expect(actual).toThrow() must be a function, %s was given',this.actual),u(c(this.actual,this.context,this.args,t),e||"Expected %s to throw %s",this.actual,t),this},r.prototype.toNotThrow=function(t,e){return u(i(this.actual),'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given',this.actual),u(!c(this.actual,this.context,this.args,t),e||"Expected %s to not throw %s",this.actual,t),this},r.prototype.toBeA=function(t,e){return u(i(t)||"string"==typeof t,'The "value" argument in toBeA(value) must be a function or a string'),u(p(this.actual,t),e||"Expected %s to be a %s",this.actual,t),this},r.prototype.toNotBeA=function(t,e){return u(i(t)||"string"==typeof t,'The "value" argument in toNotBeA(value) must be a function or a string'),u(!p(this.actual,t),e||"Expected %s to be a %s",this.actual,t),this},r.prototype.toMatch=function(t,e){return u("string"==typeof this.actual,'The "actual" argument in expect(actual).toMatch() must be a string'),u(a(t),'The "value" argument in toMatch(value) must be a RegExp'),u(t.test(this.actual),e||"Expected %s to match %s",this.actual,t),this},r.prototype.toNotMatch=function(t,e){return u("string"==typeof this.actual,'The "actual" argument in expect(actual).toNotMatch() must be a string'),u(a(t),'The "value" argument in toNotMatch(value) must be a RegExp'),u(!t.test(this.actual),e||"Expected %s to not match %s",this.actual,t),this},r.prototype.toBeLessThan=function(t,e){return u("number"==typeof this.actual,'The "actual" argument in expect(actual).toBeLessThan() must be a number'),u("number"==typeof t,'The "value" argument in toBeLessThan(value) must be a number'),u(this.actual<t,e||"Expected %s to be less than %s",this.actual,t),this},r.prototype.toBeGreaterThan=function(t,e){return u("number"==typeof this.actual,'The "actual" argument in expect(actual).toBeGreaterThan() must be a number'),u("number"==typeof t,'The "value" argument in toBeGreaterThan(value) must be a number'),u(this.actual>t,e||"Expected %s to be greater than %s",this.actual,t),this},r.prototype.toInclude=function(t,e,n){return u(f(this.actual)||"string"==typeof this.actual,'The "actual" argument in expect(actual).toInclude() must be an array or a string'),"string"==typeof e&&(n=e,e=null),n=n||"Expected %s to include %s",f(this.actual)?u(l(this.actual,t,e),n,this.actual,t):u(s(this.actual,t),n,this.actual,t),this},r.prototype.toExclude=function(t,e,n){return u(f(this.actual)||"string"==typeof this.actual,'The "actual" argument in expect(actual).toExclude() must be an array or a string'),"string"==typeof e&&(n=e,e=null),n=n||"Expected %s to exclude %s",f(this.actual)?u(!l(this.actual,t,e),n,this.actual,t):u(!s(this.actual,t),n,this.actual,t),this},r.prototype.toHaveBeenCalled=function(t){var e=this.actual;return u(e&&e.__isSpy,'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy'),u(e.calls.length>0,t||"spy was not called"),this},r.prototype.toHaveBeenCalledWith=function(){var t=this.actual;u(t&&t.__isSpy,'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy');var e=Array.prototype.slice.call(arguments,0);return u(t.calls.some(function(t){return o(t.arguments,e)}),"spy was never called with %s",e),this},r.prototype.toNotHaveBeenCalled=function(t){var e=this.actual;return u(e&&e.__isSpy,'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy'),u(0===e.calls.length,t||"spy was not supposed to be called"),this},r.prototype.withContext=function(t){return u(i(this.actual),'The "actual" argument in expect(actual).withContext() must be a function'),this.context=t,this},r.prototype.withArgs=function(){return u(i(this.actual),'The "actual" argument in expect(actual).withArgs() must be a function'),arguments.length&&(this.args=this.args.concat(Array.prototype.slice.call(arguments,0))),this};var h={toBeAn:"toBeA",toNotBeAn:"toNotBeA",toBeTruthy:"toExist",toBeFalsy:"toNotExist",toBeFewerThan:"toBeLessThan",toBeMoreThan:"toBeGreaterThan",toContain:"toInclude",toNotContain:"toExclude"};for(var y in h)r.prototype[y]=r.prototype[h[y]];t.exports=r},function(t,e){"use strict";function n(t,e,n){return null==n?-1!==t.indexOf(e):t.some(function(t){return n(t,e)!==!1})}t.exports=n},function(t,e,n){"use strict";function r(t,e,n,r){try{t.apply(e,n)}catch(u){if(null==r)return!0;if(a(r)&&u instanceof r)return!0;var i=u.message||u;if("string"==typeof i){if(o(r)&&r.test(u.message))return!0;if("string"==typeof r&&-1!==i.indexOf(r))return!0}}return!1}var o=n(4),a=n(1);t.exports=r},function(t,e,n){"use strict";function r(t,e){return o(e)?t instanceof e:"array"===e?Array.isArray(t):typeof t===e}var o=n(1);t.exports=r},function(t,e){"use strict";function n(t,e){return-1!==t.indexOf(e)}t.exports=n},function(t,e,n){function r(t){return null===t||void 0===t}function o(t){return t&&"object"==typeof t&&"number"==typeof t.length?"function"!=typeof t.copy||"function"!=typeof t.slice?!1:t.length>0&&"number"!=typeof t[0]?!1:!0:!1}function a(t,e,n){var a,l;if(r(t)||r(e))return!1;if(t.prototype!==e.prototype)return!1;if(c(t))return c(e)?(t=u.call(t),e=u.call(e),s(t,e,n)):!1;if(o(t)){if(!o(e))return!1;if(t.length!==e.length)return!1;for(a=0;a<t.length;a++)if(t[a]!==e[a])return!1;return!0}try{var p=i(t),f=i(e)}catch(h){return!1}if(p.length!=f.length)return!1;for(p.sort(),f.sort(),a=p.length-1;a>=0;a--)if(p[a]!=f[a])return!1;for(a=p.length-1;a>=0;a--)if(l=p[a],!s(t[l],e[l],n))return!1;return typeof t==typeof e}var u=Array.prototype.slice,i=n(12),c=n(11),s=t.exports=function(t,e,n){return n||(n={}),t===e?!0:t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():!t||!e||"object"!=typeof t&&"object"!=typeof e?n.strict?t===e:t==e:a(t,e,n)}},function(t,e){function n(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function r(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=o?n:r,e.supported=n,e.unsupported=r},function(t,e){function n(t){var e=[];for(var n in t)e.push(n);return e}e=t.exports="function"==typeof Object.keys?Object.keys:n,e.shim=n},function(t,e){function n(t){return String(t).replace(/"/g,""")}function r(t){return"[object Array]"===s(t)}function o(t){return"[object Date]"===s(t)}function a(t){return"[object RegExp]"===s(t)}function u(t){return"[object Error]"===s(t)}function i(t){return"[object Symbol]"===s(t)}function c(t,e){return y.call(t,e)}function s(t){return Object.prototype.toString.call(t)}function l(t){if(t.name)return t.name;var e=t.toString().match(/^function\s*([\w$]+)/);return e?e[1]:void 0}function p(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0,r=t.length;r>n;n++)if(t[n]===e)return n;return-1}function f(t){return t&&"object"==typeof t?"undefined"!=typeof HTMLElement&&t instanceof HTMLElement?!0:"string"==typeof t.nodeName&&"function"==typeof t.getAttribute:!1}function h(t){function e(t){var e=t.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[e];return n?"\\"+n:"\\x"+(16>e?"0":"")+e.toString(16)}var n=t.replace(/(['\\])/g,"\\$1").replace(/[\x00-\x1f]/g,e);return"'"+n+"'"}t.exports=function g(t,e,s,y){function m(t,n){return n&&(y=y.slice(),y.push(n)),g(t,e,s+1,y)}e||(e={});var x=void 0===e.depth?5:e.depth;if(void 0===s&&(s=0),s>=x&&x>0&&t&&"object"==typeof t)return"[Object]";if(void 0===y)y=[];else if(p(y,t)>=0)return"[Circular]";if("string"==typeof t)return h(t);if("function"==typeof t){var d=l(t);return"[Function"+(d?": "+d:"")+"]"}if(null===t)return"null";if(i(t)){var b=Symbol.prototype.toString.call(t);return"object"==typeof t?"Object("+b+")":b}if(f(t)){for(var v="<"+String(t.nodeName).toLowerCase(),T=t.attributes||[],j=0;j<T.length;j++)v+=" "+T[j].name+'="'+n(T[j].value)+'"';return v+=">",t.childNodes&&t.childNodes.length&&(v+="..."),v+="</"+String(t.nodeName).toLowerCase()+">"}if(r(t)){if(0===t.length)return"[]";for(var E=Array(t.length),j=0;j<t.length;j++)E[j]=c(t,j)?m(t[j],t):"";return"[ "+E.join(", ")+" ]"}if(u(t)){var w=[];for(var B in t)c(t,B)&&(/[^\w$]/.test(B)?w.push(m(B)+": "+m(t[B])):w.push(B+": "+m(t[B])));return 0===w.length?"["+t+"]":"{ ["+t+"] "+w.join(", ")+" }"}if("object"==typeof t&&"function"==typeof t.inspect)return t.inspect();if("object"!=typeof t||o(t)||a(t))return String(t);var E=[],A=[];for(var B in t)c(t,B)&&A.push(B);A.sort();for(var j=0;j<A.length;j++){var B=A[j];/[^\w$]/.test(B)?E.push(m(B)+": "+m(t[B],t)):E.push(B+": "+m(t[B],t))}return 0===E.length?"{}":"{ "+E.join(", ")+" }"};var y=Object.prototype.hasOwnProperty||function(t){return t in this}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.expect=e():t.expect=e()}(this,function(){return function(t){function e(u){if(n[u])return n[u].exports;var a=n[u]={exports:{},id:u,loaded:!1};return t[u].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function a(t){return new o["default"](t)}e.__esModule=!0;var r=n(5),o=u(r),i=n(2);a.createSpy=i.createSpy,a.spyOn=i.spyOn,a.isSpy=i.isSpy,e["default"]=a,t.exports=e["default"]},function(t,e){"use strict";function n(t){return"function"==typeof t}e.__esModule=!0,e["default"]=n,t.exports=e["default"]},function(t,e,n){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function a(){}function r(t){null==t&&(t=a),c["default"](f["default"](t),"createSpy needs a function");var e=void 0,n=void 0,u=void 0,r=function o(){if(o.calls.push({context:this,arguments:Array.prototype.slice.call(arguments,0)}),e)return e.apply(this,arguments);if(n)throw n;return u};return r.calls=[],r.andCall=function(t){return e=t,r},r.andCallThrough=function(){return r.andCall(t)},r.andThrow=function(t){return n=t,r},r.andReturn=function(t){return u=t,r},r.getLastCall=function(){return r.calls[r.calls.length-1]},r.__isSpy=!0,r}function o(t,e){var n=t[e];if(null==n||!n.__isSpy){var u=r(n);u.restore=u.destroy=function(){t[e]=n},t[e]=u}return t[e]}function i(t){return t&&t.__isSpy===!0}e.__esModule=!0,e.createSpy=r,e.spyOn=o,e.isSpy=i;var l=n(3),c=u(l),s=n(1),f=u(s)},function(t,e,n){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function a(t,e){if(!t){var n=Array.prototype.slice.call(arguments,2),u=0;throw new Error(e.replace(/%s/g,function(){return o["default"](n[u++])}))}}e.__esModule=!0;var r=n(13),o=u(r);e["default"]=a,t.exports=e["default"]},function(t,e){"use strict";t.exports=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)}},function(t,e,n){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}e.__esModule=!0;var r=n(10),o=u(r),i=n(4),l=u(i),c=n(3),s=u(c),f=n(1),p=u(f),h=n(7),d=u(h),y=n(9),g=u(y),m=n(6),x=u(m),b=n(2),v=n(8),T=u(v),_=Array.isArray,E=function(){function t(e){a(this,t),this.actual=e,p["default"](e)&&(this.context=null,this.args=[])}return t.prototype.toExist=function(t){return s["default"](this.actual,t||"Expected %s to exist",this.actual),this},t.prototype.toNotExist=function(t){return s["default"](!this.actual,t||"Expected %s to not exist",this.actual),this},t.prototype.toBe=function(t,e){return s["default"](this.actual===t,e||"Expected %s to be %s",this.actual,t),this},t.prototype.toNotBe=function(t,e){return s["default"](this.actual!==t,e||"Expected %s to not be %s",this.actual,t),this},t.prototype.toEqual=function(t,e){return s["default"](o["default"](this.actual,t),e||"Expected %s to equal %s",this.actual,t),this},t.prototype.toNotEqual=function(t,e){return s["default"](!o["default"](this.actual,t),e||"Expected %s to not equal %s",this.actual,t),this},t.prototype.toThrow=function(t,e){return s["default"](p["default"](this.actual),'The "actual" argument in expect(actual).toThrow() must be a function, %s was given',this.actual),s["default"](d["default"](this.actual,this.context,this.args,t),e||"Expected %s to throw %s",this.actual,t),this},t.prototype.toNotThrow=function(t,e){return s["default"](p["default"](this.actual),'The "actual" argument in expect(actual).toNotThrow() must be a function, %s was given',this.actual),s["default"](!d["default"](this.actual,this.context,this.args,t),e||"Expected %s to not throw %s",this.actual,t),this},t.prototype.toBeA=function(t,e){return s["default"](p["default"](t)||"string"==typeof t,'The "value" argument in toBeA(value) must be a function or a string'),s["default"](T["default"](this.actual,t),e||"Expected %s to be a %s",this.actual,t),this},t.prototype.toNotBeA=function(t,e){return s["default"](p["default"](t)||"string"==typeof t,'The "value" argument in toNotBeA(value) must be a function or a string'),s["default"](!T["default"](this.actual,t),e||"Expected %s to be a %s",this.actual,t),this},t.prototype.toMatch=function(t,e){return s["default"]("string"==typeof this.actual,'The "actual" argument in expect(actual).toMatch() must be a string'),s["default"](l["default"](t),'The "value" argument in toMatch(value) must be a RegExp'),s["default"](t.test(this.actual),e||"Expected %s to match %s",this.actual,t),this},t.prototype.toNotMatch=function(t,e){return s["default"]("string"==typeof this.actual,'The "actual" argument in expect(actual).toNotMatch() must be a string'),s["default"](l["default"](t),'The "value" argument in toNotMatch(value) must be a RegExp'),s["default"](!t.test(this.actual),e||"Expected %s to not match %s",this.actual,t),this},t.prototype.toBeLessThan=function(t,e){return s["default"]("number"==typeof this.actual,'The "actual" argument in expect(actual).toBeLessThan() must be a number'),s["default"]("number"==typeof t,'The "value" argument in toBeLessThan(value) must be a number'),s["default"](this.actual<t,e||"Expected %s to be less than %s",this.actual,t),this},t.prototype.toBeGreaterThan=function(t,e){return s["default"]("number"==typeof this.actual,'The "actual" argument in expect(actual).toBeGreaterThan() must be a number'),s["default"]("number"==typeof t,'The "value" argument in toBeGreaterThan(value) must be a number'),s["default"](this.actual>t,e||"Expected %s to be greater than %s",this.actual,t),this},t.prototype.toInclude=function(t,e,n){return s["default"](_(this.actual)||"string"==typeof this.actual,'The "actual" argument in expect(actual).toInclude() must be an array or a string'),"string"==typeof e&&(n=e,e=null),n=n||"Expected %s to include %s",_(this.actual)?s["default"](x["default"](this.actual,t,e),n,this.actual,t):s["default"](g["default"](this.actual,t),n,this.actual,t),this},t.prototype.toExclude=function(t,e,n){return s["default"](_(this.actual)||"string"==typeof this.actual,'The "actual" argument in expect(actual).toExclude() must be an array or a string'),"string"==typeof e&&(n=e,e=null),n=n||"Expected %s to exclude %s",_(this.actual)?s["default"](!x["default"](this.actual,t,e),n,this.actual,t):s["default"](!g["default"](this.actual,t),n,this.actual,t),this},t.prototype.toHaveBeenCalled=function(t){var e=this.actual;return s["default"](b.isSpy(e),'The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy'),s["default"](e.calls.length>0,t||"spy was not called"),this},t.prototype.toHaveBeenCalledWith=function(){var t=this.actual;s["default"](b.isSpy(t),'The "actual" argument in expect(actual).toHaveBeenCalledWith() must be a spy');var e=Array.prototype.slice.call(arguments,0);return s["default"](t.calls.some(function(t){return o["default"](t.arguments,e)}),"spy was never called with %s",e),this},t.prototype.toNotHaveBeenCalled=function(t){var e=this.actual;return s["default"](b.isSpy(e),'The "actual" argument in expect(actual).toNotHaveBeenCalled() must be a spy'),s["default"](0===e.calls.length,t||"spy was not supposed to be called"),this},t.prototype.withContext=function(t){return s["default"](p["default"](this.actual),'The "actual" argument in expect(actual).withContext() must be a function'),this.context=t,this},t.prototype.withArgs=function(){return s["default"](p["default"](this.actual),'The "actual" argument in expect(actual).withArgs() must be a function'),arguments.length&&(this.args=this.args.concat(Array.prototype.slice.call(arguments,0))),this},t}(),j={toBeAn:"toBeA",toNotBeAn:"toNotBeA",toBeTruthy:"toExist",toBeFalsy:"toNotExist",toBeFewerThan:"toBeLessThan",toBeMoreThan:"toBeGreaterThan",toContain:"toInclude",toNotContain:"toExclude"};for(var w in j)E.prototype[w]=E.prototype[j[w]];e["default"]=E,t.exports=e["default"]},function(t,e){"use strict";function n(t,e,n){return null==n?-1!==t.indexOf(e):t.some(function(t){return n(t,e)!==!1})}e.__esModule=!0,e["default"]=n,t.exports=e["default"]},function(t,e,n){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function a(t,e,n,u){try{t.apply(e,n)}catch(a){if(null==u)return!0;if(l["default"](u)&&a instanceof u)return!0;var r=a.message||a;if("string"==typeof r){if(o["default"](u)&&u.test(a.message))return!0;if("string"==typeof u&&-1!==r.indexOf(u))return!0}}return!1}e.__esModule=!0;var r=n(4),o=u(r),i=n(1),l=u(i);e["default"]=a,t.exports=e["default"]},function(t,e,n){"use strict";function u(t){return t&&t.__esModule?t:{"default":t}}function a(t,e){return o["default"](e)?t instanceof e:"array"===e?Array.isArray(t):typeof t===e}e.__esModule=!0;var r=n(1),o=u(r);e["default"]=a,t.exports=e["default"]},function(t,e){"use strict";function n(t,e){return-1!==t.indexOf(e)}e.__esModule=!0,e["default"]=n,t.exports=e["default"]},function(t,e,n){function u(t){return null===t||void 0===t}function a(t){return t&&"object"==typeof t&&"number"==typeof t.length?"function"!=typeof t.copy||"function"!=typeof t.slice?!1:t.length>0&&"number"!=typeof t[0]?!1:!0:!1}function r(t,e,n){var r,s;if(u(t)||u(e))return!1;if(t.prototype!==e.prototype)return!1;if(l(t))return l(e)?(t=o.call(t),e=o.call(e),c(t,e,n)):!1;if(a(t)){if(!a(e))return!1;if(t.length!==e.length)return!1;for(r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}try{var f=i(t),p=i(e)}catch(h){return!1}if(f.length!=p.length)return!1;for(f.sort(),p.sort(),r=f.length-1;r>=0;r--)if(f[r]!=p[r])return!1;for(r=f.length-1;r>=0;r--)if(s=f[r],!c(t[s],e[s],n))return!1;return typeof t==typeof e}var o=Array.prototype.slice,i=n(12),l=n(11),c=t.exports=function(t,e,n){return n||(n={}),t===e?!0:t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():!t||!e||"object"!=typeof t&&"object"!=typeof e?n.strict?t===e:t==e:r(t,e,n)}},function(t,e){function n(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function u(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var a="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=a?n:u,e.supported=n,e.unsupported=u},function(t,e){function n(t){var e=[];for(var n in t)e.push(n);return e}e=t.exports="function"==typeof Object.keys?Object.keys:n,e.shim=n},function(t,e){function n(t){return String(t).replace(/"/g,""")}function u(t){return"[object Array]"===c(t)}function a(t){return"[object Date]"===c(t)}function r(t){return"[object RegExp]"===c(t)}function o(t){return"[object Error]"===c(t)}function i(t){return"[object Symbol]"===c(t)}function l(t,e){return d.call(t,e)}function c(t){return Object.prototype.toString.call(t)}function s(t){if(t.name)return t.name;var e=t.toString().match(/^function\s*([\w$]+)/);return e?e[1]:void 0}function f(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0,u=t.length;u>n;n++)if(t[n]===e)return n;return-1}function p(t){return t&&"object"==typeof t?"undefined"!=typeof HTMLElement&&t instanceof HTMLElement?!0:"string"==typeof t.nodeName&&"function"==typeof t.getAttribute:!1}function h(t){function e(t){var e=t.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[e];return n?"\\"+n:"\\x"+(16>e?"0":"")+e.toString(16)}var n=t.replace(/(['\\])/g,"\\$1").replace(/[\x00-\x1f]/g,e);return"'"+n+"'"}t.exports=function y(t,e,c,d){function g(t,n){return n&&(d=d.slice(),d.push(n)),y(t,e,c+1,d)}e||(e={});var m=void 0===e.depth?5:e.depth;if(void 0===c&&(c=0),c>=m&&m>0&&t&&"object"==typeof t)return"[Object]";if(void 0===d)d=[];else if(f(d,t)>=0)return"[Circular]";if("string"==typeof t)return h(t);if("function"==typeof t){var x=s(t);return"[Function"+(x?": "+x:"")+"]"}if(null===t)return"null";if(i(t)){var b=Symbol.prototype.toString.call(t);return"object"==typeof t?"Object("+b+")":b}if(p(t)){for(var v="<"+String(t.nodeName).toLowerCase(),T=t.attributes||[],_=0;_<T.length;_++)v+=" "+T[_].name+'="'+n(T[_].value)+'"';return v+=">",t.childNodes&&t.childNodes.length&&(v+="..."),v+="</"+String(t.nodeName).toLowerCase()+">"}if(u(t)){if(0===t.length)return"[]";for(var E=Array(t.length),_=0;_<t.length;_++)E[_]=l(t,_)?g(t[_],t):"";return"[ "+E.join(", ")+" ]"}if(o(t)){var j=[];for(var w in t)l(t,w)&&(/[^\w$]/.test(w)?j.push(g(w)+": "+g(t[w])):j.push(w+": "+g(t[w])));return 0===j.length?"["+t+"]":"{ ["+t+"] "+j.join(", ")+" }"}if("object"==typeof t&&"function"==typeof t.inspect)return t.inspect();if("object"!=typeof t||a(t)||r(t))return String(t);var E=[],B=[];for(var w in t)l(t,w)&&B.push(w);B.sort();for(var _=0;_<B.length;_++){var w=B[_];/[^\w$]/.test(w)?E.push(g(w)+": "+g(t[w],t)):E.push(w+": "+g(t[w],t))}return 0===E.length?"{}":"{ "+E.join(", ")+" }"};var d=Object.prototype.hasOwnProperty||function(t){return t in this}}])}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
255
0
77065
25
1504