UNPKG

ember-introjs

Version:
1,612 lines (1,310 loc) 2.25 MB
/* Sinon.JS 3.3.0, 2017-09-18, @license BSD-3 */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.sinon = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ "use strict"; exports.assert = require("./sinon/assert"); exports.collection = require("./sinon/collection"); exports.match = require("./sinon/match"); exports.spy = require("./sinon/spy"); exports.spyCall = require("./sinon/call"); exports.stub = require("./sinon/stub"); exports.mock = require("./sinon/mock"); var sandbox = require("./sinon/sandbox"); exports.sandbox = sandbox; exports.expectation = require("./sinon/mock-expectation"); exports.createStubInstance = require("./sinon/stub").createStubInstance; exports.defaultConfig = require("./sinon/util/core/default-config"); var fakeTimers = require("./sinon/util/fake_timers"); exports.useFakeTimers = fakeTimers.useFakeTimers; exports.clock = fakeTimers.clock; exports.timers = fakeTimers.timers; var nise = require("nise"); exports.xhr = nise.fakeXhr.xhr; exports.FakeXMLHttpRequest = nise.fakeXhr.FakeXMLHttpRequest; exports.useFakeXMLHttpRequest = nise.fakeXhr.useFakeXMLHttpRequest; exports.fakeServer = nise.fakeServer; exports.fakeServerWithClock = nise.fakeServerWithClock; exports.createSandbox = sandbox.create; exports.createFakeServer = nise.fakeServer.create.bind(nise.fakeServer); exports.createFakeServerWithClock = nise.fakeServerWithClock.create.bind(nise.fakeServerWithClock); var behavior = require("./sinon/behavior"); exports.addBehavior = function (name, fn) { behavior.addBehavior(exports.stub, name, fn); }; var format = require("./sinon/util/core/format"); exports.setFormatter = format.setFormatter; },{"./sinon/assert":2,"./sinon/behavior":3,"./sinon/call":4,"./sinon/collection":6,"./sinon/match":9,"./sinon/mock":11,"./sinon/mock-expectation":10,"./sinon/sandbox":12,"./sinon/spy":14,"./sinon/stub":16,"./sinon/util/core/default-config":20,"./sinon/util/core/format":23,"./sinon/util/fake_timers":34,"nise":52}],2:[function(require,module,exports){ (function (global){ "use strict"; var calledInOrder = require("./util/core/called-in-order"); var orderByFirstCall = require("./util/core/order-by-first-call"); var timesInWords = require("./util/core/times-in-words"); var format = require("./util/core/format"); var sinonMatch = require("./match"); var slice = Array.prototype.slice; var assert; function verifyIsStub() { var args = Array.prototype.slice.call(arguments); args.forEach(function (method) { if (!method) { assert.fail("fake is not a spy"); } if (method.proxy && method.proxy.isSinonProxy) { verifyIsStub(method.proxy); } else { if (typeof method !== "function") { assert.fail(method + " is not a function"); } if (typeof method.getCall !== "function") { assert.fail(method + " is not stubbed"); } } }); } function verifyIsValidAssertion(assertionMethod, assertionArgs) { switch (assertionMethod) { case "notCalled": case "called": case "calledOnce": case "calledTwice": case "calledThrice": if (assertionArgs.length !== 0) { assert.fail(assertionMethod + " takes 1 argument but was called with " + (assertionArgs.length + 1) + " arguments"); } break; default: break; } } function failAssertion(object, msg) { object = object || global; var failMethod = object.fail || assert.fail; failMethod.call(object, msg); } function mirrorPropAsAssertion(name, method, message) { if (arguments.length === 2) { message = method; method = name; } assert[name] = function (fake) { verifyIsStub(fake); var args = slice.call(arguments, 1); var failed = false; verifyIsValidAssertion(name, args); if (typeof method === "function") { failed = !method(fake); } else { failed = typeof fake[method] === "function" ? !fake[method].apply(fake, args) : !fake[method]; } if (failed) { failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, [message].concat(args))); } else { assert.pass(name); } }; } function exposedName(prefix, prop) { return !prefix || /^fail/.test(prop) ? prop : prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1); } assert = { failException: "AssertError", fail: function fail(message) { var error = new Error(message); error.name = this.failException || assert.failException; throw error; }, pass: function pass() {}, callOrder: function assertCallOrder() { verifyIsStub.apply(null, arguments); var expected = ""; var actual = ""; if (!calledInOrder(arguments)) { try { expected = [].join.call(arguments, ", "); var calls = slice.call(arguments); var i = calls.length; while (i) { if (!calls[--i].called) { calls.splice(i, 1); } } actual = orderByFirstCall(calls).join(", "); } catch (e) { // If this fails, we'll just fall back to the blank string } failAssertion(this, "expected " + expected + " to be " + "called in order but were called as " + actual); } else { assert.pass("callOrder"); } }, callCount: function assertCallCount(method, count) { verifyIsStub(method); if (method.callCount !== count) { var msg = "expected %n to be called " + timesInWords(count) + " but was called %c%C"; failAssertion(this, method.printf(msg)); } else { assert.pass("callCount"); } }, expose: function expose(target, options) { if (!target) { throw new TypeError("target is null or undefined"); } var o = options || {}; var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix; var includeFail = typeof o.includeFail === "undefined" || !!o.includeFail; var instance = this; Object.keys(instance).forEach(function (method) { if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) { target[exposedName(prefix, method)] = instance[method]; } }); return target; }, match: function match(actual, expectation) { var matcher = sinonMatch(expectation); if (matcher.test(actual)) { assert.pass("match"); } else { var formatted = [ "expected value to match", " expected = " + format(expectation), " actual = " + format(actual) ]; failAssertion(this, formatted.join("\n")); } } }; mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); mirrorPropAsAssertion("notCalled", function (spy) { return !spy.called; }, "expected %n to not have been called but was called %c%C"); mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); mirrorPropAsAssertion( "alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t" ); mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %D"); mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %D"); mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %D"); mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %D"); mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %D"); mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %D"); mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C"); mirrorPropAsAssertion("threw", "%n did not throw exception%C"); mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C"); module.exports = assert; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./match":9,"./util/core/called-in-order":18,"./util/core/format":23,"./util/core/order-by-first-call":28,"./util/core/times-in-words":29}],3:[function(require,module,exports){ (function (process){ "use strict"; var extend = require("./util/core/extend"); var functionName = require("./util/core/function-name"); var valueToString = require("./util/core/value-to-string"); var slice = Array.prototype.slice; var join = Array.prototype.join; var useLeftMostCallback = -1; var useRightMostCallback = -2; var nextTick = (function () { if (typeof process === "object" && typeof process.nextTick === "function") { return process.nextTick; } if (typeof setImmediate === "function") { return setImmediate; } return function (callback) { setTimeout(callback, 0); }; })(); function getCallback(behavior, args) { var callArgAt = behavior.callArgAt; if (callArgAt >= 0) { return args[callArgAt]; } var argumentList; if (callArgAt === useLeftMostCallback) { argumentList = args; } if (callArgAt === useRightMostCallback) { argumentList = slice.call(args).reverse(); } var callArgProp = behavior.callArgProp; for (var i = 0, l = argumentList.length; i < l; ++i) { if (!callArgProp && typeof argumentList[i] === "function") { return argumentList[i]; } if (callArgProp && argumentList[i] && typeof argumentList[i][callArgProp] === "function") { return argumentList[i][callArgProp]; } } return null; } function getCallbackError(behavior, func, args) { if (behavior.callArgAt < 0) { var msg; if (behavior.callArgProp) { msg = functionName(behavior.stub) + " expected to yield to '" + valueToString(behavior.callArgProp) + "', but no object with such a property was passed."; } else { msg = functionName(behavior.stub) + " expected to yield, but no callback was passed."; } if (args.length > 0) { msg += " Received [" + join.call(args, ", ") + "]"; } return msg; } return "argument at index " + behavior.callArgAt + " is not a function: " + func; } function callCallback(behavior, args) { if (typeof behavior.callArgAt === "number") { var func = getCallback(behavior, args); if (typeof func !== "function") { throw new TypeError(getCallbackError(behavior, func, args)); } if (behavior.callbackAsync) { nextTick(function () { func.apply(behavior.callbackContext, behavior.callbackArguments); }); } else { func.apply(behavior.callbackContext, behavior.callbackArguments); } } } var proto = { create: function create(stub) { var behavior = extend({}, proto); delete behavior.create; delete behavior.addBehavior; delete behavior.createBehavior; behavior.stub = stub; if (stub.defaultBehavior && stub.defaultBehavior.promiseLibrary) { behavior.promiseLibrary = stub.defaultBehavior.promiseLibrary; } return behavior; }, isPresent: function isPresent() { return (typeof this.callArgAt === "number" || this.exception || this.exceptionCreator || typeof this.returnArgAt === "number" || this.returnThis || this.resolveThis || typeof this.throwArgAt === "number" || this.fakeFn || this.returnValueDefined); }, invoke: function invoke(context, args) { callCallback(this, args); if (this.exception) { throw this.exception; } else if (this.exceptionCreator) { this.exception = this.exceptionCreator(); this.exceptionCreator = undefined; throw this.exception; } else if (typeof this.returnArgAt === "number") { return args[this.returnArgAt]; } else if (this.returnThis) { return context; } else if (typeof this.throwArgAt === "number") { if (args.length < this.throwArgAt) { throw new TypeError( "throwArgs failed: " + this.throwArgAt + " arguments required but only " + args.length + " present" ); } throw args[this.throwArgAt]; } else if (this.fakeFn) { return this.fakeFn.apply(context, args); } else if (this.resolveThis) { return (this.promiseLibrary || Promise).resolve(context); } else if (this.resolve) { return (this.promiseLibrary || Promise).resolve(this.returnValue); } else if (this.reject) { return (this.promiseLibrary || Promise).reject(this.returnValue); } else if (this.callsThrough) { return this.stub.wrappedMethod.apply(context, args); } return this.returnValue; }, onCall: function onCall(index) { return this.stub.onCall(index); }, onFirstCall: function onFirstCall() { return this.stub.onFirstCall(); }, onSecondCall: function onSecondCall() { return this.stub.onSecondCall(); }, onThirdCall: function onThirdCall() { return this.stub.onThirdCall(); }, withArgs: function withArgs(/* arguments */) { throw new Error( "Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" " + "is not supported. Use \"stub.withArgs(...).onCall(...)\" " + "to define sequential behavior for calls with certain arguments." ); } }; function createAsyncVersion(syncFnName) { return function () { var result = this[syncFnName].apply(this, arguments); this.callbackAsync = true; return result; }; } // create asynchronous versions of callsArg* and yields* methods Object.keys(proto).forEach(function (method) { // need to avoid creating anotherasync versions of the newly added async methods if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) { proto[method + "Async"] = createAsyncVersion(method); } }); function createBehavior(behaviorMethod) { return function () { this.defaultBehavior = this.defaultBehavior || proto.create(this); this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments); return this; }; } function addBehavior(stub, name, fn) { proto[name] = function () { fn.apply(this, [this].concat([].slice.call(arguments))); return this.stub || this; }; stub[name] = createBehavior(name); } proto.addBehavior = addBehavior; proto.createBehavior = createBehavior; module.exports = proto; }).call(this,require('_process')) },{"./util/core/extend":22,"./util/core/function-name":24,"./util/core/value-to-string":31,"_process":35}],4:[function(require,module,exports){ "use strict"; var sinonMatch = require("./match"); var deepEqual = require("./util/core/deep-equal").use(sinonMatch); var functionName = require("./util/core/function-name"); var sinonFormat = require("./util/core/format"); var valueToString = require("./util/core/value-to-string"); var slice = Array.prototype.slice; var filter = Array.prototype.filter; function throwYieldError(proxy, text, args) { var msg = functionName(proxy) + text; if (args.length) { msg += " Received [" + slice.call(args).join(", ") + "]"; } throw new Error(msg); } var callProto = { calledOn: function calledOn(thisValue) { if (sinonMatch && sinonMatch.isMatcher(thisValue)) { return thisValue.test(this.thisValue); } return this.thisValue === thisValue; }, calledWith: function calledWith() { var self = this; var calledWithArgs = slice.call(arguments); if (calledWithArgs.length > self.args.length) { return false; } return calledWithArgs.reduce(function (prev, arg, i) { return prev && deepEqual(arg, self.args[i]); }, true); }, calledWithMatch: function calledWithMatch() { var self = this; var calledWithMatchArgs = slice.call(arguments); if (calledWithMatchArgs.length > self.args.length) { return false; } return calledWithMatchArgs.reduce(function (prev, expectation, i) { var actual = self.args[i]; return prev && (sinonMatch && sinonMatch(expectation).test(actual)); }, true); }, calledWithExactly: function calledWithExactly() { return arguments.length === this.args.length && this.calledWith.apply(this, arguments); }, notCalledWith: function notCalledWith() { return !this.calledWith.apply(this, arguments); }, notCalledWithMatch: function notCalledWithMatch() { return !this.calledWithMatch.apply(this, arguments); }, returned: function returned(value) { return deepEqual(value, this.returnValue); }, threw: function threw(error) { if (typeof error === "undefined" || !this.exception) { return !!this.exception; } return this.exception === error || this.exception.name === error; }, calledWithNew: function calledWithNew() { return this.proxy.prototype && this.thisValue instanceof this.proxy; }, calledBefore: function (other) { return this.callId < other.callId; }, calledAfter: function (other) { return this.callId > other.callId; }, calledImmediatelyBefore: function (other) { return this.callId === other.callId - 1; }, calledImmediatelyAfter: function (other) { return this.callId === other.callId + 1; }, callArg: function (pos) { this.args[pos](); }, callArgOn: function (pos, thisValue) { this.args[pos].apply(thisValue); }, callArgWith: function (pos) { this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1))); }, callArgOnWith: function (pos, thisValue) { var args = slice.call(arguments, 2); this.args[pos].apply(thisValue, args); }, throwArg: function (pos) { if (pos > this.args.length) { throw new TypeError( "Not enough arguments: " + pos + " required but only " + this.args.length + " present" ); } throw this.args[pos]; }, "yield": function () { this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0))); }, yieldOn: function (thisValue) { var args = slice.call(this.args); var yieldFn = filter.call(args, function (arg) { return typeof arg === "function"; })[0]; if (!yieldFn) { throwYieldError(this.proxy, " cannot yield since no callback was passed.", args); } yieldFn.apply(thisValue, slice.call(arguments, 1)); }, yieldTo: function (prop) { this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1))); }, yieldToOn: function (prop, thisValue) { var args = slice.call(this.args); var yieldArg = filter.call(args, function (arg) { return arg && typeof arg[prop] === "function"; })[0]; var yieldFn = yieldArg && yieldArg[prop]; if (!yieldFn) { throwYieldError(this.proxy, " cannot yield to '" + valueToString(prop) + "' since no callback was passed.", args); } yieldFn.apply(thisValue, slice.call(arguments, 2)); }, toString: function () { var callStr = this.proxy ? this.proxy.toString() + "(" : ""; var formattedArgs; if (!this.args) { return ":("; } formattedArgs = slice.call(this.args).map(function (arg) { return sinonFormat(arg); }); callStr = callStr + formattedArgs.join(", ") + ")"; if (typeof this.returnValue !== "undefined") { callStr += " => " + sinonFormat(this.returnValue); } if (this.exception) { callStr += " !" + this.exception.name; if (this.exception.message) { callStr += "(" + this.exception.message + ")"; } } if (this.stack) { // Omit the error message and the two top stack frames in sinon itself: callStr += ( this.stack.split("\n")[3] || "unknown" ).replace(/^\s*(?:at\s+|@)?/, " at "); } return callStr; } }; Object.defineProperty(callProto, "stack", { enumerable: true, configurable: true, get: function () { return this.errorWithCallStack && this.errorWithCallStack.stack || ""; } }); callProto.invokeCallback = callProto.yield; function createSpyCall(spy, thisValue, args, returnValue, exception, id, errorWithCallStack) { if (typeof id !== "number") { throw new TypeError("Call id is not a number"); } var proxyCall = Object.create(callProto); proxyCall.proxy = spy; proxyCall.thisValue = thisValue; proxyCall.args = args; proxyCall.returnValue = returnValue; proxyCall.exception = exception; proxyCall.callId = id; proxyCall.errorWithCallStack = errorWithCallStack; return proxyCall; } createSpyCall.toString = callProto.toString; // used by mocks module.exports = createSpyCall; },{"./match":9,"./util/core/deep-equal":19,"./util/core/format":23,"./util/core/function-name":24,"./util/core/value-to-string":31}],5:[function(require,module,exports){ "use strict"; var walk = require("./util/core/walk"); var getPropertyDescriptor = require("./util/core/get-property-descriptor"); function collectMethod(methods, object, prop, propOwner) { if ( typeof getPropertyDescriptor(propOwner, prop).value === "function" && object.hasOwnProperty(prop) ) { methods.push(object[prop]); } } // This function returns an array of all the own methods on the passed object function collectOwnMethods(object) { var methods = []; walk(object, collectMethod.bind(null, methods, object)); return methods; } module.exports = collectOwnMethods; },{"./util/core/get-property-descriptor":26,"./util/core/walk":32}],6:[function(require,module,exports){ "use strict"; var sinonSpy = require("./spy"); var sinonStub = require("./stub"); var sinonMock = require("./mock"); var collectOwnMethods = require("./collect-own-methods"); var valueToString = require("./util/core/value-to-string"); var push = Array.prototype.push; var filter = Array.prototype.filter; function getFakes(fakeCollection) { if (!fakeCollection.fakes) { fakeCollection.fakes = []; } return fakeCollection.fakes; } function each(fakeCollection, method) { var fakes = getFakes(fakeCollection); var matchingFakes = filter.call(fakes, function (fake) { return typeof fake[method] === "function"; }); matchingFakes.forEach(function (fake) { fake[method](); }); } var collection = { verify: function verify() { each(this, "verify"); }, restore: function restore() { each(this, "restore"); this.fakes = []; }, reset: function reset() { each(this, "reset"); }, resetBehavior: function resetBehavior() { each(this, "resetBehavior"); }, resetHistory: function resetHistory() { getFakes(this).forEach(function (fake) { var method = fake.resetHistory || fake.reset; if (method) { method.call(fake); } }); }, verifyAndRestore: function verifyAndRestore() { var exception; try { this.verify(); } catch (e) { exception = e; } this.restore(); if (exception) { throw exception; } }, add: function add(fake) { push.call(getFakes(this), fake); return fake; }, addUsingPromise: function (fake) { fake.usingPromise(this.promiseLibrary); return fake; }, spy: function spy() { return this.add(sinonSpy.apply(sinonSpy, arguments)); }, stub: function stub(object, property) { if (object && typeof property !== "undefined" && !(property in object)) { throw new TypeError("Cannot stub non-existent own property " + valueToString(property)); } var stubbed = sinonStub.apply(null, arguments); var isStubbingEntireObject = typeof property === "undefined" && typeof object === "object"; if (isStubbingEntireObject) { var ownMethods = collectOwnMethods(stubbed); ownMethods.forEach(this.add.bind(this)); if (this.promiseLibrary) { ownMethods.forEach(this.addUsingPromise.bind(this)); } } else { this.add(stubbed); if (this.promiseLibrary) { stubbed.usingPromise(this.promiseLibrary); } } return stubbed; }, mock: function mock() { return this.add(sinonMock.apply(null, arguments)); }, inject: function inject(obj) { var col = this; obj.spy = function () { return col.spy.apply(col, arguments); }; obj.stub = function () { return col.stub.apply(col, arguments); }; obj.mock = function () { return col.mock.apply(col, arguments); }; return obj; } }; module.exports = collection; },{"./collect-own-methods":5,"./mock":11,"./spy":14,"./stub":16,"./util/core/value-to-string":31}],7:[function(require,module,exports){ (function (process){ "use strict"; var canColor = typeof process !== "undefined"; function colorize(str, color) { if (!canColor) { return str; } return "\x1b[" + color + "m" + str + "\x1b[0m"; } exports.red = function (str) { return colorize(str, 31); }; exports.green = function (str) { return colorize(str, 32); }; }).call(this,require('_process')) },{"_process":35}],8:[function(require,module,exports){ "use strict"; var getPropertyDescriptor = require("./util/core/get-property-descriptor"); var slice = [].slice; var useLeftMostCallback = -1; var useRightMostCallback = -2; function throwsException(fake, error, message) { if (typeof error === "function") { fake.exceptionCreator = error; } else if (typeof error === "string") { fake.exceptionCreator = function () { var newException = new Error(message || ""); newException.name = error; return newException; }; } else if (!error) { fake.exceptionCreator = function () { return new Error("Error"); }; } else { fake.exception = error; } } function isPropertyConfigurable(obj, propName) { var propertyDescriptor = getPropertyDescriptor(obj, propName); return propertyDescriptor ? propertyDescriptor.configurable : true; } module.exports = { callsFake: function callsFake(fake, fn) { fake.fakeFn = fn; }, callsArg: function callsArg(fake, pos) { if (typeof pos !== "number") { throw new TypeError("argument index is not number"); } fake.callArgAt = pos; fake.callbackArguments = []; fake.callbackContext = undefined; fake.callArgProp = undefined; fake.callbackAsync = false; }, callsArgOn: function callsArgOn(fake, pos, context) { if (typeof pos !== "number") { throw new TypeError("argument index is not number"); } fake.callArgAt = pos; fake.callbackArguments = []; fake.callbackContext = context; fake.callArgProp = undefined; fake.callbackAsync = false; }, callsArgWith: function callsArgWith(fake, pos) { if (typeof pos !== "number") { throw new TypeError("argument index is not number"); } fake.callArgAt = pos; fake.callbackArguments = slice.call(arguments, 2); fake.callbackContext = undefined; fake.callArgProp = undefined; fake.callbackAsync = false; }, callsArgOnWith: function callsArgWith(fake, pos, context) { if (typeof pos !== "number") { throw new TypeError("argument index is not number"); } fake.callArgAt = pos; fake.callbackArguments = slice.call(arguments, 3); fake.callbackContext = context; fake.callArgProp = undefined; fake.callbackAsync = false; }, usingPromise: function usingPromise(fake, promiseLibrary) { fake.promiseLibrary = promiseLibrary; }, yields: function (fake) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice.call(arguments, 1); fake.callbackContext = undefined; fake.callArgProp = undefined; fake.callbackAsync = false; }, yieldsRight: function (fake) { fake.callArgAt = useRightMostCallback; fake.callbackArguments = slice.call(arguments, 1); fake.callbackContext = undefined; fake.callArgProp = undefined; fake.callbackAsync = false; }, yieldsOn: function (fake, context) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice.call(arguments, 2); fake.callbackContext = context; fake.callArgProp = undefined; fake.callbackAsync = false; }, yieldsTo: function (fake, prop) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice.call(arguments, 2); fake.callbackContext = undefined; fake.callArgProp = prop; fake.callbackAsync = false; }, yieldsToOn: function (fake, prop, context) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice.call(arguments, 3); fake.callbackContext = context; fake.callArgProp = prop; fake.callbackAsync = false; }, throws: throwsException, throwsException: throwsException, returns: function returns(fake, value) { fake.returnValue = value; fake.resolve = false; fake.reject = false; fake.returnValueDefined = true; fake.exception = undefined; fake.exceptionCreator = undefined; fake.fakeFn = undefined; }, returnsArg: function returnsArg(fake, pos) { if (typeof pos !== "number") { throw new TypeError("argument index is not number"); } fake.returnArgAt = pos; }, throwsArg: function throwsArg(fake, pos) { if (typeof pos !== "number") { throw new TypeError("argument index is not number"); } fake.throwArgAt = pos; }, returnsThis: function returnsThis(fake) { fake.returnThis = true; }, resolves: function resolves(fake, value) { fake.returnValue = value; fake.resolve = true; fake.resolveThis = false; fake.reject = false; fake.returnValueDefined = true; fake.exception = undefined; fake.exceptionCreator = undefined; fake.fakeFn = undefined; }, rejects: function rejects(fake, error, message) { var reason; if (typeof error === "string") { reason = new Error(message || ""); reason.name = error; } else if (!error) { reason = new Error("Error"); } else { reason = error; } fake.returnValue = reason; fake.resolve = false; fake.resolveThis = false; fake.reject = true; fake.returnValueDefined = true; fake.exception = undefined; fake.exceptionCreator = undefined; fake.fakeFn = undefined; return fake; }, resolvesThis: function resolvesThis(fake) { fake.returnValue = undefined; fake.resolve = false; fake.resolveThis = true; fake.reject = false; fake.returnValueDefined = false; fake.exception = undefined; fake.exceptionCreator = undefined; fake.fakeFn = undefined; }, callThrough: function callThrough(fake) { fake.callsThrough = true; }, get: function get(fake, getterFunction) { var rootStub = fake.stub || fake; Object.defineProperty(rootStub.rootObj, rootStub.propName, { get: getterFunction, configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName) }); return fake; }, set: function set(fake, setterFunction) { var rootStub = fake.stub || fake; Object.defineProperty(rootStub.rootObj, rootStub.propName, { // eslint-disable-line accessor-pairs set: setterFunction, configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName) }); return fake; }, value: function value(fake, newVal) { var rootStub = fake.stub || fake; Object.defineProperty(rootStub.rootObj, rootStub.propName, { value: newVal, enumerable: true, configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName) }); return fake; } }; function createAsyncVersion(syncFnName) { return function () { var result = module.exports[syncFnName].apply(this, arguments); this.callbackAsync = true; return result; }; } // create asynchronous versions of callsArg* and yields* methods Object.keys(module.exports).forEach(function (method) { // need to avoid creating anotherasync versions of the newly added async methods if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) { module.exports[method + "Async"] = createAsyncVersion(method); } }); },{"./util/core/get-property-descriptor":26}],9:[function(require,module,exports){ "use strict"; var deepEqual = require("./util/core/deep-equal").use(match); // eslint-disable-line no-use-before-define var every = require("./util/core/every"); var functionName = require("./util/core/function-name"); var get = require("lodash.get"); var iterableToString = require("./util/core/iterable-to-string"); var typeOf = require("./util/core/typeOf"); var valueToString = require("./util/core/value-to-string"); var indexOf = Array.prototype.indexOf; function assertType(value, type, name) { var actual = typeOf(value); if (actual !== type) { throw new TypeError("Expected type of " + name + " to be " + type + ", but was " + actual); } } function assertMethodExists(value, method, name, methodPath) { if (value[method] == null) { throw new TypeError("Expected " + name + " to have method " + methodPath); } } var matcher = { toString: function () { return this.message; } }; function isMatcher(object) { return matcher.isPrototypeOf(object); } function matchObject(expectation, actual) { if (actual === null || actual === undefined) { return false; } return Object.keys(expectation).every(function (key) { var exp = expectation[key]; var act = actual[key]; if (isMatcher(exp)) { if (!exp.test(act)) { return false; } } else if (typeOf(exp) === "object") { if (!matchObject(exp, act)) { return false; } } else if (!deepEqual(exp, act)) { return false; } return true; }); } var TYPE_MAP = { "function": function (m, expectation, message) { m.test = expectation; m.message = message || "match(" + functionName(expectation) + ")"; }, number: function (m, expectation) { m.test = function (actual) { // we need type coercion here return expectation == actual; // eslint-disable-line eqeqeq }; }, object: function (m, expectation) { var array = []; if (typeof expectation.test === "function") { m.test = function (actual) { return expectation.test(actual) === true; }; m.message = "match(" + functionName(expectation.test) + ")"; return m; } array = Object.keys(expectation).map(function (key) { return key + ": " + valueToString(expectation[key]); }); m.test = function (actual) { return matchObject(expectation, actual); }; m.message = "match(" + array.join(", ") + ")"; return m; }, regexp: function (m, expectation) { m.test = function (actual) { return typeof actual === "string" && expectation.test(actual); }; }, string: function (m, expectation) { m.test = function (actual) { return typeof actual === "string" && actual.indexOf(expectation) !== -1; }; m.message = "match(\"" + expectation + "\")"; } }; function match(expectation, message) { var m = Object.create(matcher); var type = typeOf(expectation); if (type in TYPE_MAP) { TYPE_MAP[type](m, expectation, message); } else { m.test = function (actual) { return deepEqual(expectation, actual); }; } if (!m.message) { m.message = "match(" + valueToString(expectation) + ")"; } return m; } matcher.or = function (m2) { if (!arguments.length) { throw new TypeError("Matcher expected"); } else if (!isMatcher(m2)) { m2 = match(m2); } var m1 = this; var or = Object.create(matcher); or.test = function (actual) { return m1.test(actual) || m2.test(actual); }; or.message = m1.message + ".or(" + m2.message + ")"; return or; }; matcher.and = function (m2) { if (!arguments.length) { throw new TypeError("Matcher expected"); } else if (!isMatcher(m2)) { m2 = match(m2); } var m1 = this; var and = Object.create(matcher); and.test = function (actual) { return m1.test(actual) && m2.test(actual); }; and.message = m1.message + ".and(" + m2.message + ")"; return and; }; match.isMatcher = isMatcher; match.any = match(function () { return true; }, "any"); match.defined = match(function (actual) { return actual !== null && actual !== undefined; }, "defined"); match.truthy = match(function (actual) { return !!actual; }, "truthy"); match.falsy = match(function (actual) { return !actual; }, "falsy"); match.same = function (expectation) { return match(function (actual) { return expectation === actual; }, "same(" + valueToString(expectation) + ")"); }; match.typeOf = function (type) { assertType(type, "string", "type"); return match(function (actual) { return typeOf(actual) === type; }, "typeOf(\"" + type + "\")"); }; match.instanceOf = function (type) { if (typeof Symbol === "undefined" || typeof Symbol.hasInstance === "undefined") { assertType(type, "function", "type"); } else { assertMethodExists(type, Symbol.hasInstance, "type", "[Symbol.hasInstance]"); } return match(function (actual) { return actual instanceof type; }, "instanceOf(" + (functionName(type) || Object.prototype.toString.call(type)) + ")"); }; function createPropertyMatcher(propertyTest, messagePrefix) { return function (property, value) { assertType(property, "string", "property"); var onlyProperty = arguments.length === 1; var message = messagePrefix + "(\"" + property + "\""; if (!onlyProperty) { message += ", " + valueToString(value); } message += ")"; return match(function (actual) { if (actual === undefined || actual === null || !propertyTest(actual, property)) { return false; } return onlyProperty || deepEqual(value, actual[property]); }, message); }; } match.has = createPropertyMatcher(function (actual, property) { if (typeof actual === "object") { return property in actual; } return actual[property] !== undefined; }, "has"); match.hasOwn = createPropertyMatcher(function (actual, property) { return actual.hasOwnProperty(property); }, "hasOwn"); match.hasNested = function (property, value) { assertType(property, "string", "property"); var onlyProperty = arguments.length === 1; var message = "hasNested(\"" + property + "\""; if (!onlyProperty) { message += ", " + valueToString(value); } message += ")"; return match(function (actual) { if (actual === undefined || actual === null || get(actual, property) === undefined) { return false; } return onlyProperty || deepEqual(value, get(actual, property)); }, message); }; match.array = match.typeOf("array"); match.array.deepEquals = function (expectation) { return match(function (actual) { // Comparing lengths is the fastest way to spot a difference before iterating through every item var sameLength = actual.length === expectation.length; return typeOf(actual) === "array" && sameLength && every(actual, function (element, index) { return expectation[index] === element; }); }, "deepEquals([" + iterableToString(expectation) + "])"); }; match.array.startsWith = function (expectation) { return match(function (actual) { return typeOf(actual) === "array" && every(expectation, function (expectedElement, index) { return actual[index] === expectedElement; }); }, "startsWith([" + iterableToString(expectation) + "])"); }; match.array.endsWith = function (expectation) { return match(function (actual) { // This indicates the index in which we should start matching var offset = actual.length - expectation.length; return typeOf(actual) === "array" && every(expectation, function (expectedElement, index) { return actual[offset + index] === expectedElement; }); }, "endsWith([" + iterableToString(expectation) + "])"); }; match.array.contains = function (expectation) { return match(function (actual) { return typeOf(actual) === "array" && every(expectation, function (expectedElement) { return indexOf.call(actual, expectedElement) !== -1; }); }, "contains([" + iterableToString(expectation) + "])"); }; match.map = match.typeOf("map"); match.map.deepEquals = function mapDeepEquals(expectation) { return match(function (actual) { // Comparing lengths is the fastest way to spot a difference before iterating through every item var sameLength = actual.size === expectation.size; return typeOf(actual) === "map" && sameLength && every(actual, function (element, key) { return expectation.has(key) && expectation.get(key) === element; }); }, "deepEquals(Map[" + iterableToString(expectation) + "])"); }; match.map.contains = function mapContains(expectation) { return match(function (actual) { return typeOf(actual) === "map" && every(expectation, function (element, key) { return actual.has(key) && actual.get(key) === element; }); }, "contains(Map[" + iterableToString(expectation) + "])"); }; match.set = match.typeOf("set"); match.set.deepEquals = function setDeepEquals(expectation) { return match(function (actual) { // Comparing lengths is the fastest way to spot a difference before iterating through every item var sameLength = actual.size === expectation.size; return typeOf(actual) === "set" && sameLength && every(actual, function (element) { return expectation.has(element); }); }, "deepEquals(Set[" + iterableToString(expectation) + "])"); }; match.set.contains = function setContains(expectation) { return match(function (actual) { return typeOf(actual) === "set" && every(expectation, function (element) { return actual.has(element); }); }, "contains(Set[" + iterableToString(expectation) + "])"); }; match.bool = match.typeOf("boolean"); match.number = match.typeOf("number"); match.string = match.typeOf("string"); match.object = match.typeOf("object"); match.func = match.typeOf("function"); match.regexp = match.typeOf("regexp"); match.date = match.typeOf("date"); match.symbol = match.typeOf("symbol"); module.exports = match; },{"./util/core/deep-equal":19,"./util/core/every":21,"./util/core/function-name":24,"./util/core/iterable-to-string":27,"./util/core/typeOf":30,"./util/core/value-to-string":31,"lodash.get":39}],10:[function(require,module,exports){ "use strict"; var spyInvoke = require("./spy").invoke; var spyCallToString = require("./call").toString; var timesInWords = require("./util/core/times-in-words"); var extend = require("./util/core/extend"); var match = require("./match"); var stub = require("./stub"); var assert = require("./assert"); var deepEqual = require("./util/core/deep-equal").use(match); var format = require("./util/core/format"); var valueToString = require("./util/core/value-to-string"); var slice = Array.prototype.slice; var push = Array.prototype.push; function callCountInWords(callCount) { if (callCount === 0) { return "never called"; } return "called " + timesInWords(callCount); } function expectedCallCountInWords(expectation) { var min = expectation.minCalls; var max = expectation.maxCalls; if (typeof min === "number" && typeof max === "number") { var str = timesInWords(min); if (min !== max) { str = "at least " + str + " and at most " + timesInWords(max); } return str; } if (typeof min === "number") { return "at least " + timesInWords(min); } return "at most " + timesInWords(max); } function receivedMinCalls(expectation) { var hasMinLimit = typeof expectation.minCalls === "number"; return !hasMinLimit || expectation.callCount >= expectation.minCalls; } function receivedMaxCalls(expectation) { if (typeof expectation.maxCalls !== "number") { return false; } return expectation.callCount === expectation.maxCalls; } function verifyMatcher(possibleMatcher, arg) { var isMatcher = match && match.isMatcher(possibleMatcher); return isMatcher && possibleMatcher.test(arg) || true; } var mockExpectation = { minCalls: 1, maxCalls: 1, create: function create(methodName) { var expectation = extend(stub.create(), mockExpectation); delete expectation.create; expectation.method = methodName; return expectation; }, invoke: function invoke(func, thisValue, args) { this.verifyCallAllowed(thisValue, args); return spyInvoke.apply(this, arguments); }, atLeast: function atLeast(num) { if (typeof num !== "number") { throw new TypeError("'" + valueToString(num) + "' is not number"); } if (!this.limitsSet) { this.maxCalls = null; this.limitsSet = true; } this.minCalls = num; return this; }, atMost: function atMost(num) { if (typeof num !== "number") { throw new TypeError("'" + valueToString(num) + "' is not number"); } if (!this.limitsSet) { this.minCalls = null; this.limitsSet = true; } this.maxCalls = num; return this; }, never: function never() { return this.exactly(0); }, once: function once()