Merge branch 'expose-property' of https://github.com/johnjbarton/jasmine
* Merges #1820 from @johnjbarton
This commit is contained in:
@@ -144,6 +144,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
||||
'toBeUndefined',
|
||||
'toContain',
|
||||
'toEqual',
|
||||
'toHaveSize',
|
||||
'toHaveBeenCalled',
|
||||
'toHaveBeenCalledBefore',
|
||||
'toHaveBeenCalledTimes',
|
||||
@@ -314,6 +315,24 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
);
|
||||
};
|
||||
|
||||
j$.isWeakMap = function(obj) {
|
||||
return (
|
||||
obj !== null &&
|
||||
typeof obj !== 'undefined' &&
|
||||
typeof jasmineGlobal.WeakMap !== 'undefined' &&
|
||||
obj.constructor === jasmineGlobal.WeakMap
|
||||
);
|
||||
};
|
||||
|
||||
j$.isDataView = function(obj) {
|
||||
return (
|
||||
obj !== null &&
|
||||
typeof obj !== 'undefined' &&
|
||||
typeof jasmineGlobal.DataView !== 'undefined' &&
|
||||
obj.constructor === jasmineGlobal.DataView
|
||||
);
|
||||
};
|
||||
|
||||
j$.isPromise = function(obj) {
|
||||
return (
|
||||
typeof jasmineGlobal.Promise !== 'undefined' &&
|
||||
@@ -697,6 +716,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
|
||||
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
|
||||
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
||||
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
||||
*/
|
||||
this.result = {
|
||||
id: this.id,
|
||||
@@ -706,7 +726,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
passedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
pendingReason: '',
|
||||
duration: null
|
||||
duration: null,
|
||||
properties: null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -723,6 +744,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
Spec.prototype.setSpecProperty = function(key, value) {
|
||||
this.result.properties = this.result.properties || {};
|
||||
this.result.properties[key] = value;
|
||||
};
|
||||
|
||||
Spec.prototype.expect = function(actual) {
|
||||
return this.expectationFactory(actual, this);
|
||||
};
|
||||
@@ -2049,6 +2075,40 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return spec;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets a user-defined property that will be provided to reporters as part of {@link SpecResult#properties}
|
||||
* @name Env#setSpecProperty
|
||||
* @since 3.6.0
|
||||
* @function
|
||||
* @param {String} key The name of the property
|
||||
* @param {*} value The value of the property
|
||||
*/
|
||||
this.setSpecProperty = function(key, value) {
|
||||
if (!currentRunnable() || currentRunnable() == currentSuite()) {
|
||||
throw new Error(
|
||||
"'setSpecProperty' was used when there was no current spec"
|
||||
);
|
||||
}
|
||||
currentRunnable().setSpecProperty(key, value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets a user-defined property that will be provided to reporters as part of {@link SuiteResult#properties}
|
||||
* @name Env#setSuiteProperty
|
||||
* @since 3.6.0
|
||||
* @function
|
||||
* @param {String} key The name of the property
|
||||
* @param {*} value The value of the property
|
||||
*/
|
||||
this.setSuiteProperty = function(key, value) {
|
||||
if (!currentSuite()) {
|
||||
throw new Error(
|
||||
"'setSuiteProperty' was used when there was no current suite"
|
||||
);
|
||||
}
|
||||
currentSuite().setSuiteProperty(key, value);
|
||||
};
|
||||
|
||||
this.expect = function(actual) {
|
||||
if (!currentRunnable()) {
|
||||
throw new Error(
|
||||
@@ -4053,6 +4113,32 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
||||
return GlobalErrors;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().toBePending = function(j$) {
|
||||
/**
|
||||
* Expect a promise to be pending, ie. the promise is neither resolved nor rejected.
|
||||
* @function
|
||||
* @async
|
||||
* @name async-matchers#toBePending
|
||||
* @since 3.5.1 (should this be the next version or the version when it was added?)
|
||||
* @example
|
||||
* await expectAsync(aPromise).toBePending();
|
||||
*/
|
||||
return function toBePending() {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
if (!j$.isPromiseLike(actual)) {
|
||||
throw new Error('Expected toBePending to be called on a promise.');
|
||||
}
|
||||
var want = {};
|
||||
return Promise.race([actual, Promise.resolve(want)]).then(
|
||||
function(got) { return {pass: want === got}; },
|
||||
function() { return {pass: false}; }
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
getJasmineRequireObj().toBeRejected = function(j$) {
|
||||
/**
|
||||
* Expect a promise to be rejected.
|
||||
@@ -5086,6 +5172,7 @@ getJasmineRequireObj().ObjectPath = function(j$) {
|
||||
|
||||
getJasmineRequireObj().requireAsyncMatchers = function(jRequire, j$) {
|
||||
var availableMatchers = [
|
||||
'toBePending',
|
||||
'toBeResolved',
|
||||
'toBeRejected',
|
||||
'toBeResolvedTo',
|
||||
@@ -5862,6 +5949,49 @@ getJasmineRequireObj().toHaveClass = function(j$) {
|
||||
return toHaveClass;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().toHaveSize = function(j$) {
|
||||
/**
|
||||
* {@link expect} the actual size to be equal to the expected, using array-like length or object keys size.
|
||||
* @function
|
||||
* @name matchers#toHaveSize
|
||||
* @since 3.5.1
|
||||
* @param {Object} expected - Expected size
|
||||
* @example
|
||||
* array = [1,2];
|
||||
* expect(array).toHaveSize(2);
|
||||
*/
|
||||
function toHaveSize() {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
var result = {
|
||||
pass: false
|
||||
};
|
||||
|
||||
if (j$.isA_('WeakSet', actual) || j$.isWeakMap(actual) || j$.isDataView(actual)) {
|
||||
throw new Error('Cannot get size of ' + actual + '.');
|
||||
}
|
||||
|
||||
if (j$.isSet(actual) || j$.isMap(actual)) {
|
||||
result.pass = actual.size === expected;
|
||||
} else if (isLength(actual.length)) {
|
||||
result.pass = actual.length === expected;
|
||||
} else {
|
||||
result.pass = Object.keys(actual).length === expected;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
||||
function isLength(value) {
|
||||
return (typeof value == 'number') && value > -1 && value % 1 === 0 && value <= MAX_SAFE_INTEGER;
|
||||
}
|
||||
|
||||
return toHaveSize;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().toMatch = function(j$) {
|
||||
|
||||
var getErrorMsg = j$.formatErrorMsg('<toMatch>', 'expect(<expectation>).toMatch(<string> || <regexp>)');
|
||||
@@ -7163,6 +7293,30 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
||||
return env.afterAll.apply(env, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets a user-defined property that will be provided to reporters as part of {@link SpecResult#properties}
|
||||
* @name Env#setSpecProperty
|
||||
* @since 3.6.0
|
||||
* @function
|
||||
* @param {String} key The name of the property
|
||||
* @param {*} value The value of the property
|
||||
*/
|
||||
setSpecProperty: function(key, value) {
|
||||
return env.setSpecProperty(key, value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets a user-defined property that will be provided to reporters as part of {@link SuiteResult#properties}
|
||||
* @name Env#setSuiteProperty
|
||||
* @since 3.6.0
|
||||
* @function
|
||||
* @param {String} key The name of the property
|
||||
* @param {*} value The value of the property
|
||||
*/
|
||||
setSuiteProperty: function(key, value) {
|
||||
return env.setSuiteProperty(key, value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create an expectation for a spec.
|
||||
* @name expect
|
||||
@@ -8259,6 +8413,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred on this suite.
|
||||
* @property {String} status - Once the suite has completed, this string represents the pass/fail status of this suite.
|
||||
* @property {number} duration - The time in ms for Suite execution, including any before/afterAll, before/afterEach.
|
||||
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSuiteProperty}
|
||||
*/
|
||||
this.result = {
|
||||
id: this.id,
|
||||
@@ -8266,10 +8421,16 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
fullName: this.getFullName(),
|
||||
failedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
duration: null
|
||||
duration: null,
|
||||
properties: null
|
||||
};
|
||||
}
|
||||
|
||||
Suite.prototype.setSuiteProperty = function(key, value) {
|
||||
this.result.properties = this.result.properties || {};
|
||||
this.result.properties[key] = value;
|
||||
};
|
||||
|
||||
Suite.prototype.expect = function(actual) {
|
||||
return this.expectationFactory(actual, this);
|
||||
};
|
||||
@@ -8724,5 +8885,5 @@ getJasmineRequireObj().UserContext = function(j$) {
|
||||
};
|
||||
|
||||
getJasmineRequireObj().version = function() {
|
||||
return '3.5.0';
|
||||
return '3.5.1';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user