Merge branch 'master' into expect-context
This commit is contained in:
228
src/core/AsyncExpectation.js
Normal file
228
src/core/AsyncExpectation.js
Normal file
@@ -0,0 +1,228 @@
|
||||
getJasmineRequireObj().AsyncExpectation = function(j$) {
|
||||
var promiseForMessage = {
|
||||
jasmineToString: function() { return 'a promise'; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronous matchers.
|
||||
* @namespace async-matchers
|
||||
*/
|
||||
function AsyncExpectation(options) {
|
||||
var global = options.global || j$.getGlobal();
|
||||
this.util = options.util || { buildFailureMessage: function() {} };
|
||||
this.customEqualityTesters = options.customEqualityTesters || [];
|
||||
this.addExpectationResult = options.addExpectationResult || function(){};
|
||||
this.actual = options.actual;
|
||||
this.filters = new j$.ExpectationFilterChain();
|
||||
|
||||
if (!global.Promise) {
|
||||
throw new Error('expectAsync is unavailable because the environment does not support promises.');
|
||||
}
|
||||
|
||||
if (!j$.isPromiseLike(this.actual)) {
|
||||
throw new Error('Expected expectAsync to be called with a promise.');
|
||||
}
|
||||
|
||||
['toBeResolved', 'toBeRejected', 'toBeResolvedTo', 'toBeRejectedWith'].forEach(wrapCompare.bind(this));
|
||||
}
|
||||
|
||||
function wrapCompare(name) {
|
||||
var matcher = this[name];
|
||||
this[name] = function() {
|
||||
var self = this;
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
args.unshift(this.actual);
|
||||
|
||||
// Capture the call stack here, before we go async, so that it will
|
||||
// contain frames that are relevant to the user instead of just parts
|
||||
// of Jasmine.
|
||||
var errorForStack = j$.util.errorWithStack();
|
||||
|
||||
var matcherCompare = this.instantiateMatcher(matcher);
|
||||
|
||||
return matcherCompare.apply(self, args).then(function(result) {
|
||||
var message;
|
||||
|
||||
args[0] = promiseForMessage;
|
||||
message = j$.Expectation.prototype.buildMessage.call(self, result, name, args);
|
||||
|
||||
self.addExpectationResult(result.pass, {
|
||||
matcherName: name,
|
||||
passed: result.pass,
|
||||
message: message,
|
||||
error: undefined,
|
||||
errorForStack: errorForStack,
|
||||
actual: self.actual
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
AsyncExpectation.prototype.instantiateMatcher = function(matcher) {
|
||||
var comparisonFunc = this.filters.selectComparisonFunc(matcher);
|
||||
return comparisonFunc || matcher;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expect a promise to be resolved.
|
||||
* @function
|
||||
* @async
|
||||
* @name async-matchers#toBeResolved
|
||||
* @example
|
||||
* await expectAsync(aPromise).toBeResolved();
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeResolved();
|
||||
*/
|
||||
AsyncExpectation.prototype.toBeResolved = function(actual) {
|
||||
return actual.then(
|
||||
function() { return {pass: true}; },
|
||||
function() { return {pass: false}; }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expect a promise to be rejected.
|
||||
* @function
|
||||
* @async
|
||||
* @name async-matchers#toBeRejected
|
||||
* @example
|
||||
* await expectAsync(aPromise).toBeRejected();
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeRejected();
|
||||
*/
|
||||
AsyncExpectation.prototype.toBeRejected = function(actual) {
|
||||
return actual.then(
|
||||
function() { return {pass: false}; },
|
||||
function() { return {pass: true}; }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expect a promise to be resolved to a value equal to the expected, using deep equality comparison.
|
||||
* @function
|
||||
* @async
|
||||
* @name async-matchers#toBeResolvedTo
|
||||
* @param {Object} expected - Value that the promise is expected to resolve to
|
||||
* @example
|
||||
* await expectAsync(aPromise).toBeResolvedTo({prop: 'value'});
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeResolvedTo({prop: 'value'});
|
||||
*/
|
||||
AsyncExpectation.prototype.toBeResolvedTo = function(actualPromise, expectedValue) {
|
||||
var self = this;
|
||||
|
||||
function prefix(passed) {
|
||||
return 'Expected a promise ' +
|
||||
(passed ? 'not ' : '') +
|
||||
'to be resolved to ' + j$.pp(expectedValue);
|
||||
}
|
||||
|
||||
return actualPromise.then(
|
||||
function(actualValue) {
|
||||
if (self.util.equals(actualValue, expectedValue, self.customEqualityTesters)) {
|
||||
return {
|
||||
pass: true,
|
||||
message: prefix(true) + '.'
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was resolved to ' + j$.pp(actualValue) + '.'
|
||||
};
|
||||
}
|
||||
},
|
||||
function() {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was rejected.'
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expect a promise to be rejected to a value equal to the expected, using deep equality comparison.
|
||||
* @function
|
||||
* @async
|
||||
* @name async-matchers#toBeRejectedWith
|
||||
* @param {Object} expected - Value that the promise is expected to reject to
|
||||
* @example
|
||||
* await expectAsync(aPromise).toBeRejectedWith({prop: 'value'});
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeRejectedWith({prop: 'value'});
|
||||
*/
|
||||
AsyncExpectation.prototype.toBeRejectedWith = function(actualPromise, expectedValue) {
|
||||
var self = this;
|
||||
|
||||
function prefix(passed) {
|
||||
return 'Expected a promise ' +
|
||||
(passed ? 'not ' : '') +
|
||||
'to be rejected with ' + j$.pp(expectedValue);
|
||||
}
|
||||
|
||||
return actualPromise.then(
|
||||
function() {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was resolved.'
|
||||
};
|
||||
},
|
||||
function(actualValue) {
|
||||
if (self.util.equals(actualValue, expectedValue, self.customEqualityTesters)) {
|
||||
return {
|
||||
pass: true,
|
||||
message: prefix(true) + '.'
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was rejected with ' + j$.pp(actualValue) + '.'
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
AsyncExpectation.prototype.addFilter = function(filter) {
|
||||
var result = Object.create(this);
|
||||
result.filters = this.filters.addFilter(filter);
|
||||
return result;
|
||||
};
|
||||
|
||||
AsyncExpectation.factory = function(options) {
|
||||
var expect = new AsyncExpectation(options);
|
||||
expect.not = expect.addFilter(negatingFilter);
|
||||
|
||||
return expect;
|
||||
};
|
||||
|
||||
var negatingFilter = {
|
||||
selectComparisonFunc: function(matcher) {
|
||||
function defaultNegativeCompare() {
|
||||
return matcher.apply(this, arguments).then(function(result) {
|
||||
result.pass = !result.pass;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
return defaultNegativeCompare;
|
||||
},
|
||||
buildFailureMessage: function(result, matcherName, args, util) {
|
||||
if (result.message) {
|
||||
if (j$.isFunction_(result.message)) {
|
||||
return result.message();
|
||||
} else {
|
||||
return result.message;
|
||||
}
|
||||
}
|
||||
|
||||
args = args.slice();
|
||||
args.unshift(true);
|
||||
args.unshift(matcherName);
|
||||
return util.buildFailureMessage.apply(null, args);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return AsyncExpectation;
|
||||
};
|
||||
248
src/core/Env.js
248
src/core/Env.js
@@ -23,13 +23,62 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var currentSpec = null;
|
||||
var currentlyExecutingSuites = [];
|
||||
var currentDeclarationSuite = null;
|
||||
var throwOnExpectationFailure = false;
|
||||
var stopOnSpecFailure = false;
|
||||
var random = true;
|
||||
var seed = null;
|
||||
var handlingLoadErrors = true;
|
||||
var hasFailures = false;
|
||||
|
||||
/**
|
||||
* This represents the available options to configure Jasmine.
|
||||
* Options that are not provided will use their default values
|
||||
* @interface Configuration
|
||||
*/
|
||||
var config = {
|
||||
/**
|
||||
* Whether to randomize spec execution order
|
||||
* @name Configuration#random
|
||||
* @type Boolean
|
||||
* @default true
|
||||
*/
|
||||
random: true,
|
||||
/**
|
||||
* Seed to use as the basis of randomization.
|
||||
* Null causes the seed to be determined randomly at the start of execution.
|
||||
* @name Configuration#seed
|
||||
* @type function
|
||||
* @default null
|
||||
*/
|
||||
seed: null,
|
||||
/**
|
||||
* Whether to stop execution of the suite after the first spec failure
|
||||
* @name Configuration#failFast
|
||||
* @type Boolean
|
||||
* @default false
|
||||
*/
|
||||
failFast: false,
|
||||
/**
|
||||
* Whether to cause specs to only have one expectation failure.
|
||||
* @name Configuration#oneFailurePerSpec
|
||||
* @type Boolean
|
||||
* @default false
|
||||
*/
|
||||
oneFailurePerSpec: false,
|
||||
/**
|
||||
* Function to use to filter specs
|
||||
* @name Configuration#specFilter
|
||||
* @type function
|
||||
* @default true
|
||||
*/
|
||||
specFilter: function() {
|
||||
return true;
|
||||
},
|
||||
/**
|
||||
* Whether or not reporters should hide disabled specs from their output.
|
||||
* Currently only supported by Jasmine's HTMLReporter
|
||||
* @name Configuration#hideDisabled
|
||||
* @type Boolean
|
||||
* @default false
|
||||
*/
|
||||
hideDisabled: false
|
||||
};
|
||||
|
||||
var currentSuite = function() {
|
||||
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
||||
};
|
||||
@@ -62,10 +111,63 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
});
|
||||
}
|
||||
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
/**
|
||||
* Configure your jasmine environment
|
||||
* @name Env#configure
|
||||
* @argument {Configuration} configuration
|
||||
* @function
|
||||
*/
|
||||
this.configure = function(configuration) {
|
||||
if (configuration.specFilter) {
|
||||
config.specFilter = configuration.specFilter;
|
||||
}
|
||||
|
||||
if (configuration.hasOwnProperty('random')) {
|
||||
config.random = !!configuration.random;
|
||||
}
|
||||
|
||||
if (configuration.hasOwnProperty('seed')) {
|
||||
config.seed = configuration.seed;
|
||||
}
|
||||
|
||||
if (configuration.hasOwnProperty('failFast')) {
|
||||
config.failFast = configuration.failFast;
|
||||
}
|
||||
|
||||
if (configuration.hasOwnProperty('oneFailurePerSpec')) {
|
||||
config.oneFailurePerSpec = configuration.oneFailurePerSpec;
|
||||
}
|
||||
|
||||
if (configuration.hasOwnProperty('hideDisabled')) {
|
||||
config.hideDisabled = configuration.hideDisabled;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current configuration for your jasmine environment
|
||||
* @name Env#configuration
|
||||
* @function
|
||||
* @returns {Configuration}
|
||||
*/
|
||||
this.configuration = function() {
|
||||
var result = {};
|
||||
for (var property in config) {
|
||||
result[property] = config[property];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
Object.defineProperty(this, 'specFilter', {
|
||||
get: function() {
|
||||
self.deprecated('Getting specFilter directly from Env is deprecated, please check the specFilter option from `configuration`');
|
||||
return config.specFilter;
|
||||
},
|
||||
set: function(val) {
|
||||
self.deprecated('Setting specFilter directly on Env is deprecated, please use the specFilter option in `configure`');
|
||||
config.specFilter = val;
|
||||
}
|
||||
});
|
||||
|
||||
this.addSpyStrategy = function(name, fn) {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Custom spy strategies must be added in a before function or a spec');
|
||||
@@ -116,6 +218,19 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
var asyncExpectationFactory = function(actual, spec) {
|
||||
return j$.AsyncExpectation.factory({
|
||||
util: j$.matchersUtil,
|
||||
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
function addExpectationResult(passed, result) {
|
||||
return spec.addExpectationResult(passed, result);
|
||||
}
|
||||
};
|
||||
|
||||
var defaultResourcesForRunnable = function(id, parentRunnableId) {
|
||||
var resources = {spies: [], customEqualityTesters: [], customMatchers: {}, customSpyStrategies: {}};
|
||||
|
||||
@@ -174,35 +289,85 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var maximumSpecCallbackDepth = 20;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
|
||||
/**
|
||||
* Sets whether Jasmine should throw an Error when an expectation fails.
|
||||
* This causes a spec to only have one expectation failure.
|
||||
* @name Env#throwOnExpectationFailure
|
||||
* @function
|
||||
* @param {Boolean} value Whether to throw when a expectation fails
|
||||
* @deprecated Use the `oneFailurePerSpec` option with {@link Env#configure}
|
||||
*/
|
||||
this.throwOnExpectationFailure = function(value) {
|
||||
throwOnExpectationFailure = !!value;
|
||||
this.deprecated('Setting throwOnExpectationFailure directly on Env is deprecated, please use the oneFailurePerSpec option in `configure`');
|
||||
this.configure({oneFailurePerSpec: !!value});
|
||||
};
|
||||
|
||||
this.throwingExpectationFailures = function() {
|
||||
return throwOnExpectationFailure;
|
||||
this.deprecated('Getting throwingExpectationFailures directly from Env is deprecated, please check the oneFailurePerSpec option from `configuration`');
|
||||
return config.oneFailurePerSpec;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether to stop suite execution when a spec fails
|
||||
* @name Env#stopOnSpecFailure
|
||||
* @function
|
||||
* @param {Boolean} value Whether to stop suite execution when a spec fails
|
||||
* @deprecated Use the `failFast` option with {@link Env#configure}
|
||||
*/
|
||||
this.stopOnSpecFailure = function(value) {
|
||||
stopOnSpecFailure = !!value;
|
||||
this.deprecated('Setting stopOnSpecFailure directly is deprecated, please use the failFast option in `configure`');
|
||||
this.configure({failFast: !!value});
|
||||
};
|
||||
|
||||
this.stoppingOnSpecFailure = function() {
|
||||
return stopOnSpecFailure;
|
||||
this.deprecated('Getting stoppingOnSpecFailure directly from Env is deprecated, please check the failFast option from `configuration`');
|
||||
return config.failFast;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether to randomize test execution order
|
||||
* @name Env#randomizeTests
|
||||
* @function
|
||||
* @param {Boolean} value Whether to randomize execution order
|
||||
* @deprecated Use the `random` option with {@link Env#configure}
|
||||
*/
|
||||
this.randomizeTests = function(value) {
|
||||
random = !!value;
|
||||
this.deprecated('Setting randomizeTests directly is deprecated, please use the random option in `configure`');
|
||||
config.random = !!value;
|
||||
};
|
||||
|
||||
this.randomTests = function() {
|
||||
return random;
|
||||
this.deprecated('Getting randomTests directly from Env is deprecated, please check the random option from `configuration`');
|
||||
return config.random;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the random number seed for spec randomization
|
||||
* @name Env#seed
|
||||
* @function
|
||||
* @param {Number} value The seed value
|
||||
* @deprecated Use the `seed` option with {@link Env#configure}
|
||||
*/
|
||||
this.seed = function(value) {
|
||||
this.deprecated('Setting seed directly is deprecated, please use the seed option in `configure`');
|
||||
if (value) {
|
||||
seed = value;
|
||||
config.seed = value;
|
||||
}
|
||||
return seed;
|
||||
return config.seed;
|
||||
};
|
||||
|
||||
this.hidingDisabled = function(value) {
|
||||
this.deprecated('Getting hidingDisabled directly from Env is deprecated, please check the hideDisabled option from `configuration`');
|
||||
return config.hideDisabled;
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Env#hideDisabled
|
||||
* @function
|
||||
*/
|
||||
this.hideDisabled = function(value) {
|
||||
this.deprecated('Setting hideDisabled directly is deprecated, please use the hideDisabled option in `configure`');
|
||||
config.hideDisabled = !!value;
|
||||
};
|
||||
|
||||
this.deprecated = function(deprecation) {
|
||||
@@ -216,9 +381,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var queueRunnerFactory = function(options, args) {
|
||||
var failFast = false;
|
||||
if (options.isLeaf) {
|
||||
failFast = throwOnExpectationFailure;
|
||||
failFast = config.oneFailurePerSpec;
|
||||
} else if (!options.isReporter) {
|
||||
failFast = stopOnSpecFailure;
|
||||
failFast = config.failFast;
|
||||
}
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||
@@ -238,6 +403,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
id: getNextSuiteId(),
|
||||
description: 'Jasmine__TopLevel__Suite',
|
||||
expectationFactory: expectationFactory,
|
||||
asyncExpectationFactory: asyncExpectationFactory,
|
||||
expectationResultFactory: expectationResultFactory
|
||||
});
|
||||
defaultResourcesForRunnable(topSuite.id);
|
||||
@@ -332,8 +498,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
|
||||
var order = new j$.Order({
|
||||
random: random,
|
||||
seed: seed
|
||||
random: config.random,
|
||||
seed: config.seed
|
||||
});
|
||||
|
||||
var processor = new j$.TreeProcessor({
|
||||
@@ -363,7 +529,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return order.sort(node.children);
|
||||
},
|
||||
excludeNode: function(spec) {
|
||||
return !self.specFilter(spec);
|
||||
return !config.specFilter(spec);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -431,10 +597,22 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
reporter.addReporter(reporterToAdd);
|
||||
};
|
||||
|
||||
/**
|
||||
* Provide a fallback reporter if no other reporters have been specified.
|
||||
* @name Env#provideFallbackReporter
|
||||
* @function
|
||||
* @param {Reporter} reporterToAdd The reporter
|
||||
* @see custom_reporter
|
||||
*/
|
||||
this.provideFallbackReporter = function(reporterToAdd) {
|
||||
reporter.provideFallbackReporter(reporterToAdd);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear all registered reporters
|
||||
* @name Env#clearReporters
|
||||
* @function
|
||||
*/
|
||||
this.clearReporters = function() {
|
||||
reporter.clearReporters();
|
||||
};
|
||||
@@ -473,6 +651,10 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return spyRegistry.spyOnProperty.apply(spyRegistry, arguments);
|
||||
};
|
||||
|
||||
this.spyOnAllFunctions = function() {
|
||||
return spyRegistry.spyOnAllFunctions.apply(spyRegistry, arguments);
|
||||
};
|
||||
|
||||
this.createSpy = function(name, originalFn) {
|
||||
if (arguments.length === 1 && j$.isFunction_(name)) {
|
||||
originalFn = name;
|
||||
@@ -512,8 +694,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
description: description,
|
||||
parentSuite: currentDeclarationSuite,
|
||||
expectationFactory: expectationFactory,
|
||||
asyncExpectationFactory: asyncExpectationFactory,
|
||||
expectationResultFactory: expectationResultFactory,
|
||||
throwOnExpectationFailure: throwOnExpectationFailure
|
||||
throwOnExpectationFailure: config.oneFailurePerSpec
|
||||
});
|
||||
|
||||
return suite;
|
||||
@@ -605,6 +788,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
id: getNextSpecId(),
|
||||
beforeAndAfterFns: beforeAndAfterFns(suite),
|
||||
expectationFactory: expectationFactory,
|
||||
asyncExpectationFactory: asyncExpectationFactory,
|
||||
resultCallback: specResultCallback,
|
||||
getSpecName: function(spec) {
|
||||
return getSpecName(spec, suite);
|
||||
@@ -616,9 +800,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
userContext: function() { return suite.clonedSharedUserContext(); },
|
||||
queueableFn: {
|
||||
fn: fn,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
timeout: timeout || 0
|
||||
},
|
||||
throwOnExpectationFailure: throwOnExpectationFailure
|
||||
throwOnExpectationFailure: config.oneFailurePerSpec
|
||||
});
|
||||
|
||||
return spec;
|
||||
@@ -686,12 +870,20 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return currentRunnable().expect(actual);
|
||||
};
|
||||
|
||||
this.expectAsync = function(actual) {
|
||||
if (!currentRunnable()) {
|
||||
throw new Error('\'expectAsync\' was used when there was no current spec, this could be because an asynchronous test timed out');
|
||||
}
|
||||
|
||||
return currentRunnable().expectAsync(actual);
|
||||
};
|
||||
|
||||
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||
ensureIsNotNested('beforeEach');
|
||||
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
||||
currentDeclarationSuite.beforeEach({
|
||||
fn: beforeEachFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
timeout: timeout || 0
|
||||
});
|
||||
};
|
||||
|
||||
@@ -700,7 +892,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
||||
currentDeclarationSuite.beforeAll({
|
||||
fn: beforeAllFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
timeout: timeout || 0
|
||||
});
|
||||
};
|
||||
|
||||
@@ -710,7 +902,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
afterEachFunction.isCleanup = true;
|
||||
currentDeclarationSuite.afterEach({
|
||||
fn: afterEachFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
timeout: timeout || 0
|
||||
});
|
||||
};
|
||||
|
||||
@@ -719,7 +911,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
||||
currentDeclarationSuite.afterAll({
|
||||
fn: afterAllFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
timeout: timeout || 0
|
||||
});
|
||||
};
|
||||
|
||||
@@ -758,7 +950,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
error: error && error.message ? error : null
|
||||
});
|
||||
|
||||
if (self.throwingExpectationFailures()) {
|
||||
if (config.oneFailurePerSpec) {
|
||||
throw new Error(message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,6 +7,8 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
||||
|
||||
if (error.name && error.message) {
|
||||
message += error.name + ': ' + error.message;
|
||||
} else if (error.message) {
|
||||
message += error.message;
|
||||
} else {
|
||||
message += error.toString() + ' thrown';
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ getJasmineRequireObj().Expectation = function(j$) {
|
||||
Expectation.prototype.processResult = function(result, name, expected, args) {
|
||||
var message = this.buildMessage(result, name, args);
|
||||
|
||||
if (expected.length == 1) {
|
||||
if (expected.length === 1) {
|
||||
expected = expected[0];
|
||||
}
|
||||
|
||||
@@ -58,14 +58,13 @@ getJasmineRequireObj().Expectation = function(j$) {
|
||||
};
|
||||
|
||||
Expectation.prototype.buildMessage = function(result, name, args) {
|
||||
var util = this.util,
|
||||
msg;
|
||||
var util = this.util;
|
||||
|
||||
if (result.pass) {
|
||||
return '';
|
||||
}
|
||||
|
||||
msg = this.filters.buildFailureMessage(result, name, args, util, defaultMessage);
|
||||
var msg = this.filters.buildFailureMessage(result, name, args, util, defaultMessage);
|
||||
return this.filters.modifyFailureMessage(msg || defaultMessage());
|
||||
|
||||
function defaultMessage() {
|
||||
|
||||
@@ -45,7 +45,9 @@ getJasmineRequireObj().buildExpectationResult = function() {
|
||||
|
||||
var error = options.error;
|
||||
if (!error) {
|
||||
if (options.stack) {
|
||||
if (options.errorForStack) {
|
||||
error = options.errorForStack;
|
||||
} else if (options.stack) {
|
||||
error = options;
|
||||
} else {
|
||||
try {
|
||||
|
||||
@@ -5,26 +5,29 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
function once(fn) {
|
||||
var called = false;
|
||||
return function() {
|
||||
return function(arg) {
|
||||
if (!called) {
|
||||
called = true;
|
||||
fn.apply(null, arguments);
|
||||
// Direct call using single parameter, because cleanup/next does not need more
|
||||
fn(arg);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
function emptyFn() {}
|
||||
|
||||
function QueueRunner(attrs) {
|
||||
var queueableFns = attrs.queueableFns || [];
|
||||
this.queueableFns = queueableFns.concat(attrs.cleanupFns || []);
|
||||
this.firstCleanupIx = queueableFns.length;
|
||||
this.onComplete = attrs.onComplete || function() {};
|
||||
this.onComplete = attrs.onComplete || emptyFn;
|
||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||
this.onException = attrs.onException || function() {};
|
||||
this.onException = attrs.onException || emptyFn;
|
||||
this.userContext = attrs.userContext || new j$.UserContext();
|
||||
this.timeout = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
||||
this.fail = attrs.fail || function() {};
|
||||
this.globalErrors = attrs.globalErrors || { pushListener: function() {}, popListener: function() {} };
|
||||
this.fail = attrs.fail || emptyFn;
|
||||
this.globalErrors = attrs.globalErrors || { pushListener: emptyFn, popListener: emptyFn };
|
||||
this.completeOnFirstError = !!attrs.completeOnFirstError;
|
||||
this.errored = false;
|
||||
|
||||
@@ -66,7 +69,9 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
next(error);
|
||||
},
|
||||
cleanup = once(function cleanup() {
|
||||
self.clearTimeout(timeoutId);
|
||||
if (timeoutId !== void 0) {
|
||||
self.clearTimeout(timeoutId);
|
||||
}
|
||||
self.globalErrors.popListener(handleError);
|
||||
}),
|
||||
next = once(function next(err) {
|
||||
@@ -105,12 +110,16 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
self.globalErrors.pushListener(handleError);
|
||||
|
||||
if (queueableFn.timeout) {
|
||||
if (queueableFn.timeout !== undefined) {
|
||||
var timeoutInterval = queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL;
|
||||
timeoutId = self.setTimeout(function() {
|
||||
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
||||
var error = new Error(
|
||||
'Timeout - Async callback was not invoked within ' + timeoutInterval + 'ms ' +
|
||||
(queueableFn.timeout ? '(custom timeout)' : '(set by jasmine.DEFAULT_TIMEOUT_INTERVAL)')
|
||||
);
|
||||
onException(error);
|
||||
next();
|
||||
}, queueableFn.timeout());
|
||||
}, timeoutInterval);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -159,7 +168,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.errored = result.errored;
|
||||
self.errored = self.errored || result.errored;
|
||||
|
||||
if (this.completeOnFirstError && result.errored) {
|
||||
this.skipToCleanup(iterativeIndex);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
getJasmineRequireObj().Spec = function(j$) {
|
||||
function Spec(attrs) {
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.resultCallback = attrs.resultCallback || function() {};
|
||||
this.id = attrs.id;
|
||||
this.description = attrs.description || '';
|
||||
@@ -57,6 +58,10 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
return this.expectationFactory(actual, this);
|
||||
};
|
||||
|
||||
Spec.prototype.expectAsync = function(actual) {
|
||||
return this.asyncExpectationFactory(actual, this);
|
||||
};
|
||||
|
||||
Spec.prototype.execute = function(onComplete, excluded) {
|
||||
var self = this;
|
||||
|
||||
|
||||
@@ -120,6 +120,23 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
||||
return spy;
|
||||
};
|
||||
|
||||
this.spyOnAllFunctions = function(obj) {
|
||||
if (j$.util.isUndefined(obj)) {
|
||||
throw new Error('spyOnAllFunctions could not find an object to spy upon');
|
||||
}
|
||||
|
||||
for (var prop in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] instanceof Function) {
|
||||
var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
||||
if ((descriptor.writable || descriptor.set) && descriptor.configurable) {
|
||||
this.spyOn(obj, prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
this.clearSpies = function() {
|
||||
var spies = currentSpies();
|
||||
for (var i = spies.length - 1; i >= 0; i--) {
|
||||
|
||||
@@ -5,6 +5,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
this.parentSuite = attrs.parentSuite;
|
||||
this.description = attrs.description;
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.expectationResultFactory = attrs.expectationResultFactory;
|
||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||
|
||||
@@ -37,6 +38,10 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
return this.expectationFactory(actual, this);
|
||||
};
|
||||
|
||||
Suite.prototype.expectAsync = function(actual) {
|
||||
return this.asyncExpectationFactory(actual, this);
|
||||
};
|
||||
|
||||
Suite.prototype.getFullName = function() {
|
||||
var fullName = [];
|
||||
for (var parentSuite = this; parentSuite; parentSuite = parentSuite.parentSuite) {
|
||||
|
||||
@@ -174,8 +174,11 @@ getJasmineRequireObj().TreeProcessor = function() {
|
||||
|
||||
queueRunnerFactory({
|
||||
onComplete: function () {
|
||||
var args = Array.prototype.slice.call(arguments, [0]);
|
||||
node.cleanupBeforeAfter();
|
||||
nodeComplete(node, node.getResult(), done);
|
||||
nodeComplete(node, node.getResult(), function() {
|
||||
done.apply(undefined, args);
|
||||
});
|
||||
},
|
||||
queueableFns: [onStart].concat(wrapChildren(node, segmentNumber)),
|
||||
userContext: node.sharedUserContext(),
|
||||
|
||||
@@ -120,7 +120,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
};
|
||||
|
||||
j$.isPromise = function(obj) {
|
||||
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
||||
return typeof jasmineGlobal.Promise !== 'undefined' && !!obj && obj.constructor === jasmineGlobal.Promise;
|
||||
};
|
||||
|
||||
j$.isPromiseLike = function(obj) {
|
||||
return !!obj && j$.isFunction_(obj.then);
|
||||
};
|
||||
|
||||
j$.fnNameFor = function(func) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
getJasmineRequireObj().toBe = function() {
|
||||
getJasmineRequireObj().toBe = function(j$) {
|
||||
/**
|
||||
* {@link expect} the actual value to be `===` to the expected value.
|
||||
* @function
|
||||
@@ -7,12 +7,20 @@ getJasmineRequireObj().toBe = function() {
|
||||
* @example
|
||||
* expect(thing).toBe(realThing);
|
||||
*/
|
||||
function toBe() {
|
||||
function toBe(util) {
|
||||
var tip = ' Tip: To check for deep equality, use .toEqual() instead of .toBe().';
|
||||
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
return {
|
||||
pass: actual === expected
|
||||
var result = {
|
||||
pass: actual === expected,
|
||||
};
|
||||
|
||||
if (typeof expected === 'object') {
|
||||
result.message = util.buildFailureMessage('toBe', result.pass, actual, expected) + tip;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ var getJasmineRequireObj = (function (jasmineGlobal) {
|
||||
j$.ExceptionFormatter = jRequire.ExceptionFormatter(j$);
|
||||
j$.ExpectationFilterChain = jRequire.ExpectationFilterChain();
|
||||
j$.Expectation = jRequire.Expectation(j$);
|
||||
j$.AsyncExpectation = jRequire.AsyncExpectation(j$);
|
||||
j$.buildExpectationResult = jRequire.buildExpectationResult();
|
||||
j$.JsApiReporter = jRequire.JsApiReporter();
|
||||
j$.matchersUtil = jRequire.matchersUtil(j$);
|
||||
|
||||
@@ -167,6 +167,25 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
||||
return env.expect(actual);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an asynchronous expectation for a spec. Note that the matchers
|
||||
* that are provided by an asynchronous expectation all return promises
|
||||
* which must be either returned from the spec or waited for using `await`
|
||||
* in order for Jasmine to associate them with the correct spec.
|
||||
* @name expectAsync
|
||||
* @function
|
||||
* @global
|
||||
* @param {Object} actual - Actual computed value to test expectations against.
|
||||
* @return {async-matchers}
|
||||
* @example
|
||||
* await expectAsync(somePromise).toBeResolved();
|
||||
* @example
|
||||
* return expectAsync(somePromise).toBeResolved();
|
||||
*/
|
||||
expectAsync: function(actual) {
|
||||
return env.expectAsync(actual);
|
||||
},
|
||||
|
||||
/**
|
||||
* Mark a spec as pending, expectation results will be ignored.
|
||||
* @name pending
|
||||
@@ -216,6 +235,18 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
||||
return env.spyOnProperty(obj, methodName, accessType);
|
||||
},
|
||||
|
||||
/**
|
||||
* Installs spies on all writable and configurable properties of an object.
|
||||
* @name spyOnAllFunctions
|
||||
* @function
|
||||
* @global
|
||||
* @param {Object} obj - The object upon which to install the {@link Spy}s
|
||||
* @returns {Object} the spied object
|
||||
*/
|
||||
spyOnAllFunctions: function(obj) {
|
||||
return env.spyOnAllFunctions(obj);
|
||||
},
|
||||
|
||||
jsApiReporter: new jasmine.JsApiReporter({
|
||||
timer: new jasmine.Timer()
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user