jasmine-core 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/jasmine-core/jasmine.js +112 -23
- package/lib/jasmine-core.js +12 -9
- package/package.json +5 -4
|
@@ -809,14 +809,6 @@ getJasmineRequireObj().Spec = function(j$) {
|
|
|
809
809
|
this.result.properties[key] = value;
|
|
810
810
|
};
|
|
811
811
|
|
|
812
|
-
Spec.prototype.expect = function(actual) {
|
|
813
|
-
return this.expectationFactory(actual, this);
|
|
814
|
-
};
|
|
815
|
-
|
|
816
|
-
Spec.prototype.expectAsync = function(actual) {
|
|
817
|
-
return this.asyncExpectationFactory(actual, this);
|
|
818
|
-
};
|
|
819
|
-
|
|
820
812
|
Spec.prototype.execute = function(
|
|
821
813
|
queueRunnerFactory,
|
|
822
814
|
onComplete,
|
|
@@ -1401,6 +1393,49 @@ getJasmineRequireObj().Env = function(j$) {
|
|
|
1401
1393
|
}
|
|
1402
1394
|
};
|
|
1403
1395
|
|
|
1396
|
+
const handleThrowUnlessFailure = function(passed, result) {
|
|
1397
|
+
if (!passed) {
|
|
1398
|
+
/**
|
|
1399
|
+
* @interface
|
|
1400
|
+
* @name ThrowUnlessFailure
|
|
1401
|
+
* @extends Error
|
|
1402
|
+
* @description Represents a failure of an expectation evaluated with
|
|
1403
|
+
* {@link throwUnless}. Properties of this error are a subset of the
|
|
1404
|
+
* properties of {@link Expectation} and have the same values.
|
|
1405
|
+
* @property {String} matcherName - The name of the matcher that was executed for this expectation.
|
|
1406
|
+
* @property {String} message - The failure message for the expectation.
|
|
1407
|
+
* @property {Boolean} passed - Whether the expectation passed or failed.
|
|
1408
|
+
* @property {Object} expected - If the expectation failed, what was the expected value.
|
|
1409
|
+
* @property {Object} actual - If the expectation failed, what actual value was produced.
|
|
1410
|
+
*/
|
|
1411
|
+
const error = new Error(result.message);
|
|
1412
|
+
error.passed = result.passed;
|
|
1413
|
+
error.message = result.message;
|
|
1414
|
+
error.expected = result.expected;
|
|
1415
|
+
error.actual = result.actual;
|
|
1416
|
+
error.matcherName = result.matcherName;
|
|
1417
|
+
throw error;
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1421
|
+
const throwUnlessFactory = function(actual, spec) {
|
|
1422
|
+
return j$.Expectation.factory({
|
|
1423
|
+
matchersUtil: runableResources.makeMatchersUtil(),
|
|
1424
|
+
customMatchers: runableResources.customMatchers(),
|
|
1425
|
+
actual: actual,
|
|
1426
|
+
addExpectationResult: handleThrowUnlessFailure
|
|
1427
|
+
});
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
const throwUnlessAsyncFactory = function(actual, spec) {
|
|
1431
|
+
return j$.Expectation.asyncFactory({
|
|
1432
|
+
matchersUtil: runableResources.makeMatchersUtil(),
|
|
1433
|
+
customAsyncMatchers: runableResources.customAsyncMatchers(),
|
|
1434
|
+
actual: actual,
|
|
1435
|
+
addExpectationResult: handleThrowUnlessFailure
|
|
1436
|
+
});
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1404
1439
|
// TODO: Unify recordLateError with recordLateExpectation? The extra
|
|
1405
1440
|
// diagnostic info added by the latter is probably useful in most cases.
|
|
1406
1441
|
function recordLateError(error) {
|
|
@@ -1904,23 +1939,37 @@ getJasmineRequireObj().Env = function(j$) {
|
|
|
1904
1939
|
};
|
|
1905
1940
|
|
|
1906
1941
|
this.expect = function(actual) {
|
|
1907
|
-
|
|
1942
|
+
const runable = runner.currentRunable();
|
|
1943
|
+
|
|
1944
|
+
if (!runable) {
|
|
1908
1945
|
throw new Error(
|
|
1909
1946
|
"'expect' was used when there was no current spec, this could be because an asynchronous test timed out"
|
|
1910
1947
|
);
|
|
1911
1948
|
}
|
|
1912
1949
|
|
|
1913
|
-
return
|
|
1950
|
+
return runable.expectationFactory(actual, runable);
|
|
1914
1951
|
};
|
|
1915
1952
|
|
|
1916
1953
|
this.expectAsync = function(actual) {
|
|
1917
|
-
|
|
1954
|
+
const runable = runner.currentRunable();
|
|
1955
|
+
|
|
1956
|
+
if (!runable) {
|
|
1918
1957
|
throw new Error(
|
|
1919
1958
|
"'expectAsync' was used when there was no current spec, this could be because an asynchronous test timed out"
|
|
1920
1959
|
);
|
|
1921
1960
|
}
|
|
1922
1961
|
|
|
1923
|
-
return
|
|
1962
|
+
return runable.asyncExpectationFactory(actual, runable);
|
|
1963
|
+
};
|
|
1964
|
+
|
|
1965
|
+
this.throwUnless = function(actual) {
|
|
1966
|
+
const runable = runner.currentRunable();
|
|
1967
|
+
return throwUnlessFactory(actual, runable);
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
this.throwUnlessAsync = function(actual) {
|
|
1971
|
+
const runable = runner.currentRunable();
|
|
1972
|
+
return throwUnlessAsyncFactory(actual, runable);
|
|
1924
1973
|
};
|
|
1925
1974
|
|
|
1926
1975
|
this.beforeEach = function(beforeEachFunction, timeout) {
|
|
@@ -3531,7 +3580,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|
|
3531
3580
|
lines.unshift(stackTrace.message);
|
|
3532
3581
|
}
|
|
3533
3582
|
|
|
3534
|
-
if (error.cause) {
|
|
3583
|
+
if (error.cause && error.cause instanceof Error) {
|
|
3535
3584
|
const substack = this.stack_(error.cause, {
|
|
3536
3585
|
messageHandling: 'require'
|
|
3537
3586
|
});
|
|
@@ -3566,7 +3615,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|
|
3566
3615
|
const result = {};
|
|
3567
3616
|
let empty = true;
|
|
3568
3617
|
|
|
3569
|
-
for (const prop
|
|
3618
|
+
for (const prop of Object.keys(error)) {
|
|
3570
3619
|
if (ignoredProperties.includes(prop)) {
|
|
3571
3620
|
continue;
|
|
3572
3621
|
}
|
|
@@ -8232,6 +8281,54 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
|
|
8232
8281
|
return env.expectAsync(actual);
|
|
8233
8282
|
},
|
|
8234
8283
|
|
|
8284
|
+
/**
|
|
8285
|
+
* Create an asynchronous expectation for a spec and throw an error if it fails.
|
|
8286
|
+
*
|
|
8287
|
+
* This is intended to allow Jasmine matchers to be used with tools like
|
|
8288
|
+
* testing-library's `waitFor`, which expect matcher failures to throw
|
|
8289
|
+
* exceptions and not trigger a spec failure if the exception is caught.
|
|
8290
|
+
* It can also be used to integration-test custom matchers.
|
|
8291
|
+
*
|
|
8292
|
+
* If the resulting expectation fails, a {@link ThrowUnlessFailure} will be
|
|
8293
|
+
* thrown. A failed expectation will not result in a spec failure unless the
|
|
8294
|
+
* exception propagates back to Jasmine, either via the call stack or via
|
|
8295
|
+
* the global unhandled exception/unhandled promise rejection events.
|
|
8296
|
+
* @name throwUnlessAsync
|
|
8297
|
+
* @since 5.1.0
|
|
8298
|
+
* @function
|
|
8299
|
+
* @param actual
|
|
8300
|
+
* @global
|
|
8301
|
+
* @param {Object} actual - Actual computed value to test expectations against.
|
|
8302
|
+
* @return {matchers}
|
|
8303
|
+
*/
|
|
8304
|
+
throwUnlessAsync: function(actual) {
|
|
8305
|
+
return env.throwUnless(actual);
|
|
8306
|
+
},
|
|
8307
|
+
|
|
8308
|
+
/**
|
|
8309
|
+
* Create an expectation for a spec and throw an error if it fails.
|
|
8310
|
+
*
|
|
8311
|
+
* This is intended to allow Jasmine matchers to be used with tools like
|
|
8312
|
+
* testing-library's `waitFor`, which expect matcher failures to throw
|
|
8313
|
+
* exceptions and not trigger a spec failure if the exception is caught.
|
|
8314
|
+
* It can also be used to integration-test custom matchers.
|
|
8315
|
+
*
|
|
8316
|
+
* If the resulting expectation fails, a {@link ThrowUnlessFailure} will be
|
|
8317
|
+
* thrown. A failed expectation will not result in a spec failure unless the
|
|
8318
|
+
* exception propagates back to Jasmine, either via the call stack or via
|
|
8319
|
+
* the global unhandled exception/unhandled promise rejection events.
|
|
8320
|
+
* @name throwUnless
|
|
8321
|
+
* @since 5.1.0
|
|
8322
|
+
* @function
|
|
8323
|
+
* @param actual
|
|
8324
|
+
* @global
|
|
8325
|
+
* @param {Object} actual - Actual computed value to test expectations against.
|
|
8326
|
+
* @return {matchers}
|
|
8327
|
+
*/
|
|
8328
|
+
throwUnless: function(actual) {
|
|
8329
|
+
return env.throwUnless(actual);
|
|
8330
|
+
},
|
|
8331
|
+
|
|
8235
8332
|
/**
|
|
8236
8333
|
* Mark a spec as pending, expectation results will be ignored.
|
|
8237
8334
|
* @name pending
|
|
@@ -9755,14 +9852,6 @@ getJasmineRequireObj().Suite = function(j$) {
|
|
|
9755
9852
|
this.result.properties[key] = value;
|
|
9756
9853
|
};
|
|
9757
9854
|
|
|
9758
|
-
Suite.prototype.expect = function(actual) {
|
|
9759
|
-
return this.expectationFactory(actual, this);
|
|
9760
|
-
};
|
|
9761
|
-
|
|
9762
|
-
Suite.prototype.expectAsync = function(actual) {
|
|
9763
|
-
return this.asyncExpectationFactory(actual, this);
|
|
9764
|
-
};
|
|
9765
|
-
|
|
9766
9855
|
Suite.prototype.getFullName = function() {
|
|
9767
9856
|
const fullName = [];
|
|
9768
9857
|
for (
|
|
@@ -10713,5 +10802,5 @@ getJasmineRequireObj().UserContext = function(j$) {
|
|
|
10713
10802
|
};
|
|
10714
10803
|
|
|
10715
10804
|
getJasmineRequireObj().version = function() {
|
|
10716
|
-
return '5.
|
|
10805
|
+
return '5.1.0';
|
|
10717
10806
|
};
|
package/lib/jasmine-core.js
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
const jasmineRequire = require('./jasmine-core/jasmine.js');
|
|
7
7
|
module.exports = jasmineRequire;
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const boot = (function() {
|
|
10
10
|
let jasmine, jasmineInterface;
|
|
11
11
|
|
|
12
|
-
return function bootWithoutGlobals() {
|
|
13
|
-
if (!jasmineInterface) {
|
|
12
|
+
return function bootWithoutGlobals(reinitialize) {
|
|
13
|
+
if (!jasmineInterface || reinitialize === true) {
|
|
14
14
|
jasmine = jasmineRequire.core(jasmineRequire);
|
|
15
15
|
const env = jasmine.getEnv({ suppressLoadErrors: true });
|
|
16
16
|
jasmineInterface = jasmineRequire.interface(jasmine, env);
|
|
@@ -22,12 +22,14 @@ const bootOnce = (function() {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
|
|
25
|
-
* If boot is called multiple times, the same object is returned every time
|
|
25
|
+
* If boot is called multiple times, the same object is returned every time
|
|
26
|
+
* unless true is passed.
|
|
27
|
+
* @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
|
|
26
28
|
* @type {function}
|
|
27
29
|
* @return {jasmine}
|
|
28
30
|
*/
|
|
29
|
-
module.exports.boot = function() {
|
|
30
|
-
const {jasmine, jasmineInterface} =
|
|
31
|
+
module.exports.boot = function(reinitialize) {
|
|
32
|
+
const {jasmine, jasmineInterface} = boot(reinitialize);
|
|
31
33
|
|
|
32
34
|
for (const k in jasmineInterface) {
|
|
33
35
|
global[k] = jasmineInterface[k];
|
|
@@ -39,13 +41,14 @@ module.exports.boot = function() {
|
|
|
39
41
|
/**
|
|
40
42
|
* Boots a copy of Jasmine and returns an object containing the properties
|
|
41
43
|
* that would normally be added to the global object. If noGlobals is called
|
|
42
|
-
* multiple times, the same object is returned every time.
|
|
44
|
+
* multiple times, the same object is returned every time unless true is passed.
|
|
43
45
|
*
|
|
46
|
+
* @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
|
|
44
47
|
* @example
|
|
45
48
|
* const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
|
|
46
49
|
*/
|
|
47
|
-
module.exports.noGlobals = function() {
|
|
48
|
-
const {jasmineInterface} =
|
|
50
|
+
module.exports.noGlobals = function(reinitialize) {
|
|
51
|
+
const {jasmineInterface} = boot(reinitialize);
|
|
49
52
|
return jasmineInterface;
|
|
50
53
|
};
|
|
51
54
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jasmine-core",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/jasmine/jasmine.git"
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"grunt-contrib-concat": "^2.0.0",
|
|
44
44
|
"grunt-css-url-embed": "^1.11.1",
|
|
45
45
|
"grunt-sass": "^3.0.2",
|
|
46
|
-
"jasmine": "5.0.0
|
|
47
|
-
"jasmine-browser-runner": "
|
|
46
|
+
"jasmine": "^5.0.0",
|
|
47
|
+
"jasmine-browser-runner": "github:jasmine/jasmine-browser-runner",
|
|
48
48
|
"jsdom": "^22.0.0",
|
|
49
49
|
"load-grunt-tasks": "^5.1.0",
|
|
50
50
|
"prettier": "1.17.1",
|
|
@@ -97,7 +97,8 @@
|
|
|
97
97
|
],
|
|
98
98
|
"space-before-blocks": "error",
|
|
99
99
|
"no-eval": "error",
|
|
100
|
-
"no-var": "error"
|
|
100
|
+
"no-var": "error",
|
|
101
|
+
"no-debugger": "error"
|
|
101
102
|
}
|
|
102
103
|
},
|
|
103
104
|
"browserslist": [
|