diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 372e542c..10b760c2 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -128,14 +128,35 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { throw new Error('unimplemented method'); }; + /** + * Maximum object depth the pretty printer will print to. + * Set this to a lower value to speed up pretty printing if you have large objects. + * @name jasmine.MAX_PRETTY_PRINT_DEPTH + */ j$.MAX_PRETTY_PRINT_DEPTH = 40; + /** + * Maximum number of array elements to display when pretty printing objects. + * Elements past this number will be ellipised. + * @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH + */ j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100; + /** + * Default number of milliseconds Jasmine will wait for an asynchronous spec to complete. + * @name jasmine.DEFAULT_TIMEOUT_INTERVAL + */ j$.DEFAULT_TIMEOUT_INTERVAL = 5000; j$.getGlobal = function() { return jasmineGlobal; }; + /** + * Get the currently booted Jasmine Environment. + * + * @name jasmine.getEnv + * @function + * @return {Env} + */ j$.getEnv = function(options) { var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options); //jasmine. singletons in here (setTimeout blah blah). @@ -183,26 +204,68 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { return matches ? matches[1] : ''; }; + /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value being compared is an instance of the specified class/constructor. + * @name jasmine.any + * @function + * @param {Constructor} clazz - The constructor to check against. + */ j$.any = function(clazz) { return new j$.Any(clazz); }; + /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value being compared is not `null` and not `undefined`. + * @name jasmine.anything + * @function + */ j$.anything = function() { return new j$.Anything(); }; + /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value being compared contains at least the keys and values. + * @name jasmine.objectContaining + * @function + * @param {Object} sample - The subset of properties that _must_ be in the actual. + */ j$.objectContaining = function(sample) { return new j$.ObjectContaining(sample); }; + /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value is a `String` that matches the `RegExp` or `String`. + * @name jasmine.stringMatching + * @function + * @param {RegExp|String} expected + */ j$.stringMatching = function(expected) { return new j$.StringMatching(expected); }; + /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value is an `Array` that contains at least the elements in the sample. + * @name jasmine.arrayContaining + * @function + * @param {Array} sample + */ j$.arrayContaining = function(sample) { return new j$.ArrayContaining(sample); }; + /** + * Create a bare {@link Spy} object. This won't be installed anywhere and will not have any implementation behind it. + * @name jasmine.createSpy + * @function + * @param {String} [name] - Name to give the spy. This will be displayed in failure messages. + * @param {Function} [originalFn] - Function to act as the real implementation. + * @return {Spy} + */ j$.createSpy = function(name, originalFn) { return j$.Spy(name, originalFn); }; @@ -215,6 +278,14 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { putativeSpy.calls instanceof j$.CallTracker; }; + /** + * Create an object with multiple {@link Spy}s as its members. + * @name jasmine.createSpyObj + * @function + * @param {String} [baseName] - Base name for the spies in the object. + * @param {String[]|Object} methodNames - Array of method names to create spies for, or Object whose keys will be method names and values the {@link Spy#and#returnValue|returnValue}. + * @return {Object} + */ j$.createSpyObj = function(baseName, methodNames) { var baseNameIsCollection = j$.isObject_(baseName) || j$.isArray_(baseName); @@ -542,6 +613,12 @@ getJasmineRequireObj().Order = function() { }; getJasmineRequireObj().Env = function(j$) { + /** + * _Note:_ Do not construct this directly, Jasmine will make one during booting. + * @name Env + * @classdesc The Jasmine environment + * @constructor + */ function Env(options) { options = options || {}; @@ -809,6 +886,12 @@ getJasmineRequireObj().Env = function(j$) { }); }; + /** + * Add a custom reporter to the Jasmine environment. + * @name Env#addReporter + * @function + * @see custom_reporter + */ this.addReporter = function(reporterToAdd) { reporter.addReporter(reporterToAdd); }; @@ -1097,6 +1180,13 @@ getJasmineRequireObj().JsApiReporter = function() { elapsed: function(){ return 0; } }; + /** + * _Note:_ Do not construct this directly, use the global `jsApiReporter` to retrieve the instantiated object. + * + * @name jsApiReporter + * @classdesc Reporter added by default in `boot.js` to record results for retrieval in javascript code. + * @class + */ function JsApiReporter(options) { var timer = options.timer || noopTimer, status = 'loaded'; @@ -1120,6 +1210,12 @@ getJasmineRequireObj().JsApiReporter = function() { status = 'done'; }; + /** + * Get the current status for the Jasmine environment. + * @name jsApiReporter#status + * @function + * @return {String} - One of `loaded`, `started`, or `done` + */ this.status = function() { return status; }; @@ -1135,6 +1231,16 @@ getJasmineRequireObj().JsApiReporter = function() { storeSuite(result); }; + /** + * Get the results for a set of suites. + * + * Retrievable in slices for easier serialization. + * @name jsApiReporter#suiteResults + * @function + * @param {Number} index - The position in the suites list to start from. + * @param {Number} length - Maximum number of suite results to return. + * @return {Object[]} + */ this.suiteResults = function(index, length) { return suites.slice(index, index + length); }; @@ -1144,6 +1250,12 @@ getJasmineRequireObj().JsApiReporter = function() { suites_hash[result.id] = result; } + /** + * Get all of the suites in a single object, with their `id` as the key. + * @name jsApiReporter#suites + * @function + * @return {Object} + */ this.suites = function() { return suites_hash; }; @@ -1154,14 +1266,36 @@ getJasmineRequireObj().JsApiReporter = function() { specs.push(result); }; + /** + * Get the results for a set of specs. + * + * Retrievable in slices for easier serialization. + * @name jsApiReporter#specResults + * @function + * @param {Number} index - The position in the specs list to start from. + * @param {Number} length - Maximum number of specs results to return. + * @return {Object[]} + */ this.specResults = function(index, length) { return specs.slice(index, index + length); }; + /** + * Get all spec results. + * @name jsApiReporter#specs + * @function + * @return {Object[]} + */ this.specs = function() { return specs; }; + /** + * Get the number of milliseconds it took for the full Jasmine suite to run. + * @name jsApiReporter#executionTime + * @function + * @return {Number} + */ this.executionTime = function() { return executionTime; }; @@ -1328,6 +1462,9 @@ getJasmineRequireObj().StringMatching = function(j$) { getJasmineRequireObj().CallTracker = function(j$) { + /** + * @namespace Spy#calls + */ function CallTracker() { var calls = []; var opts = {}; @@ -1352,23 +1489,54 @@ getJasmineRequireObj().CallTracker = function(j$) { calls.push(context); }; + /** + * Check whether this spy has been invoked. + * @name Spy#calls#any + * @function + * @return {Boolean} + */ this.any = function() { return !!calls.length; }; + /** + * Get the number of invocations of this spy. + * @name Spy#calls#count + * @function + * @return {Integer} + */ this.count = function() { return calls.length; }; + /** + * Get the arguments that were passed to a specific invocation of this spy. + * @name Spy#calls#argsFor + * @function + * @param {Integer} index The 0-based invocation index. + * @return {Array} + */ this.argsFor = function(index) { var call = calls[index]; return call ? call.args : []; }; + /** + * Get the raw calls array for this spy. + * @name Spy#calls#all + * @function + * @return {Spy.callData[]} + */ this.all = function() { return calls; }; + /** + * Get all of the arguments for each invocation of this spy in the order they were received. + * @name Spy#calls#allArgs + * @function + * @return {Array} + */ this.allArgs = function() { var callArgs = []; for(var i = 0; i < calls.length; i++){ @@ -1378,18 +1546,40 @@ getJasmineRequireObj().CallTracker = function(j$) { return callArgs; }; + /** + * Get the first invocation of this spy. + * @name Spy#calls#first + * @function + * @return {ObjecSpy.callData} + */ this.first = function() { return calls[0]; }; + /** + * Get the most recent invocation of this spy. + * @name Spy#calls#mostRecent + * @function + * @return {ObjecSpy.callData} + */ this.mostRecent = function() { return calls[calls.length - 1]; }; + /** + * Reset this spy as if it has never been called. + * @name Spy#calls#reset + * @function + */ this.reset = function() { calls = []; }; + /** + * Set this spy to do a shallow clone of arguments passed to each invocation. + * @name Spy#calls#saveArgumentsByValue + * @function + */ this.saveArgumentsByValue = function() { opts.cloneArgs = true; }; @@ -1440,6 +1630,11 @@ getJasmineRequireObj().clearStack = function(j$) { }; getJasmineRequireObj().Clock = function() { + /** + * _Note:_ Do not construct this directly, Jasmine will make one during booting. You can get the current clock with {@link jasmine.clock}. + * @class Clock + * @classdesc Jasmine's mock clock is used when testing time dependent code. + */ function Clock(global, delayedFunctionSchedulerFactory, mockDate) { var self = this, realTimingFunctions = { @@ -1459,6 +1654,12 @@ getJasmineRequireObj().Clock = function() { timer; + /** + * Install the mock clock over the built-in methods. + * @name Clock#install + * @function + * @return {Clock} + */ self.install = function() { if(!originalTimingFunctionsIntact()) { throw new Error('Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'); @@ -1471,6 +1672,11 @@ getJasmineRequireObj().Clock = function() { return self; }; + /** + * Uninstall the mock clock, returning the built-in methods to their places. + * @name Clock#uninstall + * @function + */ self.uninstall = function() { delayedFunctionScheduler = null; mockDate.uninstall(); @@ -1480,6 +1686,14 @@ getJasmineRequireObj().Clock = function() { installed = false; }; + /** + * Execute a function with a mocked Clock + * + * The clock will be {@link Clock#install|install}ed before the function is called and {@link Clock#uninstall|uninstall}ed in a `finally` after the function completes. + * @name Clock#withMock + * @function + * @param {closure} Function The function to be called. + */ self.withMock = function(closure) { this.install(); try { @@ -1489,6 +1703,12 @@ getJasmineRequireObj().Clock = function() { } }; + /** + * Instruct the installed Clock to also mock the date returned by `new Date()` + * @name Clock#mockDate + * @function + * @param {Date} [initialDate=now] The `Date` to provide. + */ self.mockDate = function(initialDate) { mockDate.install(initialDate); }; @@ -1521,6 +1741,12 @@ getJasmineRequireObj().Clock = function() { return Function.prototype.call.apply(timer.clearInterval, [global, id]); }; + /** + * Tick the Clock forward, running any enqueued timeouts along the way + * @name Clock#tick + * @function + * @param {int} millis The number of milliseconds to tick. + */ self.tick = function(millis) { if (installed) { delayedFunctionScheduler.tick(millis, function(millis) { mockDate.tick(millis); }); @@ -1771,6 +1997,10 @@ getJasmineRequireObj().ExceptionFormatter = function() { getJasmineRequireObj().Expectation = function() { + /** + * Matchers that come with Jasmine out of the box. + * @namespace matchers + */ function Expectation(options) { this.util = options.util || { buildFailureMessage: function() {} }; this.customEqualityTesters = options.customEqualityTesters || []; @@ -2454,6 +2684,14 @@ getJasmineRequireObj().ObjectPath = function(j$) { }; getJasmineRequireObj().toBe = function() { + /** + * {@link expect} the actual value to be `===` to the expected value. + * @function + * @name matchers#toBe + * @param {Object} expected - The expected value to compare against. + * @example + * expect(thing).toBe(realThing); + */ function toBe() { return { compare: function(actual, expected) { @@ -2468,7 +2706,15 @@ getJasmineRequireObj().toBe = function() { }; getJasmineRequireObj().toBeCloseTo = function() { - + /** + * {@link expect} the actual value to be within a specified precision of the expected value. + * @function + * @name matchers#toBeCloseTo + * @param {Object} expected - The expected value to compare against. + * @param {Number} [precision=2] - The number of decimal points to check. + * @example + * expect(number).toBeCloseTo(42.2, 3); + */ function toBeCloseTo() { return { compare: function(actual, expected, precision) { @@ -2487,6 +2733,13 @@ getJasmineRequireObj().toBeCloseTo = function() { }; getJasmineRequireObj().toBeDefined = function() { + /** + * {@link expect} the actual value to be defined. (Not `undefined`) + * @function + * @name matchers#toBeDefined + * @example + * expect(result).toBeDefined(); + */ function toBeDefined() { return { compare: function(actual) { @@ -2501,6 +2754,13 @@ getJasmineRequireObj().toBeDefined = function() { }; getJasmineRequireObj().toBeFalsy = function() { + /** + * {@link expect} the actual value to be falsy + * @function + * @name matchers#toBeFalsy + * @example + * expect(result).toBeFalsy(); + */ function toBeFalsy() { return { compare: function(actual) { @@ -2515,7 +2775,14 @@ getJasmineRequireObj().toBeFalsy = function() { }; getJasmineRequireObj().toBeGreaterThan = function() { - + /** + * {@link expect} the actual value to be greater than the expected value. + * @function + * @name matchers#toBeGreaterThan + * @param {Number} expected - The value to compare against. + * @example + * expect(result).toBeGreaterThan(3); + */ function toBeGreaterThan() { return { compare: function(actual, expected) { @@ -2531,7 +2798,14 @@ getJasmineRequireObj().toBeGreaterThan = function() { getJasmineRequireObj().toBeGreaterThanOrEqual = function() { - + /** + * {@link expect} the actual value to be greater than or equal to the expected value. + * @function + * @name matchers#toBeGreaterThanOrEqual + * @param {Number} expected - The expected value to compare against. + * @example + * expect(result).toBeGreaterThanOrEqual(25); + */ function toBeGreaterThanOrEqual() { return { compare: function(actual, expected) { @@ -2546,6 +2820,14 @@ getJasmineRequireObj().toBeGreaterThanOrEqual = function() { }; getJasmineRequireObj().toBeLessThan = function() { + /** + * {@link expect} the actual value to be less than the expected value. + * @function + * @name matchers#toBeLessThan + * @param {Number} expected - The expected value to compare against. + * @example + * expect(result).toBeLessThan(0); + */ function toBeLessThan() { return { @@ -2559,7 +2841,16 @@ getJasmineRequireObj().toBeLessThan = function() { return toBeLessThan; }; + getJasmineRequireObj().toBeLessThanOrEqual = function() { + /** + * {@link expect} the actual value to be less than or equal to the expected value. + * @function + * @name matchers#toBeLessThanOrEqual + * @param {Number} expected - The expected value to compare against. + * @example + * expect(result).toBeLessThanOrEqual(123); + */ function toBeLessThanOrEqual() { return { @@ -2575,7 +2866,13 @@ getJasmineRequireObj().toBeLessThanOrEqual = function() { }; getJasmineRequireObj().toBeNaN = function(j$) { - + /** + * {@link expect} the actual value to be `NaN` (Not a Number). + * @function + * @name matchers#toBeNaN + * @example + * expect(thing).toBeNaN(); + */ function toBeNaN() { return { compare: function(actual) { @@ -2598,7 +2895,13 @@ getJasmineRequireObj().toBeNaN = function(j$) { }; getJasmineRequireObj().toBeNull = function() { - + /** + * {@link expect} the actual value to be `null`. + * @function + * @name matchers#toBeNull + * @example + * expect(result).toBeNull(); + */ function toBeNull() { return { compare: function(actual) { @@ -2613,7 +2916,13 @@ getJasmineRequireObj().toBeNull = function() { }; getJasmineRequireObj().toBeTruthy = function() { - + /** + * {@link expect} the actual value to be truthy. + * @function + * @name matchers#toBeTruthy + * @example + * expect(thing).toBeTruthy(); + */ function toBeTruthy() { return { compare: function(actual) { @@ -2628,7 +2937,13 @@ getJasmineRequireObj().toBeTruthy = function() { }; getJasmineRequireObj().toBeUndefined = function() { - + /** + * {@link expect} the actual value to be `undefined`. + * @function + * @name matchers#toBeUndefined + * @example + * expect(result).toBeUndefined(): + */ function toBeUndefined() { return { compare: function(actual) { @@ -2643,6 +2958,15 @@ getJasmineRequireObj().toBeUndefined = function() { }; getJasmineRequireObj().toContain = function() { + /** + * {@link expect} the actual value to contain a specific value. + * @function + * @name matchers#toContain + * @param {Object} expected - The value to look for. + * @example + * expect(array).toContain(anElement); + * expect(string).toContain(substring); + */ function toContain(util, customEqualityTesters) { customEqualityTesters = customEqualityTesters || []; @@ -2660,7 +2984,14 @@ getJasmineRequireObj().toContain = function() { }; getJasmineRequireObj().toEqual = function(j$) { - + /** + * {@link expect} the actual value to be equal to the expected, using deep equality comparison. + * @function + * @name matchers#toEqual + * @param {Object} expected - Expected value + * @example + * expect(bigObject).toEqual({"foo": ['bar', 'baz']}); + */ function toEqual(util, customEqualityTesters) { customEqualityTesters = customEqualityTesters || []; @@ -2688,6 +3019,14 @@ getJasmineRequireObj().toHaveBeenCalled = function(j$) { var getErrorMsg = j$.formatErrorMsg('', 'expect().toHaveBeenCalled()'); + /** + * {@link expect} the actual (a {@link Spy}) to have been called. + * @function + * @name matchers#toHaveBeenCalled + * @example + * expect(mySpy).toHaveBeenCalled(); + * expect(mySpy).not.toHaveBeenCalled(); + */ function toHaveBeenCalled() { return { compare: function(actual) { @@ -2719,6 +3058,14 @@ getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) { var getErrorMsg = j$.formatErrorMsg('', 'expect().toHaveBeenCalledBefore()'); + /** + * {@link expect} the actual value (a {@link Spy}) to have been called before another {@link Spy}. + * @function + * @name matchers#toHaveBeenCalledBefore + * @param {Spy} expected - {@link Spy} that should have been called after the `actual` {@link Spy}. + * @example + * expect(mySpy).toHaveBeenCalledBefore(otherSpy); + */ function toHaveBeenCalledBefore() { return { compare: function(firstSpy, latterSpy) { @@ -2772,6 +3119,14 @@ getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) { var getErrorMsg = j$.formatErrorMsg('', 'expect().toHaveBeenCalledTimes()'); + /** + * {@link expect} the actual (a {@link Spy}) to have been called the specified number of times. + * @function + * @name matchers#toHaveBeenCalledTimes + * @param {Number} expected - The number of invocations to look for. + * @example + * expect(mySpy).toHaveBeenCalledTimes(3); + */ function toHaveBeenCalledTimes() { return { compare: function(actual, expected) { @@ -2805,6 +3160,14 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { var getErrorMsg = j$.formatErrorMsg('', 'expect().toHaveBeenCalledWith(...arguments)'); + /** + * {@link expect} the actual (a {@link Spy}) to have been called with particular arguments at least once. + * @function + * @name matchers#toHaveBeenCalledWith + * @param {...Object} - The arguments to look for + * @example + * expect(mySpy).toHaveBeenCalledWith('foo', 'bar', 2); + */ function toHaveBeenCalledWith(util, customEqualityTesters) { return { compare: function() { @@ -2841,6 +3204,15 @@ getJasmineRequireObj().toMatch = function(j$) { var getErrorMsg = j$.formatErrorMsg('', 'expect().toMatch( || )'); + /** + * {@link expect} the actual value to match a regular expression + * @function + * @name matchers#toMatch + * @param {RegExp|String} expected - Value to look for in the string. + * @example + * expect("my string").toMatch(/string$/); + * expect("other string").toMatch("her"); + */ function toMatch() { return { compare: function(actual, expected) { @@ -2864,6 +3236,15 @@ getJasmineRequireObj().toThrow = function(j$) { var getErrorMsg = j$.formatErrorMsg('', 'expect(function() {}).toThrow()'); + /** + * {@link expect} a function to `throw` something. + * @function + * @name matchers#toThrow + * @param {Object} [expected] - Value that should be thrown. If not provided, simply the fact that something was thrown will be checked. + * @example + * expect(function() { return 'things'; }).toThrow('foo'); + * expect(function() { return 'stuff'; }).toThrow(); + */ function toThrow(util) { return { compare: function(actual, expected) { @@ -2913,6 +3294,19 @@ getJasmineRequireObj().toThrowError = function(j$) { var getErrorMsg = j$.formatErrorMsg('', 'expect(function() {}).toThrowError(, )'); + /** + * {@link expect} a function to `throw` an `Error`. + * @function + * @name matchers#toThrowError + * @param {Error} [expected] - `Error` constructor the object that was thrown needs to be an instance of. If not provided, `Error` will be used. + * @param {RegExp|String} [message] - The message that should be set on the thrown `Error` + * @example + * expect(function() { return 'things'; }).toThrowError(MyCustomError, 'message'); + * expect(function() { return 'things'; }).toThrowError(MyCustomError, /bar/); + * expect(function() { return 'stuff'; }).toThrowError(MyCustomError); + * expect(function() { return 'other'; }).toThrowError(/foo/); + * expect(function() { return 'other'; }).toThrowError(); + */ function toThrowError () { return { compare: function(actual) { @@ -3500,62 +3894,202 @@ getJasmineRequireObj().ReportDispatcher = function() { getJasmineRequireObj().interface = function(jasmine, env) { var jasmineInterface = { + /** + * Create a group of specs (often called a suite). + * + * Calls to `describe` can be nested within other calls to compose your suite as a tree. + * @name describe + * @function + * @global + * @param {String} description Textual description of the group + * @param {Function} specDefinitions Function for Jasmine to invoke that will define inner suites a specs + */ describe: function(description, specDefinitions) { return env.describe(description, specDefinitions); }, + /** + * A temporarily disabled [`describe`]{@link describe} + * + * Specs within an `xdescribe` will be marked pending and not executed + * @name xdescribe + * @function + * @global + * @param {String} description Textual description of the group + * @param {Function} specDefinitions Function for Jasmine to invoke that will define inner suites a specs + */ xdescribe: function(description, specDefinitions) { return env.xdescribe(description, specDefinitions); }, + /** + * A focused [`describe`]{@link describe} + * + * If suites or specs are focused, only those that are focused will be executed + * @see fit + * @name fdescribe + * @function + * @global + * @param {String} description Textual description of the group + * @param {Function} specDefinitions Function for Jasmine to invoke that will define inner suites a specs + */ fdescribe: function(description, specDefinitions) { return env.fdescribe(description, specDefinitions); }, + /** + * Define a single spec. A spec should contain one or more {@link expect|expectations} that test the state of the code. + * + * A spec whose expectations all succeed will be passing and a spec with any failures will fail. + * @name it + * @function + * @global + * @param {String} description Textual description of what this spec is checking + * @param {Function} [testFunction] Function that contains the code of your test. If not provided the test will be `pending`. + * @param {Int} [timeout={@link jasmine.DEFAULT_TIMEOUT_INTERVAL}] Custom timeout for an async spec. + */ it: function() { return env.it.apply(env, arguments); }, + /** + * A temporarily disabled [`it`]{@link it} + * + * The spec will report as `pending` and will not be executed. + * @name xit + * @function + * @global + * @param {String} description Textual description of what this spec is checking. + * @param {Function} [testFunction] Function that contains the code of your test. Will not be executed. + */ xit: function() { return env.xit.apply(env, arguments); }, + /** + * A focused [`it`]{@link it} + * + * If suites or specs are focused, only those that are focused will be executed. + * @name fit + * @function + * @global + * @param {String} description Textual description of what this spec is checking. + * @param {Function} testFunction Function that contains the code of your test. + * @param {Int} [timeout={@link jasmine.DEFAULT_TIMEOUT_INTERVAL}] Custom timeout for an async spec. + */ fit: function() { return env.fit.apply(env, arguments); }, + /** + * Run some shared setup before each of the specs in the {@link describe} in which it is called. + * @name beforeEach + * @function + * @global + * @param {Function} [function] Function that contains the code to setup your specs. + * @param {Int} [timeout={@link jasmine.DEFAULT_TIMEOUT_INTERVAL}] Custom timeout for an async beforeEach. + */ beforeEach: function() { return env.beforeEach.apply(env, arguments); }, + /** + * Run some shared teardown after each of the specs in the {@link describe} in which it is called. + * @name afterEach + * @function + * @global + * @param {Function} [function] Function that contains the code to teardown your specs. + * @param {Int} [timeout={@link jasmine.DEFAULT_TIMEOUT_INTERVAL}] Custom timeout for an async afterEach. + */ afterEach: function() { return env.afterEach.apply(env, arguments); }, + /** + * Run some shared setup once before all of the specs in the {@link describe} are run. + * + * _Note:_ Be careful, sharing the setup from a beforeAll makes it easy to accidentally leak state between your specs so that they erroneously pass or fail. + * @name beforeAll + * @function + * @global + * @param {Function} [function] Function that contains the code to setup your specs. + * @param {Int} [timeout={@link jasmine.DEFAULT_TIMEOUT_INTERVAL}] Custom timeout for an async beforeAll. + */ beforeAll: function() { return env.beforeAll.apply(env, arguments); }, + /** + * Run some shared teardown once before all of the specs in the {@link describe} are run. + * + * _Note:_ Be careful, sharing the teardown from a afterAll makes it easy to accidentally leak state between your specs so that they erroneously pass or fail. + * @name afterAll + * @function + * @global + * @param {Function} [function] Function that contains the code to teardown your specs. + * @param {Int} [timeout={@link jasmine.DEFAULT_TIMEOUT_INTERVAL}] Custom timeout for an async afterAll. + */ afterAll: function() { return env.afterAll.apply(env, arguments); }, + /** + * Create an expectation for a spec. + * @name expect + * @function + * @global + * @param {Object} actual - Actual computed value to test expectations against. + * @return {matchers} + */ expect: function(actual) { return env.expect(actual); }, + /** + * Mark a spec as pending, expectation results will be ignored. + * @name pending + * @function + * @global + * @param {String} [message] - Reason the spec is pending. + */ pending: function() { return env.pending.apply(env, arguments); }, + /** + * Explicitly mark a spec as failed. + * @name fail + * @function + * @global + * @param {String|Error} [error] - Reason for the failure. + */ fail: function() { return env.fail.apply(env, arguments); }, + /** + * Install a spy onto an existing object. + * @name spyOn + * @function + * @global + * @param {Object} obj - The object upon which to install the {@link Spy}. + * @param {String} methodName - The name of the method to replace with a {@link Spy}. + * @returns {Spy} + */ spyOn: function(obj, methodName) { return env.spyOn(obj, methodName); }, + /** + * Install a spy on a property onto an existing object. + * @name spyOnProperty + * @function + * @global + * @param {Object} obj - The object upon which to install the {@link Spy} + * @param {String} propertyName - The name of the property to replace with a {@link Spy}. + * @param {String} [accessType=get] - The access type (get|set) of the property to {@link Spy} on. + * @returns {Spy} + */ spyOnProperty: function(obj, methodName, accessType) { return env.spyOnProperty(obj, methodName, accessType); }, @@ -3564,17 +4098,44 @@ getJasmineRequireObj().interface = function(jasmine, env) { timer: new jasmine.Timer() }), + /** + * @namespace jasmine + */ jasmine: jasmine }; + /** + * Add a custom equality tester for the current scope of specs. + * + * _Note:_ This is only callable from within a {@link beforeEach}, {@link it}, or {@link beforeAll}. + * @name jasmine.addCustomEqualityTester + * @function + * @param {Function} tester - A function which takes two arguments to compare and returns a `true` or `false` comparison result if it knows how to compare them, and `undefined` otherwise. + * @see custom_equality + */ jasmine.addCustomEqualityTester = function(tester) { env.addCustomEqualityTester(tester); }; + /** + * Add custom matchers for the current scope of specs. + * + * _Note:_ This is only callable from within a {@link beforeEach}, {@link it}, or {@link beforeAll}. + * @name jasmine.addMatchers + * @function + * @param {Object} matchers - Keys from this object will be the new matcher names. + * @see custom_matcher + */ jasmine.addMatchers = function(matchers) { return env.addMatchers(matchers); }; + /** + * Get the currently booted mock {Clock} for this Jasmine environment. + * @name jasmine.clock + * @function + * @returns {Clock} + */ jasmine.clock = function() { return env.clock; }; @@ -3592,6 +4153,11 @@ getJasmineRequireObj().Spy = function (j$) { }; })(); + /** + * _Note:_ Do not construct this directly, use {@link spyOn}, {@link spyOnProperty}, {@link jasmine.createSpy}, or {@link jasmine.createSpyObj} + * @constructor + * @name Spy + */ function Spy(name, originalFn) { var args = buildArgs(), /*`eval` is the only option to preserve both this and context: @@ -3611,6 +4177,12 @@ getJasmineRequireObj().Spy = function (j$) { }), callTracker = new j$.CallTracker(), spy = function () { + /** + * @name Spy.callData + * @property {object} object - `this` context for the invocation. + * @property {number} invocationOrder - Order of the invocation. + * @property {Array} args - The arguments passed for this invocation. + */ var callData = { object: this, invocationOrder: nextOrder(), @@ -3795,6 +4367,9 @@ getJasmineRequireObj().SpyRegistry = function(j$) { getJasmineRequireObj().SpyStrategy = function(j$) { + /** + * @namespace Spy#and + */ function SpyStrategy(options) { options = options || {}; @@ -3803,19 +4378,41 @@ getJasmineRequireObj().SpyStrategy = function(j$) { getSpy = options.getSpy || function() {}, plan = function() {}; + /** + * Return the identifying information for the spy. + * @name Spy#and#identity + * @function + * @returns {String} + */ this.identity = function() { return identity; }; + /** + * Execute the current spy strategy. + * @name Spy#and#exec + * @function + */ this.exec = function() { return plan.apply(this, arguments); }; + /** + * Tell the spy to call through to the real implementation when invoked. + * @name Spy#and#callThrough + * @function + */ this.callThrough = function() { plan = originalFn; return getSpy(); }; + /** + * Tell the spy to return the value when invoked. + * @name Spy#and#returnValue + * @function + * @param {*} value The value to return. + */ this.returnValue = function(value) { plan = function() { return value; @@ -3823,6 +4420,12 @@ getJasmineRequireObj().SpyStrategy = function(j$) { return getSpy(); }; + /** + * Tell the spy to return one of the specified values (sequentially) each time the spy is invoked. + * @name Spy#and#returnValues + * @function + * @param {...*} values - Values to be returned on subsequent calls to the spy. + */ this.returnValues = function() { var values = Array.prototype.slice.call(arguments); plan = function () { @@ -3831,6 +4434,12 @@ getJasmineRequireObj().SpyStrategy = function(j$) { return getSpy(); }; + /** + * Tell the spy to throw an error when invoked. + * @name Spy#and#throwError + * @function + * @param {Error|String} something Thing to throw + */ this.throwError = function(something) { var error = (something instanceof Error) ? something : new Error(something); plan = function() { @@ -3839,6 +4448,12 @@ getJasmineRequireObj().SpyStrategy = function(j$) { return getSpy(); }; + /** + * Tell the spy to call a fake implementation when invoked. + * @name Spy#and#callFake + * @function + * @param {Function} fn The function to invoke with the passed parameters. + */ this.callFake = function(fn) { if(!j$.isFunction_(fn)) { throw new Error('Argument passed to callFake should be a function, got ' + fn); @@ -3847,6 +4462,11 @@ getJasmineRequireObj().SpyStrategy = function(j$) { return getSpy(); }; + /** + * Tell the spy to do nothing when invoked. This is the default. + * @name Spy#and#stub + * @function + */ this.stub = function(fn) { plan = function() {}; return getSpy(); diff --git a/src/core/Env.js b/src/core/Env.js index 44d47acd..4377b81a 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -273,9 +273,10 @@ getJasmineRequireObj().Env = function(j$) { }; /** + * Add a custom reporter to the Jasmine environment. * @name Env#addReporter * @function - * @tutorial addReporter + * @see custom_reporter */ this.addReporter = function(reporterToAdd) { reporter.addReporter(reporterToAdd); diff --git a/src/core/JsApiReporter.js b/src/core/JsApiReporter.js index 5f34ffa3..3737330d 100644 --- a/src/core/JsApiReporter.js +++ b/src/core/JsApiReporter.js @@ -36,8 +36,10 @@ getJasmineRequireObj().JsApiReporter = function() { }; /** + * Get the current status for the Jasmine environment. * @name jsApiReporter#status * @function + * @return {String} - One of `loaded`, `started`, or `done` */ this.status = function() { return status; @@ -55,8 +57,14 @@ getJasmineRequireObj().JsApiReporter = function() { }; /** + * Get the results for a set of suites. + * + * Retrievable in slices for easier serialization. * @name jsApiReporter#suiteResults * @function + * @param {Number} index - The position in the suites list to start from. + * @param {Number} length - Maximum number of suite results to return. + * @return {Object[]} */ this.suiteResults = function(index, length) { return suites.slice(index, index + length); @@ -67,6 +75,12 @@ getJasmineRequireObj().JsApiReporter = function() { suites_hash[result.id] = result; } + /** + * Get all of the suites in a single object, with their `id` as the key. + * @name jsApiReporter#suites + * @function + * @return {Object} + */ this.suites = function() { return suites_hash; }; @@ -77,14 +91,36 @@ getJasmineRequireObj().JsApiReporter = function() { specs.push(result); }; + /** + * Get the results for a set of specs. + * + * Retrievable in slices for easier serialization. + * @name jsApiReporter#specResults + * @function + * @param {Number} index - The position in the specs list to start from. + * @param {Number} length - Maximum number of specs results to return. + * @return {Object[]} + */ this.specResults = function(index, length) { return specs.slice(index, index + length); }; + /** + * Get all spec results. + * @name jsApiReporter#specs + * @function + * @return {Object[]} + */ this.specs = function() { return specs; }; + /** + * Get the number of milliseconds it took for the full Jasmine suite to run. + * @name jsApiReporter#executionTime + * @function + * @return {Number} + */ this.executionTime = function() { return executionTime; }; diff --git a/src/core/base.js b/src/core/base.js index 5cae95fb..89b94555 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -4,14 +4,19 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; /** + * Maximum object depth the pretty printer will print to. + * Set this to a lower value to speed up pretty printing if you have large objects. * @name jasmine.MAX_PRETTY_PRINT_DEPTH */ j$.MAX_PRETTY_PRINT_DEPTH = 40; /** + * Maximum number of array elements to display when pretty printing objects. + * Elements past this number will be ellipised. * @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH */ j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100; /** + * Default number of milliseconds Jasmine will wait for an asynchronous spec to complete. * @name jasmine.DEFAULT_TIMEOUT_INTERVAL */ j$.DEFAULT_TIMEOUT_INTERVAL = 5000; @@ -75,14 +80,19 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value being compared is an instance of the specified class/constructor. * @name jasmine.any * @function + * @param {Constructor} clazz - The constructor to check against. */ j$.any = function(clazz) { return new j$.Any(clazz); }; /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value being compared is not `null` and not `undefined`. * @name jasmine.anything * @function */ @@ -91,32 +101,44 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value being compared contains at least the keys and values. * @name jasmine.objectContaining * @function + * @param {Object} sample - The subset of properties that _must_ be in the actual. */ j$.objectContaining = function(sample) { return new j$.ObjectContaining(sample); }; /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value is a `String` that matches the `RegExp` or `String`. * @name jasmine.stringMatching * @function + * @param {RegExp|String} expected */ j$.stringMatching = function(expected) { return new j$.StringMatching(expected); }; /** + * Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}), + * that will succeed if the actual value is an `Array` that contains at least the elements in the sample. * @name jasmine.arrayContaining * @function + * @param {Array} sample */ j$.arrayContaining = function(sample) { return new j$.ArrayContaining(sample); }; /** + * Create a bare {@link Spy} object. This won't be installed anywhere and will not have any implementation behind it. * @name jasmine.createSpy * @function + * @param {String} [name] - Name to give the spy. This will be displayed in failure messages. + * @param {Function} [originalFn] - Function to act as the real implementation. * @return {Spy} */ j$.createSpy = function(name, originalFn) { @@ -132,8 +154,12 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; /** + * Create an object with multiple {@link Spy}s as its members. * @name jasmine.createSpyObj * @function + * @param {String} [baseName] - Base name for the spies in the object. + * @param {String[]|Object} methodNames - Array of method names to create spies for, or Object whose keys will be method names and values the {@link Spy#and#returnValue|returnValue}. + * @return {Object} */ j$.createSpyObj = function(baseName, methodNames) { var baseNameIsCollection = j$.isObject_(baseName) || j$.isArray_(baseName); diff --git a/src/core/requireInterface.js b/src/core/requireInterface.js index a17e801c..468f9f93 100644 --- a/src/core/requireInterface.js +++ b/src/core/requireInterface.js @@ -1,8 +1,9 @@ getJasmineRequireObj().interface = function(jasmine, env) { var jasmineInterface = { /** - * Create a suite of specs + * Create a group of specs (often called a suite). * + * Calls to `describe` can be nested within other calls to compose your suite as a tree. * @name describe * @function * @global @@ -31,7 +32,7 @@ getJasmineRequireObj().interface = function(jasmine, env) { * A focused [`describe`]{@link describe} * * If suites or specs are focused, only those that are focused will be executed - * @see {fit} + * @see fit * @name fdescribe * @function * @global @@ -43,7 +44,9 @@ getJasmineRequireObj().interface = function(jasmine, env) { }, /** - * A single spec + * Define a single spec. A spec should contain one or more {@link expect|expectations} that test the state of the code. + * + * A spec whose expectations all succeed will be passing and a spec with any failures will fail. * @name it * @function * @global @@ -208,24 +211,33 @@ getJasmineRequireObj().interface = function(jasmine, env) { }; /** + * Add a custom equality tester for the current scope of specs. + * + * _Note:_ This is only callable from within a {@link beforeEach}, {@link it}, or {@link beforeAll}. * @name jasmine.addCustomEqualityTester * @function - * @tutorial addCustomEqualityTester + * @param {Function} tester - A function which takes two arguments to compare and returns a `true` or `false` comparison result if it knows how to compare them, and `undefined` otherwise. + * @see custom_equality */ jasmine.addCustomEqualityTester = function(tester) { env.addCustomEqualityTester(tester); }; /** + * Add custom matchers for the current scope of specs. + * + * _Note:_ This is only callable from within a {@link beforeEach}, {@link it}, or {@link beforeAll}. * @name jasmine.addMatchers * @function - * @tutorial addMatchers + * @param {Object} matchers - Keys from this object will be the new matcher names. + * @see custom_matcher */ jasmine.addMatchers = function(matchers) { return env.addMatchers(matchers); }; /** + * Get the currently booted mock {Clock} for this Jasmine environment. * @name jasmine.clock * @function * @returns {Clock}