Compare commits
15 Commits
v6.0.1
..
6e52b971cd
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e52b971cd | |||
| 0a5acd99cb | |||
| f7132d98cd | |||
| 3de4512681 | |||
| 4bf333ed38 | |||
| 4f5ef7c2d7 | |||
| 5de03beea1 | |||
| 42baa422b3 | |||
| 6af5d24b3b | |||
| b88ce2d49f | |||
| c216ae1d13 | |||
| 319776d241 | |||
| 1d0718dc2f | |||
| 929694310e | |||
| 4db18aafce |
@@ -30,7 +30,7 @@ Microsoft Edge) as well as Node.
|
|||||||
| Environment | Supported versions |
|
| Environment | Supported versions |
|
||||||
|-------------------|----------------------------------|
|
|-------------------|----------------------------------|
|
||||||
| Node | 20, 22, 24 |
|
| Node | 20, 22, 24 |
|
||||||
| Safari | 16*, 17*, 26* |
|
| Safari | 26* |
|
||||||
| Chrome | Evergreen |
|
| Chrome | Evergreen |
|
||||||
| Firefox | Evergreen, 102*, 115*, 128*, 140 |
|
| Firefox | Evergreen, 102*, 115*, 128*, 140 |
|
||||||
| Edge | Evergreen |
|
| Edge | Evergreen |
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* Maximum number of characters to display when pretty printing objects.
|
* Maximum number of characters to display when pretty printing objects.
|
||||||
* Characters past this number will be ellipised.
|
* Characters past this number will be ellipised.
|
||||||
* @name jasmine.MAX_PRETTY_PRINT_CHARS
|
* @name jasmine.MAX_PRETTY_PRINT_CHARS
|
||||||
* @default 100
|
* @default 1000
|
||||||
* @since 2.9.0
|
* @since 2.9.0
|
||||||
*/
|
*/
|
||||||
j$.MAX_PRETTY_PRINT_CHARS = 1000;
|
j$.MAX_PRETTY_PRINT_CHARS = 1000;
|
||||||
@@ -4003,7 +4003,8 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
'lineNumber',
|
'lineNumber',
|
||||||
'column',
|
'column',
|
||||||
'description',
|
'description',
|
||||||
'jasmineMessage'
|
'jasmineMessage',
|
||||||
|
'errors'
|
||||||
];
|
];
|
||||||
|
|
||||||
function ExceptionFormatter(options) {
|
function ExceptionFormatter(options) {
|
||||||
@@ -4069,6 +4070,19 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
lines = lines.concat(substack);
|
lines = lines.concat(substack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(error.errors)) {
|
||||||
|
for (let i = 0; i < error.errors.length; i++) {
|
||||||
|
if (error.errors[i] instanceof Error) {
|
||||||
|
lines.push('');
|
||||||
|
const substack = this.stack_(error.errors[i], {
|
||||||
|
messageHandling: 'require'
|
||||||
|
});
|
||||||
|
substack[0] = 'Error ' + (i + 1) + ': ' + substack[0];
|
||||||
|
lines = lines.concat(substack.map(x => ' ' + x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5108,6 +5122,71 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getJasmineRequireObj().toBeRejectedWithMatching = function(j$) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const usageError = j$.private.formatErrorMsg(
|
||||||
|
'<toBeRejectedWithMatching>',
|
||||||
|
'expect(function() {<expectation>}).toBeRejectedWithMatching(<Predicate>)'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect a promise to be rejected with a value matching a predicate.
|
||||||
|
* @function
|
||||||
|
* @async
|
||||||
|
* @name async-matchers#toBeRejectedWithMatching
|
||||||
|
* @since 6.2.0
|
||||||
|
* @param {Function} predicate - A function that takes the rejected promise value as its parameter and returns true if it matches.
|
||||||
|
* @example
|
||||||
|
* await expectAsync(aPromise).toBeRejectedWithMatching((error) => error.message === 'Some error');
|
||||||
|
* @example
|
||||||
|
* return expectAsync(aPromise).toBeRejectedWithMatching((error) => error.message === 'Some error');
|
||||||
|
*/
|
||||||
|
return function toBeRejectedWithMatching() {
|
||||||
|
return {
|
||||||
|
compare: function(actualPromise, predicate) {
|
||||||
|
if (!j$.private.isPromiseLike(actualPromise)) {
|
||||||
|
throw new Error(
|
||||||
|
`Expected toBeRejectedWithMatching to be called on a promise but was on a ${typeof actualPromise}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof predicate !== 'function') {
|
||||||
|
throw new Error(usageError('Predicate is not a Function'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function prefix(passed) {
|
||||||
|
return (
|
||||||
|
'Expected a promise ' +
|
||||||
|
(passed ? 'not ' : '') +
|
||||||
|
'to be rejected matching a predicate'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return actualPromise.then(
|
||||||
|
function() {
|
||||||
|
return {
|
||||||
|
pass: false,
|
||||||
|
message: prefix(false) + ', but it was resolved.'
|
||||||
|
};
|
||||||
|
},
|
||||||
|
function(actualValue) {
|
||||||
|
const result = predicate(actualValue);
|
||||||
|
return {
|
||||||
|
pass: Boolean(result),
|
||||||
|
message:
|
||||||
|
prefix(result) +
|
||||||
|
', but the predicate returned "' +
|
||||||
|
result +
|
||||||
|
'".'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().toBeResolved = function(j$) {
|
getJasmineRequireObj().toBeResolved = function(j$) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -6175,7 +6254,8 @@ getJasmineRequireObj().requireAsyncMatchers = function(jRequire, j$) {
|
|||||||
'toBeRejected',
|
'toBeRejected',
|
||||||
'toBeResolvedTo',
|
'toBeResolvedTo',
|
||||||
'toBeRejectedWith',
|
'toBeRejectedWith',
|
||||||
'toBeRejectedWithError'
|
'toBeRejectedWithError',
|
||||||
|
'toBeRejectedWithMatching'
|
||||||
],
|
],
|
||||||
matchers = {};
|
matchers = {};
|
||||||
|
|
||||||
@@ -12408,5 +12488,5 @@ getJasmineRequireObj().UserContext = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().version = function() {
|
getJasmineRequireObj().version = function() {
|
||||||
return '6.0.1';
|
return '6.1.0';
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "jasmine-core",
|
"name": "jasmine-core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "6.0.1",
|
"version": "6.1.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/jasmine/jasmine.git"
|
"url": "https://github.com/jasmine/jasmine.git"
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# Jasmine Core 6.1.0 Release Notes
|
||||||
|
|
||||||
|
## Changes to supported environments
|
||||||
|
|
||||||
|
* Safari 16 and 17 are no longer supported. Although jasmine-core may still work
|
||||||
|
in those versions, we no longer have a reliable way to test them and won't try
|
||||||
|
to maintain compatibility with them in future releases.
|
||||||
|
|
||||||
|
## New features
|
||||||
|
|
||||||
|
* Report the underlying errors that make up an `AggregateError`.
|
||||||
|
* Merges [#2093](https://github.com/jasmine/jasmine/pull/2093) from @puglyfe
|
||||||
|
* Fixes [#2063](https://github.com/jasmine/jasmine/issues/2063)
|
||||||
|
|
||||||
|
## Documentation improvements
|
||||||
|
|
||||||
|
* Fix default MAX_PRETTY_PRINT_CHARS in JsDoc.
|
||||||
|
* Merges [#2091](https://github.com/jasmine/jasmine/pull/2091) from @HolgerJeromin
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
This version has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------------------|
|
||||||
|
| Node | 20, 22, 24 |
|
||||||
|
| Safari | 26.3** |
|
||||||
|
| Chrome | 144* |
|
||||||
|
| Firefox | 102**, 115**, 128**, 140, 147* |
|
||||||
|
| Edge | 144* |
|
||||||
|
|
||||||
|
\* Evergreen browser. Each version of Jasmine is tested against the latest
|
||||||
|
version available at release time.<br>
|
||||||
|
\** Supported on a best-effort basis. Support for these versions may be dropped
|
||||||
|
if it becomes impractical, and bugs affecting only these versions may not be
|
||||||
|
treated as release blockers.
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# Jasmine Core 7.0.0-pre.0 Release Notes
|
||||||
|
|
||||||
|
This is a pre-release, intended to offer a preview of breaking changes and to
|
||||||
|
solicit feedback.
|
||||||
|
|
||||||
|
Before installing this release, update to 6.0.1 or later and fix all
|
||||||
|
deprecation warnings.
|
||||||
|
|
||||||
|
## Breaking changes
|
||||||
|
|
||||||
|
* `HtmlReporter`, `HtmlSpecFilter`, and `jsApiReporter`, which were deprecated
|
||||||
|
in 6.0, have been removed.
|
||||||
|
* Most private APIs are no longer exposed.
|
||||||
|
* Monkey patching is blocked. This does not affect globals (`describe`,
|
||||||
|
`expect`, etc.) or properties that are explicitly documented as writeable.
|
||||||
|
Those can still be overwritten.
|
||||||
|
* Redesigned boot process:
|
||||||
|
* `jasmineRequire`, `boot`, and `noGlobals` have been removed.
|
||||||
|
* The core instance is automatically created.
|
||||||
|
* In browsers, globals are automatically created.
|
||||||
|
* In Node, globals are not automatically created. Call the exported
|
||||||
|
`installGlobals` function to create them. If you're using the `jasmine`
|
||||||
|
package, this is done for you by default.
|
||||||
|
* In Node, the same instance is returned every time jasmine-core is imported.
|
||||||
|
If you need to do multiple consecutive independent test runs, call the
|
||||||
|
exported `reset` function to reset all state and configuration between runs.
|
||||||
|
|
||||||
|
If you maintain your own browser boot files, you may be able to update by just
|
||||||
|
removing `boot1.js`. See the `boot.js` file in this package for a working
|
||||||
|
example. If you boot jasmine-core in Node, remove the call to `boot` or
|
||||||
|
`noGlobals` and add a call to `installGlobals` if desired:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const jasmineCore = require('jasmine-core');
|
||||||
|
jasmineCore.installGlobals();
|
||||||
|
```
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
This version has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------------------|
|
||||||
|
| Node | 20, 22, 24 |
|
||||||
|
| Safari | 26.3** |
|
||||||
|
| Chrome | 144* |
|
||||||
|
| Firefox | 102**, 115**, 128**, 140, 147* |
|
||||||
|
| Edge | 144* |
|
||||||
|
|
||||||
|
\* Evergreen browser. Each version of Jasmine is tested against the latest
|
||||||
|
version available at release time.<br>
|
||||||
|
\** Supported on a best-effort basis. Support for these versions may be dropped
|
||||||
|
if it becomes impractical, and bugs affecting only these versions may not be
|
||||||
|
treated as release blockers.
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Run tests in supported browsers that are available on Saucelabs.
|
# Run tests in supported browsers that are available on Saucelabs.
|
||||||
# Note: The latest Safari version is tested via GitHub Actions because Saucelabs
|
# Note: Safari is tested via GitHub Actions because Saucelabs only makes Safari
|
||||||
# only makes it available to paid enterprise accounts. See
|
# 18 and later available to paid enterprise accounts. See
|
||||||
# .github/workflows/safari.yml.
|
# .github/workflows/safari.yml.
|
||||||
|
|
||||||
run_browser() {
|
run_browser() {
|
||||||
@@ -44,9 +44,6 @@ else
|
|||||||
fi
|
fi
|
||||||
run_browser firefox 102
|
run_browser firefox 102
|
||||||
|
|
||||||
run_browser safari 17
|
|
||||||
run_browser safari 16
|
|
||||||
|
|
||||||
run_browser MicrosoftEdge latest
|
run_browser MicrosoftEdge latest
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -346,5 +346,184 @@ describe('ExceptionFormatter', function() {
|
|||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when the error has an errors array (AggregateError)', function() {
|
||||||
|
it('includes all aggregated errors in the stack trace', function() {
|
||||||
|
const subject = new privateUnderTest.ExceptionFormatter();
|
||||||
|
const error1 = (function fn1() {
|
||||||
|
return new Error('first error');
|
||||||
|
})();
|
||||||
|
const error2 = (function fn2() {
|
||||||
|
return new Error('second error');
|
||||||
|
})();
|
||||||
|
const aggregateError = (function fn3() {
|
||||||
|
return new Error('Multiple errors occurred');
|
||||||
|
})();
|
||||||
|
aggregateError.errors = [error1, error2];
|
||||||
|
|
||||||
|
const lines = subject.stack(aggregateError).split('\n');
|
||||||
|
|
||||||
|
// TODO: be consistent across environments about whether the message is
|
||||||
|
// included in the stack trace
|
||||||
|
if (lines[0] === 'Error: Multiple errors occurred') {
|
||||||
|
lines.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exclude lines that vary from environment to environment
|
||||||
|
const filteredLines = lines.filter(
|
||||||
|
x =>
|
||||||
|
!x.includes('/jasmine.js:') &&
|
||||||
|
// Some Node 20 and 22 minors when running in parallel
|
||||||
|
!x.includes('process.processTicksAndRejections')
|
||||||
|
);
|
||||||
|
|
||||||
|
for (let i = 0; i < filteredLines.length; i++) {
|
||||||
|
jasmine.debugLog(`Line ${i} after filtering: ${filteredLines[i]}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inexact matching because stack frame formatting varies from runtime
|
||||||
|
// to runtime
|
||||||
|
const expectedPatterns = [
|
||||||
|
// Overall error
|
||||||
|
/fn3.*ExceptionFormatterSpec\.js/,
|
||||||
|
/ExceptionFormatterSpec\.js/,
|
||||||
|
/^$/,
|
||||||
|
|
||||||
|
// First nested error
|
||||||
|
/^ Error 1: Error: first error$/,
|
||||||
|
/^ .*fn1.*ExceptionFormatterSpec\.js/,
|
||||||
|
/^ .*ExceptionFormatterSpec\.js/,
|
||||||
|
/^$/,
|
||||||
|
|
||||||
|
// Second nested error
|
||||||
|
/^ .*Error 2: Error: second error$/,
|
||||||
|
/^ .*fn2.*ExceptionFormatterSpec\.js/,
|
||||||
|
/^ .*ExceptionFormatterSpec\.js/
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(filteredLines).toEqual(
|
||||||
|
expectedPatterns.map(p => jasmine.stringMatching(p))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles empty errors array', function() {
|
||||||
|
const subject = new privateUnderTest.ExceptionFormatter();
|
||||||
|
const aggregateError = new Error('No errors');
|
||||||
|
aggregateError.errors = [];
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
subject.stack(aggregateError);
|
||||||
|
}).not.toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles nested AggregateError', function() {
|
||||||
|
const subject = new privateUnderTest.ExceptionFormatter();
|
||||||
|
const innerError1 = new Error('inner error 1');
|
||||||
|
const innerError2 = new Error('inner error 2');
|
||||||
|
const innerAggregate = new Error('Inner aggregate');
|
||||||
|
innerAggregate.errors = [innerError1, innerError2];
|
||||||
|
|
||||||
|
const outerError = new Error('outer error');
|
||||||
|
const outerAggregate = new Error('Outer aggregate');
|
||||||
|
outerAggregate.errors = [innerAggregate, outerError];
|
||||||
|
|
||||||
|
const lines = subject.stack(outerAggregate).split('\n');
|
||||||
|
|
||||||
|
const innerAggMsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 1: Error: Inner aggregate')
|
||||||
|
);
|
||||||
|
expect(innerAggMsgIx).toBeGreaterThan(-1);
|
||||||
|
|
||||||
|
const innerError1MsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 1: Error: inner error 1')
|
||||||
|
);
|
||||||
|
expect(innerError1MsgIx).toBeGreaterThan(innerAggMsgIx);
|
||||||
|
|
||||||
|
const innerError2MsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 2: Error: inner error 2')
|
||||||
|
);
|
||||||
|
expect(innerError2MsgIx).toBeGreaterThan(innerError1MsgIx);
|
||||||
|
|
||||||
|
const outerErrorMsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 2: Error: outer error')
|
||||||
|
);
|
||||||
|
expect(outerErrorMsgIx).toBeGreaterThan(innerError2MsgIx);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles AggregateError containing error with cause', function() {
|
||||||
|
const subject = new privateUnderTest.ExceptionFormatter();
|
||||||
|
const rootCause = new Error('root cause');
|
||||||
|
const errorWithCause = new Error('error with cause', {
|
||||||
|
cause: rootCause
|
||||||
|
});
|
||||||
|
const aggregateError = new Error('Aggregate with cause chain');
|
||||||
|
aggregateError.errors = [errorWithCause];
|
||||||
|
|
||||||
|
const lines = subject.stack(aggregateError).split('\n');
|
||||||
|
|
||||||
|
const error1MsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 1: Error: error with cause')
|
||||||
|
);
|
||||||
|
expect(error1MsgIx).toBeGreaterThan(-1);
|
||||||
|
|
||||||
|
const causeMsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Caused by: Error: root cause')
|
||||||
|
);
|
||||||
|
expect(causeMsgIx).toBeGreaterThan(error1MsgIx);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips non-Error items in errors array', function() {
|
||||||
|
const subject = new privateUnderTest.ExceptionFormatter();
|
||||||
|
const error1 = new Error('real error');
|
||||||
|
const aggregateError = new Error('Mixed array');
|
||||||
|
aggregateError.errors = [
|
||||||
|
error1,
|
||||||
|
'string error',
|
||||||
|
{ message: 'object error' },
|
||||||
|
null,
|
||||||
|
undefined,
|
||||||
|
42
|
||||||
|
];
|
||||||
|
|
||||||
|
const lines = subject.stack(aggregateError).split('\n');
|
||||||
|
|
||||||
|
const error1MsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 1: Error: real error')
|
||||||
|
);
|
||||||
|
expect(error1MsgIx).toBeGreaterThan(-1);
|
||||||
|
|
||||||
|
const hasStringError = lines.some(line =>
|
||||||
|
line.includes('string error')
|
||||||
|
);
|
||||||
|
expect(hasStringError).toBe(false);
|
||||||
|
|
||||||
|
const hasObjectError = lines.some(line =>
|
||||||
|
line.includes('object error')
|
||||||
|
);
|
||||||
|
expect(hasObjectError).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works with native AggregateError constructor', function() {
|
||||||
|
const subject = new privateUnderTest.ExceptionFormatter();
|
||||||
|
const error1 = new Error('first error');
|
||||||
|
const error2 = new Error('second error');
|
||||||
|
const aggregateError = new AggregateError(
|
||||||
|
[error1, error2],
|
||||||
|
'Multiple errors'
|
||||||
|
);
|
||||||
|
|
||||||
|
const lines = subject.stack(aggregateError).split('\n');
|
||||||
|
|
||||||
|
const error1MsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 1: Error: first error')
|
||||||
|
);
|
||||||
|
expect(error1MsgIx).toBeGreaterThan(-1);
|
||||||
|
|
||||||
|
const error2MsgIx = lines.findIndex(line =>
|
||||||
|
line.includes('Error 2: Error: second error')
|
||||||
|
);
|
||||||
|
expect(error2MsgIx).toBeGreaterThan(error1MsgIx);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
describe('#toBeRejectedWithMatching', function() {
|
||||||
|
it('passes if the promise is rejected with something matching the predicate', function() {
|
||||||
|
const matcher = privateUnderTest.asyncMatchers.toBeRejectedWithMatching(),
|
||||||
|
actual = Promise.reject(new Error('nope')),
|
||||||
|
predicate = value => value.message === 'nope';
|
||||||
|
|
||||||
|
return matcher.compare(actual, predicate).then(function(result) {
|
||||||
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails if the promise resolves', function() {
|
||||||
|
const matcher = privateUnderTest.asyncMatchers.toBeRejectedWithMatching(),
|
||||||
|
actual = Promise.resolve(),
|
||||||
|
predicate = () => true;
|
||||||
|
|
||||||
|
return matcher.compare(actual, predicate).then(function(result) {
|
||||||
|
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails if the promise is rejected with something not matching the predicate', function() {
|
||||||
|
const matcher = privateUnderTest.asyncMatchers.toBeRejectedWithMatching(),
|
||||||
|
actual = Promise.reject('A Bad Apple'),
|
||||||
|
predicate = value => value === 'A Good Orange';
|
||||||
|
|
||||||
|
return matcher.compare(actual, predicate).then(function(result) {
|
||||||
|
expect(result).toEqual(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
pass: false,
|
||||||
|
message:
|
||||||
|
'Expected a promise to be rejected matching a predicate, but the predicate returned "false".'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should build its error correctly when negated', function() {
|
||||||
|
const matcher = privateUnderTest.asyncMatchers.toBeRejectedWithMatching(),
|
||||||
|
actual = Promise.reject(true),
|
||||||
|
predicate = () => true;
|
||||||
|
|
||||||
|
return matcher.compare(actual, predicate).then(function(result) {
|
||||||
|
expect(result).toEqual(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
pass: true,
|
||||||
|
message:
|
||||||
|
'Expected a promise not to be rejected matching a predicate, but the predicate returned "true".'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails if actual is not a promise', function() {
|
||||||
|
const matcher = privateUnderTest.asyncMatchers.toBeRejectedWithMatching(),
|
||||||
|
actual = 'not a promise';
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
return matcher.compare(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(f).toThrowError(
|
||||||
|
'Expected toBeRejectedWithMatching to be called on a promise but was on a string.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails if predicate is not a function', function() {
|
||||||
|
const matcher = privateUnderTest.asyncMatchers.toBeRejectedWithMatching(),
|
||||||
|
actual = Promise.resolve(),
|
||||||
|
predicate = 'not a function';
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
return matcher.compare(actual, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(f).toThrowError(/Predicate is not a Function/);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-env node, es6 */
|
|
||||||
const path = require('path'),
|
const path = require('path'),
|
||||||
jasmineBrowser = require('jasmine-browser-runner'),
|
jasmineBrowser = require('jasmine-browser-runner'),
|
||||||
jasmineCore = require('../../lib/jasmine-core');
|
jasmineCore = require('../../lib/jasmine-core');
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-env node, es6 */
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
srcDir: 'src',
|
srcDir: 'src',
|
||||||
srcFiles: [
|
srcFiles: [
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
'lineNumber',
|
'lineNumber',
|
||||||
'column',
|
'column',
|
||||||
'description',
|
'description',
|
||||||
'jasmineMessage'
|
'jasmineMessage',
|
||||||
|
'errors'
|
||||||
];
|
];
|
||||||
|
|
||||||
function ExceptionFormatter(options) {
|
function ExceptionFormatter(options) {
|
||||||
@@ -77,6 +78,19 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
lines = lines.concat(substack);
|
lines = lines.concat(substack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(error.errors)) {
|
||||||
|
for (let i = 0; i < error.errors.length; i++) {
|
||||||
|
if (error.errors[i] instanceof Error) {
|
||||||
|
lines.push('');
|
||||||
|
const substack = this.stack_(error.errors[i], {
|
||||||
|
messageHandling: 'require'
|
||||||
|
});
|
||||||
|
substack[0] = 'Error ' + (i + 1) + ': ' + substack[0];
|
||||||
|
lines = lines.concat(substack.map(x => ' ' + x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
* Maximum number of characters to display when pretty printing objects.
|
* Maximum number of characters to display when pretty printing objects.
|
||||||
* Characters past this number will be ellipised.
|
* Characters past this number will be ellipised.
|
||||||
* @name jasmine.MAX_PRETTY_PRINT_CHARS
|
* @name jasmine.MAX_PRETTY_PRINT_CHARS
|
||||||
* @default 100
|
* @default 1000
|
||||||
* @since 2.9.0
|
* @since 2.9.0
|
||||||
*/
|
*/
|
||||||
j$.MAX_PRETTY_PRINT_CHARS = 1000;
|
j$.MAX_PRETTY_PRINT_CHARS = 1000;
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
getJasmineRequireObj().toBeRejectedWithMatching = function(j$) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const usageError = j$.private.formatErrorMsg(
|
||||||
|
'<toBeRejectedWithMatching>',
|
||||||
|
'expect(function() {<expectation>}).toBeRejectedWithMatching(<Predicate>)'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect a promise to be rejected with a value matching a predicate.
|
||||||
|
* @function
|
||||||
|
* @async
|
||||||
|
* @name async-matchers#toBeRejectedWithMatching
|
||||||
|
* @since 6.2.0
|
||||||
|
* @param {Function} predicate - A function that takes the rejected promise value as its parameter and returns true if it matches.
|
||||||
|
* @example
|
||||||
|
* await expectAsync(aPromise).toBeRejectedWithMatching((error) => error.message === 'Some error');
|
||||||
|
* @example
|
||||||
|
* return expectAsync(aPromise).toBeRejectedWithMatching((error) => error.message === 'Some error');
|
||||||
|
*/
|
||||||
|
return function toBeRejectedWithMatching() {
|
||||||
|
return {
|
||||||
|
compare: function(actualPromise, predicate) {
|
||||||
|
if (!j$.private.isPromiseLike(actualPromise)) {
|
||||||
|
throw new Error(
|
||||||
|
`Expected toBeRejectedWithMatching to be called on a promise but was on a ${typeof actualPromise}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof predicate !== 'function') {
|
||||||
|
throw new Error(usageError('Predicate is not a Function'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function prefix(passed) {
|
||||||
|
return (
|
||||||
|
'Expected a promise ' +
|
||||||
|
(passed ? 'not ' : '') +
|
||||||
|
'to be rejected matching a predicate'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return actualPromise.then(
|
||||||
|
function() {
|
||||||
|
return {
|
||||||
|
pass: false,
|
||||||
|
message: prefix(false) + ', but it was resolved.'
|
||||||
|
};
|
||||||
|
},
|
||||||
|
function(actualValue) {
|
||||||
|
const result = predicate(actualValue);
|
||||||
|
return {
|
||||||
|
pass: Boolean(result),
|
||||||
|
message:
|
||||||
|
prefix(result) +
|
||||||
|
', but the predicate returned "' +
|
||||||
|
result +
|
||||||
|
'".'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -7,7 +7,8 @@ getJasmineRequireObj().requireAsyncMatchers = function(jRequire, j$) {
|
|||||||
'toBeRejected',
|
'toBeRejected',
|
||||||
'toBeResolvedTo',
|
'toBeResolvedTo',
|
||||||
'toBeRejectedWith',
|
'toBeRejectedWith',
|
||||||
'toBeRejectedWithError'
|
'toBeRejectedWithError',
|
||||||
|
'toBeRejectedWithMatching'
|
||||||
],
|
],
|
||||||
matchers = {};
|
matchers = {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user