Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
592fba22b8 | ||
|
|
58ef707bc6 | ||
|
|
050c1f051c | ||
|
|
8d0c52e2ec | ||
|
|
de91427356 | ||
|
|
324bc201c2 | ||
|
|
76f34e90dc | ||
|
|
46e7158c77 | ||
|
|
9ab039e330 | ||
|
|
3f5c47dff3 | ||
|
|
1320b0614f | ||
|
|
905e3fc3f9 | ||
|
|
89331bb1bb | ||
|
|
88de272c89 | ||
|
|
60bbe68148 | ||
|
|
623e638cd4 | ||
|
|
b1bcd6e825 | ||
|
|
204acf7297 | ||
|
|
cd1131354b | ||
|
|
c24aef15b1 | ||
|
|
d5d5d1965f | ||
|
|
d27bb8fa96 | ||
|
|
7d5ca27b9d | ||
|
|
795651d3b6 | ||
|
|
e7daa429a1 | ||
|
|
51ad18cb28 | ||
|
|
0b81705c11 | ||
|
|
00feef8632 | ||
|
|
5a715aecee | ||
|
|
8cb44582bc | ||
|
|
53d8073707 | ||
|
|
e0eb4755cb | ||
|
|
6277046213 | ||
|
|
6b9739030d | ||
|
|
b0d949e0d5 | ||
|
|
dfdcfc5be5 | ||
|
|
e5bb89847f | ||
|
|
1f68ed836e | ||
|
|
c4e65e4a9a | ||
|
|
0cfeb0b9c3 |
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -101,7 +101,7 @@ Follow these tips and your pull request, patch, or suggestion is much more likel
|
|||||||
|
|
||||||
Jasmine uses some internal tooling to test itself in browser on Travis. This tooling _should_ work locally as well.
|
Jasmine uses some internal tooling to test itself in browser on Travis. This tooling _should_ work locally as well.
|
||||||
|
|
||||||
$ node ci.js
|
$ node spec/support/ci.js
|
||||||
|
|
||||||
You can also set the `JASMINE_BROWSER` environment variable to specify which browser should be used.
|
You can also set the `JASMINE_BROWSER` environment variable to specify which browser should be used.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js: 10
|
node_js: 14
|
||||||
|
|
||||||
script: $TEST_COMMAND
|
script: $TEST_COMMAND
|
||||||
|
|
||||||
@@ -12,11 +12,11 @@ env:
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- node_js: "10"
|
- node_js: "14"
|
||||||
env: JASMINE_LONG_PROPERTY_TESTS="y" TEST_COMMAND="npm test"
|
env: JASMINE_LONG_PROPERTY_TESTS="y" TEST_COMMAND="npm test"
|
||||||
- node_js: "12"
|
- node_js: "12"
|
||||||
env: TEST_COMMAND="npm test"
|
env: TEST_COMMAND="npm test"
|
||||||
- node_js: "8"
|
- node_js: "10"
|
||||||
env: TEST_COMMAND="npm test"
|
env: TEST_COMMAND="npm test"
|
||||||
- env: JASMINE_BROWSER="internet explorer" SAUCE_BROWSER_VERSION=11 SAUCE_OS="Windows 8.1"
|
- env: JASMINE_BROWSER="internet explorer" SAUCE_BROWSER_VERSION=11 SAUCE_OS="Windows 8.1"
|
||||||
if: type != pull_request
|
if: type != pull_request
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -1,6 +1,6 @@
|
|||||||
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/main/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
|
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/main/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
|
||||||
|
|
||||||
[](https://travis-ci.org/jasmine/jasmine)
|
[](https://travis-ci.com/jasmine/jasmine)
|
||||||
[](https://www.codetriage.com/jasmine/jasmine)
|
[](https://www.codetriage.com/jasmine/jasmine)
|
||||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_shield)
|
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_shield)
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ To install Jasmine standalone on your local box (where **_{#.#.#}_** below is su
|
|||||||
Add the following to your HTML file:
|
Add the following to your HTML file:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-{#.#.#}/jasmine_favicon.png">
|
<link rel="shortcut icon" type="image/png" href="lib/jasmine-{#.#.#}/jasmine_favicon.png">
|
||||||
<link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-{#.#.#}/jasmine.css">
|
<link rel="stylesheet" type="text/css" href="lib/jasmine-{#.#.#}/jasmine.css">
|
||||||
|
|
||||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine.js"></script>
|
<script type="text/javascript" src="lib/jasmine-{#.#.#}/jasmine.js"></script>
|
||||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine-html.js"></script>
|
<script type="text/javascript" src="lib/jasmine-{#.#.#}/jasmine-html.js"></script>
|
||||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/boot.js"></script>
|
<script type="text/javascript" src="lib/jasmine-{#.#.#}/boot.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Supported environments
|
## Supported environments
|
||||||
@@ -56,7 +56,7 @@ Jasmine tests itself across many browsers (Safari, Chrome, Firefox, Microsoft Ed
|
|||||||
|
|
||||||
| Environment | Supported versions |
|
| Environment | Supported versions |
|
||||||
|-------------------|--------------------|
|
|-------------------|--------------------|
|
||||||
| Node | 8, 10, 12 |
|
| Node | 10, 12, 14 |
|
||||||
| Safari | 8-13 |
|
| Safari | 8-13 |
|
||||||
| Chrome | Evergreen |
|
| Chrome | Evergreen |
|
||||||
| Firefox | Evergreen, 68 |
|
| Firefox | Evergreen, 68 |
|
||||||
|
|||||||
65
RELEASE.md
65
RELEASE.md
@@ -29,29 +29,32 @@ When jasmine-core revs its major or minor version, the binding libraries should
|
|||||||
When ready to release - specs are all green and the stories are done:
|
When ready to release - specs are all green and the stories are done:
|
||||||
|
|
||||||
1. Update the release notes in `release_notes` - use the Anchorman gem to generate the markdown file and edit accordingly
|
1. Update the release notes in `release_notes` - use the Anchorman gem to generate the markdown file and edit accordingly
|
||||||
1. Update the version in `package.json` to a release candidate
|
1. Update the version in `package.json`
|
||||||
1. Update any links or top-level landing page for the Github Pages
|
1. Copy version to the Ruby gem with `grunt build:copyVersionToGem`
|
||||||
|
|
||||||
|
### Commit and push core changes
|
||||||
|
|
||||||
|
1. Commit release notes and version changes (jasmine.js, version.rb, package.json)
|
||||||
|
1. Push
|
||||||
|
1. Wait for Travis to go green
|
||||||
|
|
||||||
### Build standalone distribution
|
### Build standalone distribution
|
||||||
|
|
||||||
1. Build the standalone distribution with `grunt buildStandaloneDist`
|
1. Build the standalone distribution with `grunt buildStandaloneDist`
|
||||||
|
|
||||||
### Release the Python egg
|
### Release the core Ruby gem
|
||||||
|
|
||||||
|
1. __NOTE__: You will likely need to push a new jasmine gem with a dependent version right after this release. See below.
|
||||||
|
1. `rake release` - tags the repo with the version, builds the `jasmine-core` gem, pushes the gem to Rubygems.org. In order to release you will have to ensure you have rubygems creds locally.
|
||||||
|
|
||||||
|
### Release the core Python egg
|
||||||
|
|
||||||
Install [twine](https://github.com/pypa/twine)
|
Install [twine](https://github.com/pypa/twine)
|
||||||
|
|
||||||
1. `python setup.py sdist`
|
1. `python setup.py sdist`
|
||||||
1. `twine upload dist/jasmine-core-<version>.tar.gz` You will need pypi credentials to upload the egg.
|
1. `twine upload dist/jasmine-core-<version>.tar.gz` You will need pypi credentials to upload the egg.
|
||||||
|
|
||||||
### Release the Ruby gem
|
### Release the core NPM module
|
||||||
|
|
||||||
1. Copy version to the Ruby gem with `grunt build:copyVersionToGem`
|
|
||||||
1. __NOTE__: You will likely need to point to a local jasmine gem in order to run tests locally. _Do not_ push this version of the Gemfile.
|
|
||||||
1. __NOTE__: You will likely need to push a new jasmine gem with a dependent version right after this release.
|
|
||||||
1. Push these changes to GitHub and verify that this SHA is green
|
|
||||||
1. `rake release` - tags the repo with the version, builds the `jasmine-core` gem, pushes the gem to Rubygems.org. In order to release you will have to ensure you have rubygems creds locally.
|
|
||||||
|
|
||||||
### Release the NPM
|
|
||||||
|
|
||||||
1. `npm adduser` to save your credentials locally
|
1. `npm adduser` to save your credentials locally
|
||||||
1. `npm publish .` to publish what's in `package.json`
|
1. `npm publish .` to publish what's in `package.json`
|
||||||
@@ -60,15 +63,35 @@ Install [twine](https://github.com/pypa/twine)
|
|||||||
|
|
||||||
Probably only need to do this when releasing a minor version, and not a patch version.
|
Probably only need to do this when releasing a minor version, and not a patch version.
|
||||||
|
|
||||||
1. `cp -R edge ${version}` to copy the current edge docs to the new version
|
1. `rake update_edge_jasmine`
|
||||||
1. Add a link to the new version in `index.html`
|
1. `npm run jsdoc`
|
||||||
|
1. `rake release[${version}]` to copy the current edge docs to the new version
|
||||||
|
1. Commit and push.
|
||||||
|
|
||||||
|
### Release the binding libraries
|
||||||
|
|
||||||
|
#### NPM
|
||||||
|
|
||||||
|
1. Create release notes using Anchorman as above
|
||||||
|
1. In `package.json`, update both the package version and the jasmine-core dependency version
|
||||||
|
1. Commit and push.
|
||||||
|
1. Wait for Travis to go green again.
|
||||||
|
1. `grunt release `
|
||||||
|
1. `npm publish .`
|
||||||
|
|
||||||
|
#### Gem
|
||||||
|
|
||||||
|
1. Create release notes using Anchorman as above
|
||||||
|
1. Update the version number in `lib/jasmine/version.rb`.
|
||||||
|
1. Update the jasmine-core dependency version in `jasmine.gemspec`.
|
||||||
|
1. Commit and push.
|
||||||
|
1. Wait for Travis to go green again.
|
||||||
|
1. `rake release`
|
||||||
|
|
||||||
### Finally
|
### Finally
|
||||||
|
|
||||||
1. Visit the [Releases page for Jasmine](https://github.com/jasmine/jasmine/releases), find the tag just pushed.
|
For each of the above GitHub repos:
|
||||||
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
|
1. Visit the releases page and find the tag just published.
|
||||||
1. If it is a pre-release, mark it as such.
|
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
|
||||||
1. Attach the standalone zipfile
|
1. If it is a pre-release, mark it as such.
|
||||||
|
1. For core, attach the standalone zipfile.
|
||||||
|
|
||||||
There should be a post to Pivotal Labs blog and a tweet to that link.
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2020 Pivotal Labs
|
Copyright (c) 2008-2021 Pivotal Labs
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2020 Pivotal Labs
|
Copyright (c) 2008-2021 Pivotal Labs
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
@@ -132,7 +132,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
failures.push(failureDom(result));
|
failures.push(failureDom(result));
|
||||||
}
|
}
|
||||||
addDeprecationWarnings(result);
|
addDeprecationWarnings(result, 'suite');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.specStarted = function(result) {
|
this.specStarted = function(result) {
|
||||||
@@ -168,7 +168,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
failures.push(failureDom(result));
|
failures.push(failureDom(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
addDeprecationWarnings(result);
|
addDeprecationWarnings(result, 'spec');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.displaySpecInCorrectFormat = function(result) {
|
this.displaySpecInCorrectFormat = function(result) {
|
||||||
@@ -307,14 +307,27 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
addDeprecationWarnings(doneResult);
|
addDeprecationWarnings(doneResult);
|
||||||
|
|
||||||
var warningBarClassName = 'jasmine-bar jasmine-warning';
|
|
||||||
for (i = 0; i < deprecationWarnings.length; i++) {
|
for (i = 0; i < deprecationWarnings.length; i++) {
|
||||||
var warning = deprecationWarnings[i];
|
var context;
|
||||||
|
|
||||||
|
switch (deprecationWarnings[i].runnableType) {
|
||||||
|
case 'spec':
|
||||||
|
context = '(in spec: ' + deprecationWarnings[i].runnableName + ')';
|
||||||
|
break;
|
||||||
|
case 'suite':
|
||||||
|
context = '(in suite: ' + deprecationWarnings[i].runnableName + ')';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
context = '';
|
||||||
|
}
|
||||||
|
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
'span',
|
'span',
|
||||||
{ className: warningBarClassName },
|
{ className: 'jasmine-bar jasmine-warning' },
|
||||||
'DEPRECATION: ' + warning
|
'DEPRECATION: ' + deprecationWarnings[i].message,
|
||||||
|
createDom('br'),
|
||||||
|
context
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -625,12 +638,16 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
return addToExistingQueryString('spec', els.join(' '));
|
return addToExistingQueryString('spec', els.join(' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDeprecationWarnings(result) {
|
function addDeprecationWarnings(result, runnableType) {
|
||||||
if (result && result.deprecationWarnings) {
|
if (result && result.deprecationWarnings) {
|
||||||
for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
||||||
var warning = result.deprecationWarnings[i].message;
|
var warning = result.deprecationWarnings[i].message;
|
||||||
if (!j$.util.arrayContains(warning)) {
|
if (!j$.util.arrayContains(warning)) {
|
||||||
deprecationWarnings.push(warning);
|
deprecationWarnings.push({
|
||||||
|
message: warning,
|
||||||
|
runnableName: result.fullName,
|
||||||
|
runnableType: runnableType
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2020 Pivotal Labs
|
Copyright (c) 2008-2021 Pivotal Labs
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
#
|
#
|
||||||
module Jasmine
|
module Jasmine
|
||||||
module Core
|
module Core
|
||||||
VERSION = "3.6.0"
|
VERSION = "3.7.0"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "jasmine-core",
|
"name": "jasmine-core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "3.6.0",
|
"version": "3.7.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/jasmine/jasmine.git"
|
"url": "https://github.com/jasmine/jasmine.git"
|
||||||
@@ -13,9 +13,9 @@
|
|||||||
"bdd"
|
"bdd"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"posttest": "eslint \"src/**/*.js\" \"spec/**/*.js\" && prettier --check src/**/*.js spec/**/*.js",
|
"posttest": "eslint \"src/**/*.js\" \"spec/**/*.js\" && prettier --check \"src/**/*.js\" \"spec/**/*.js\"",
|
||||||
"test": "grunt --stack execSpecsInNode",
|
"test": "grunt --stack execSpecsInNode",
|
||||||
"cleanup": "prettier --write src/**/*.js spec/**/*.js",
|
"cleanup": "prettier --write \"src/**/*.js\" \"spec/**/*.js\"",
|
||||||
"build": "grunt buildDistribution",
|
"build": "grunt buildDistribution",
|
||||||
"serve": "node spec/support/localJasmineBrowser.js",
|
"serve": "node spec/support/localJasmineBrowser.js",
|
||||||
"serve:performance": "node spec/support/localJasmineBrowser.js jasmine-browser-performance.json",
|
"serve:performance": "node spec/support/localJasmineBrowser.js jasmine-browser-performance.json",
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
"grunt-css-url-embed": "^1.11.1",
|
"grunt-css-url-embed": "^1.11.1",
|
||||||
"grunt-sass": "^3.0.2",
|
"grunt-sass": "^3.0.2",
|
||||||
"jasmine": "^3.4.0",
|
"jasmine": "^3.4.0",
|
||||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser",
|
"jasmine-browser-runner": "^0.4.0",
|
||||||
"jsdom": "^15.0.0",
|
"jsdom": "^15.0.0",
|
||||||
"load-grunt-tasks": "^4.0.0",
|
"load-grunt-tasks": "^4.0.0",
|
||||||
"node-sass": "^4.11.0",
|
"node-sass": "^4.11.0",
|
||||||
|
|||||||
80
release_notes/3.7.0.md
Normal file
80
release_notes/3.7.0.md
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
# Jasmine Core 3.7 Release Notes
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This is a maintenance release of Jasmine with a number of new features and fixes.
|
||||||
|
|
||||||
|
|
||||||
|
## New features and bug fixes
|
||||||
|
|
||||||
|
* Allow custom object formatters to be added in beforeAll
|
||||||
|
- Fixes [#1876](http://github.com/jasmine/jasmine/issues/1876)
|
||||||
|
|
||||||
|
* Allow specs to disable Jasmine's global error handling by overwriting `onerror`.
|
||||||
|
- Merges [#1860](https://github.com/jasmine/jasmine/pull/1860) from @greghuc
|
||||||
|
|
||||||
|
* Fixed comparison between URL objects
|
||||||
|
- Fixes [#1866](http://github.com/jasmine/jasmine/issues/1866)
|
||||||
|
|
||||||
|
* Added support for stack traces created by `node --enable-source-maps`
|
||||||
|
with tools like the Typescript compiler.
|
||||||
|
- Merges [#1862](https://github.com/jasmine/jasmine/pull/1862) from @JannesMeyer
|
||||||
|
|
||||||
|
* Made properties added by createSpyObj() enumerable.
|
||||||
|
- Merges [#1859](https://github.com/jasmine/jasmine/pull/1859) from DCtheTall
|
||||||
|
- Fixes [#1837](http://github.com/jasmine/jasmine/issues/1837)
|
||||||
|
|
||||||
|
* Show the name of the spec/suite that caused a deprecation
|
||||||
|
|
||||||
|
* Warn if a spec or before/after function both takes a callback and returns a promise
|
||||||
|
|
||||||
|
* Don't overwrite MatchersUtil methods with ones that were added to
|
||||||
|
`Array.prototype`, esp. `contains`
|
||||||
|
- Fixes [#1849](http://github.com/jasmine/jasmine/issues/1849)
|
||||||
|
|
||||||
|
* Allow generator functions to be passed to `.and.callFake`
|
||||||
|
- Fixes [#1848](http://github.com/jasmine/jasmine/issues/1848)
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation updates
|
||||||
|
|
||||||
|
* Fixed instructions for contributors to run Jasmine's ci script
|
||||||
|
|
||||||
|
* Updated supported Node versions in README
|
||||||
|
|
||||||
|
* Fixed script and CSS URLs in standalone example in README
|
||||||
|
- Merges [#1839](https://github.com/jasmine/jasmine/pull/1839) from @snowman
|
||||||
|
|
||||||
|
* Fixed typo in asyncMatcher toBePending comment
|
||||||
|
- Merges [#1847](https://github.com/jasmine/jasmine/pull/1847) from @SnailCoil
|
||||||
|
|
||||||
|
* Fixed link to custom object formatter tutorial
|
||||||
|
|
||||||
|
* Added jasmine.isSpy to the public interface
|
||||||
|
- Fixes [#1880](http://github.com/jasmine/jasmine/issues/1880)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Internal notes
|
||||||
|
|
||||||
|
* Fixed intermittent test failures
|
||||||
|
|
||||||
|
* Added additional assertions to tests for toBeTruthy and toBeFalsy
|
||||||
|
- Merges [#1875](https://github.com/jasmine/jasmine/pull/1875) from @yasinkocak
|
||||||
|
|
||||||
|
* Pointed Travis badge at travis-ci.com, not .org
|
||||||
|
|
||||||
|
* Fixed file globs so that Prettier runs on all files
|
||||||
|
|
||||||
|
* Check for forgotten console and debugger statements
|
||||||
|
|
||||||
|
* Fixed code in Jasmine that will trigger deprecations in 3.99
|
||||||
|
|
||||||
|
* Use jasmine-browser from npm rather than from the main branch
|
||||||
|
- The current released version now works with IE, so we no longer need to
|
||||||
|
depend on main.
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
"ignorePatterns": [
|
ignorePatterns: ['support/ci.js', 'support/jasmine-browser.js'],
|
||||||
"support/ci.js",
|
|
||||||
"support/jasmine-browser.js"
|
|
||||||
],
|
|
||||||
rules: {
|
rules: {
|
||||||
// Relax rules for now to allow for the quirks of the test suite
|
// Relax rules for now to allow for the quirks of the test suite
|
||||||
// TODO: We should probably remove these & fix the resulting errors
|
// TODO: We should probably remove these & fix the resulting errors
|
||||||
"quotes": "off",
|
quotes: 'off',
|
||||||
"semi": "off",
|
semi: 'off',
|
||||||
"key-spacing": "off",
|
'key-spacing': 'off',
|
||||||
"space-before-blocks": "off",
|
'space-before-blocks': 'off',
|
||||||
"no-unused-vars": "off",
|
'no-unused-vars': 'off',
|
||||||
"no-trailing-spaces": "off",
|
'no-trailing-spaces': 'off',
|
||||||
"block-spacing": "off",
|
'block-spacing': 'off',
|
||||||
|
|
||||||
|
// Since linting is done at the end of the process and doesn't stop us
|
||||||
|
// from running tests, it makes sense to fail if debugger statements
|
||||||
|
// or console references are present.
|
||||||
|
'no-debugger': 'error',
|
||||||
|
'no-console': 'error'
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -334,20 +334,16 @@ describe('Env', function() {
|
|||||||
expectationFactory('actual', specInstance);
|
expectationFactory('actual', specInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter({
|
env.execute(null, function() {
|
||||||
jasmineDone: function() {
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
customObjectFormatter
|
||||||
customObjectFormatter
|
]);
|
||||||
]);
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
customTesters: [customEqualityTester],
|
||||||
customTesters: [customEqualityTester],
|
pp: prettyPrinter
|
||||||
pp: prettyPrinter
|
});
|
||||||
});
|
done();
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
||||||
@@ -371,19 +367,15 @@ describe('Env', function() {
|
|||||||
asyncExpectationFactory('actual', specInstance);
|
asyncExpectationFactory('actual', specInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter({
|
env.execute(null, function() {
|
||||||
jasmineDone: function() {
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
customObjectFormatter
|
||||||
customObjectFormatter
|
]);
|
||||||
]);
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
customTesters: [customEqualityTester],
|
||||||
customTesters: [customEqualityTester],
|
pp: prettyPrinter
|
||||||
pp: prettyPrinter
|
});
|
||||||
});
|
done();
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -86,6 +86,37 @@ describe('ExceptionFormatter', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('filters Jasmine stack frames from V8-style traces but leaves unmatched lines intact', function() {
|
||||||
|
var error = {
|
||||||
|
message: 'nope',
|
||||||
|
stack:
|
||||||
|
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||||
|
" new Error('nope');\n" +
|
||||||
|
' ^\n' +
|
||||||
|
'\n' +
|
||||||
|
'Error: nope\n' +
|
||||||
|
' at fn1 (C:\\__spec__\\core\\UtilSpec.js:115:19)\n' +
|
||||||
|
' -> C:\\__spec__\\core\\UtilSpec.ts:120:15\n' +
|
||||||
|
' at fn2 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7533:40)\n' +
|
||||||
|
' at fn3 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7575:25)\n' +
|
||||||
|
' at fn4 (node:internal/timers:462:21)\n'
|
||||||
|
};
|
||||||
|
var subject = new jasmineUnderTest.ExceptionFormatter({
|
||||||
|
jasmineFile: 'C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js'
|
||||||
|
});
|
||||||
|
var result = subject.stack(error);
|
||||||
|
expect(result).toEqual(
|
||||||
|
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||||
|
" new Error('nope');\n" +
|
||||||
|
' ^\n' +
|
||||||
|
'Error: nope\n' +
|
||||||
|
' at fn1 (C:\\__spec__\\core\\UtilSpec.js:115:19)\n' +
|
||||||
|
' -> C:\\__spec__\\core\\UtilSpec.ts:120:15\n' +
|
||||||
|
' at <Jasmine>\n' +
|
||||||
|
' at fn4 (node:internal/timers:462:21)'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('filters Jasmine stack frames from V8 style traces', function() {
|
it('filters Jasmine stack frames from V8 style traces', function() {
|
||||||
var error = {
|
var error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ describe('Exceptions:', function() {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ jasmineDone: expectations });
|
env.execute(null, expectations);
|
||||||
env.execute();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
|
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
|
||||||
@@ -49,7 +48,6 @@ describe('Exceptions:', function() {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ jasmineDone: expectations });
|
env.execute(null, expectations);
|
||||||
env.execute();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,6 +12,23 @@ describe('GlobalErrors', function() {
|
|||||||
expect(handler).toHaveBeenCalledWith('foo');
|
expect(handler).toHaveBeenCalledWith('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('enables external interception of error by overriding global.onerror', function() {
|
||||||
|
var fakeGlobal = { onerror: null },
|
||||||
|
handler = jasmine.createSpy('errorHandler'),
|
||||||
|
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||||
|
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
|
||||||
|
fakeGlobal.onerror = hijackHandler;
|
||||||
|
|
||||||
|
fakeGlobal.onerror('foo');
|
||||||
|
|
||||||
|
expect(hijackHandler).toHaveBeenCalledWith('foo');
|
||||||
|
expect(handler).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('calls the global error handler with all parameters', function() {
|
it('calls the global error handler with all parameters', function() {
|
||||||
var fakeGlobal = { onerror: null },
|
var fakeGlobal = { onerror: null },
|
||||||
handler = jasmine.createSpy('errorHandler'),
|
handler = jasmine.createSpy('errorHandler'),
|
||||||
@@ -58,7 +75,7 @@ describe('GlobalErrors', function() {
|
|||||||
errors.pushListener(handler1);
|
errors.pushListener(handler1);
|
||||||
errors.pushListener(handler2);
|
errors.pushListener(handler2);
|
||||||
|
|
||||||
errors.popListener();
|
errors.popListener(handler2);
|
||||||
|
|
||||||
fakeGlobal.onerror('foo');
|
fakeGlobal.onerror('foo');
|
||||||
|
|
||||||
@@ -66,6 +83,13 @@ describe('GlobalErrors', function() {
|
|||||||
expect(handler2).not.toHaveBeenCalled();
|
expect(handler2).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws when no listener is passed to #popListener', function() {
|
||||||
|
var errors = new jasmineUnderTest.GlobalErrors({});
|
||||||
|
expect(function() {
|
||||||
|
errors.popListener();
|
||||||
|
}).toThrowError('popListener expects a listener');
|
||||||
|
});
|
||||||
|
|
||||||
it('uninstalls itself, putting back a previous callback', function() {
|
it('uninstalls itself, putting back a previous callback', function() {
|
||||||
var originalCallback = jasmine.createSpy('error'),
|
var originalCallback = jasmine.createSpy('error'),
|
||||||
fakeGlobal = { onerror: originalCallback },
|
fakeGlobal = { onerror: originalCallback },
|
||||||
@@ -268,5 +292,64 @@ describe('GlobalErrors', function() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Enabling external interception of reported rejections by overriding global.onerror', function() {
|
||||||
|
it('overriding global.onerror intercepts rejections whose reason is a string', function() {
|
||||||
|
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'addEventListener'
|
||||||
|
]),
|
||||||
|
handler = jasmine.createSpy('errorHandler'),
|
||||||
|
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||||
|
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
|
||||||
|
fakeGlobal.onerror = hijackHandler;
|
||||||
|
|
||||||
|
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||||
|
addedListener({ reason: 'nope' });
|
||||||
|
|
||||||
|
expect(hijackHandler).toHaveBeenCalledWith(
|
||||||
|
'Unhandled promise rejection: nope'
|
||||||
|
);
|
||||||
|
expect(handler).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('overriding global.onerror intercepts rejections whose reason is an Error', function() {
|
||||||
|
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'addEventListener'
|
||||||
|
]),
|
||||||
|
handler = jasmine.createSpy('errorHandler'),
|
||||||
|
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||||
|
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
|
||||||
|
fakeGlobal.onerror = hijackHandler;
|
||||||
|
|
||||||
|
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||||
|
var reason;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Throwing ensures that we get a stack property in all browsers
|
||||||
|
throw new Error('bar');
|
||||||
|
} catch (e) {
|
||||||
|
reason = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
addedListener({ reason: reason });
|
||||||
|
|
||||||
|
expect(hijackHandler).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||||
|
message: reason.message,
|
||||||
|
stack: reason.stack
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(handler).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -512,6 +512,50 @@ describe('QueueRunner', function() {
|
|||||||
expect(onExceptionCallback).toHaveBeenCalledWith('foo');
|
expect(onExceptionCallback).toHaveBeenCalledWith('foo');
|
||||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('issues a deprecation if the function also takes a parameter', function() {
|
||||||
|
var queueableFn = {
|
||||||
|
fn: function(done) {
|
||||||
|
return new StubPromise();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deprecated = jasmine.createSpy('deprecated'),
|
||||||
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
|
queueableFns: [queueableFn],
|
||||||
|
deprecated: deprecated
|
||||||
|
}),
|
||||||
|
env = jasmineUnderTest.getEnv();
|
||||||
|
|
||||||
|
queueRunner.execute();
|
||||||
|
|
||||||
|
expect(deprecated).toHaveBeenCalledWith(
|
||||||
|
'An asynchronous ' +
|
||||||
|
'before/it/after function took a done callback but also returned a ' +
|
||||||
|
'promise. This is not supported and will stop working in the future. ' +
|
||||||
|
'Either remove the done callback (recommended) or change the function ' +
|
||||||
|
'to not return a promise.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('issues a more specific deprecation if the function is `async`', function() {
|
||||||
|
jasmine.getEnv().requireAsyncAwait();
|
||||||
|
eval('var fn = async function(done){};');
|
||||||
|
var deprecated = jasmine.createSpy('deprecated'),
|
||||||
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
|
queueableFns: [{ fn: fn }],
|
||||||
|
deprecated: deprecated
|
||||||
|
});
|
||||||
|
|
||||||
|
queueRunner.execute();
|
||||||
|
|
||||||
|
expect(deprecated).toHaveBeenCalledWith(
|
||||||
|
'An asynchronous ' +
|
||||||
|
'before/it/after function was defined with the async keyword but ' +
|
||||||
|
'also took a done callback. This is not supported and will stop ' +
|
||||||
|
'working in the future. Either remove the done callback ' +
|
||||||
|
'(recommended) or remove the async keyword.'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the error instance to exception handlers in HTML browsers', function() {
|
it('passes the error instance to exception handlers in HTML browsers', function() {
|
||||||
|
|||||||
@@ -183,14 +183,13 @@ describe('Spies', function() {
|
|||||||
var spyObj = env.createSpyObj('base', ['method1'], ['prop1']);
|
var spyObj = env.createSpyObj('base', ['method1'], ['prop1']);
|
||||||
|
|
||||||
expect(spyObj).toEqual({
|
expect(spyObj).toEqual({
|
||||||
method1: jasmine.any(Function)
|
method1: jasmine.any(Function),
|
||||||
|
prop1: undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
var descriptor = Object.getOwnPropertyDescriptor(spyObj, 'prop1');
|
var descriptor = Object.getOwnPropertyDescriptor(spyObj, 'prop1');
|
||||||
expect(descriptor.get.and.identity).toEqual('base.prop1.get');
|
expect(descriptor.get.and.identity).toEqual('base.prop1.get');
|
||||||
expect(descriptor.set.and.identity).toEqual('base.prop1.set');
|
expect(descriptor.set.and.identity).toEqual('base.prop1.set');
|
||||||
|
|
||||||
expect(spyObj.prop1).toBeUndefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates an object with property names and return values if second object is passed', function() {
|
it('creates an object with property names and return values if second object is passed', function() {
|
||||||
@@ -200,7 +199,9 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(spyObj).toEqual({
|
expect(spyObj).toEqual({
|
||||||
method1: jasmine.any(Function)
|
method1: jasmine.any(Function),
|
||||||
|
prop1: 'foo',
|
||||||
|
prop2: 37
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(spyObj.prop1).toEqual('foo');
|
expect(spyObj.prop1).toEqual('foo');
|
||||||
|
|||||||
@@ -334,6 +334,17 @@ describe('SpyStrategy', function() {
|
|||||||
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows generator functions to be passed to callFake strategy', function() {
|
||||||
|
jasmine.getEnv().requireGeneratorFunctions();
|
||||||
|
|
||||||
|
var generator = jasmine.getEnv().makeGeneratorFunction('yield "ok";'),
|
||||||
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
|
||||||
|
|
||||||
|
spyStrategy.callFake(generator);
|
||||||
|
|
||||||
|
expect(spyStrategy.exec().next().value).toEqual('ok');
|
||||||
|
});
|
||||||
|
|
||||||
it('allows a return to plan stubbing after another strategy', function() {
|
it('allows a return to plan stubbing after another strategy', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
var originalFn = jasmine.createSpy('original'),
|
||||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
|
|||||||
it('provides properties of Array.prototype', function() {
|
it('provides properties of Array.prototype', function() {
|
||||||
var keys = [
|
var keys = [
|
||||||
'concat',
|
'concat',
|
||||||
'constructor',
|
|
||||||
'every',
|
'every',
|
||||||
'filter',
|
'filter',
|
||||||
'forEach',
|
'forEach',
|
||||||
@@ -55,8 +54,6 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
|
|||||||
'some',
|
'some',
|
||||||
'sort',
|
'sort',
|
||||||
'splice',
|
'splice',
|
||||||
'toLocaleString',
|
|
||||||
'toString',
|
|
||||||
'unshift'
|
'unshift'
|
||||||
],
|
],
|
||||||
optionalKeys = [
|
optionalKeys = [
|
||||||
@@ -98,4 +95,46 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('When Array.prototype additions collide with MatchersUtil methods', function() {
|
||||||
|
function keys() {
|
||||||
|
return [
|
||||||
|
'contains',
|
||||||
|
'buildFailureMessage',
|
||||||
|
'asymmetricDiff_',
|
||||||
|
'asymmetricMatch_',
|
||||||
|
'equals',
|
||||||
|
'eq_'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
keys().forEach(function(k) {
|
||||||
|
expect(Array.prototype[k])
|
||||||
|
.withContext('Array.prototype already had ' + k)
|
||||||
|
.toBeUndefined();
|
||||||
|
Array.prototype[k] = function() {};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
keys().forEach(function(k) {
|
||||||
|
delete Array.prototype[k];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses the MatchersUtil methods', function() {
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({}),
|
||||||
|
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||||
|
matchersUtil,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
keys().forEach(function(k) {
|
||||||
|
expect(shim[k])
|
||||||
|
.withContext(k + ' was overwritten')
|
||||||
|
.toBe(jasmineUnderTest.MatchersUtil.prototype[k]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
describe("Any", function() {
|
describe('Any', function() {
|
||||||
it("matches a string", function() {
|
it('matches a string', function() {
|
||||||
var any = new jasmineUnderTest.Any(String);
|
var any = new jasmineUnderTest.Any(String);
|
||||||
|
|
||||||
expect(any.asymmetricMatch("foo")).toBe(true);
|
expect(any.asymmetricMatch('foo')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a number", function() {
|
it('matches a number', function() {
|
||||||
var any = new jasmineUnderTest.Any(Number);
|
var any = new jasmineUnderTest.Any(Number);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(1)).toBe(true);
|
expect(any.asymmetricMatch(1)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a function", function() {
|
it('matches a function', function() {
|
||||||
var any = new jasmineUnderTest.Any(Function);
|
var any = new jasmineUnderTest.Any(Function);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(function(){})).toBe(true);
|
expect(any.asymmetricMatch(function() {})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an Object", function() {
|
it('matches an Object', function() {
|
||||||
var any = new jasmineUnderTest.Any(Object);
|
var any = new jasmineUnderTest.Any(Object);
|
||||||
|
|
||||||
expect(any.asymmetricMatch({})).toBe(true);
|
expect(any.asymmetricMatch({})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Boolean", function() {
|
it('matches a Boolean', function() {
|
||||||
var any = new jasmineUnderTest.Any(Boolean);
|
var any = new jasmineUnderTest.Any(Boolean);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(true)).toBe(true);
|
expect(any.asymmetricMatch(true)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Map", function() {
|
it('matches a Map', function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var any = new jasmineUnderTest.Any(Map);
|
var any = new jasmineUnderTest.Any(Map);
|
||||||
@@ -37,7 +37,7 @@ describe("Any", function() {
|
|||||||
expect(any.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
expect(any.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Set", function() {
|
it('matches a Set', function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
var any = new jasmineUnderTest.Any(Set);
|
var any = new jasmineUnderTest.Any(Set);
|
||||||
@@ -45,7 +45,7 @@ describe("Any", function() {
|
|||||||
expect(any.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
expect(any.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a TypedArray", function() {
|
it('matches a TypedArray', function() {
|
||||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||||
|
|
||||||
var any = new jasmineUnderTest.Any(Uint32Array); // eslint-disable-line compat/compat
|
var any = new jasmineUnderTest.Any(Uint32Array); // eslint-disable-line compat/compat
|
||||||
@@ -53,7 +53,7 @@ describe("Any", function() {
|
|||||||
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
|
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Symbol", function() {
|
it('matches a Symbol', function() {
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var any = new jasmineUnderTest.Any(Symbol); // eslint-disable-line compat/compat
|
var any = new jasmineUnderTest.Any(Symbol); // eslint-disable-line compat/compat
|
||||||
@@ -61,14 +61,14 @@ describe("Any", function() {
|
|||||||
expect(any.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
|
expect(any.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches another constructed object", function() {
|
it('matches another constructed object', function() {
|
||||||
var Thing = function() {},
|
var Thing = function() {},
|
||||||
any = new jasmineUnderTest.Any(Thing);
|
any = new jasmineUnderTest.Any(Thing);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not treat null as an Object", function() {
|
it('does not treat null as an Object', function() {
|
||||||
var any = new jasmineUnderTest.Any(Object);
|
var any = new jasmineUnderTest.Any(Object);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(null)).toBe(false);
|
expect(any.asymmetricMatch(null)).toBe(false);
|
||||||
@@ -81,8 +81,8 @@ describe("Any", function() {
|
|||||||
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when called without an argument", function() {
|
describe('when called without an argument', function() {
|
||||||
it("tells the user to pass a constructor or use jasmine.anything()", function() {
|
it('tells the user to pass a constructor or use jasmine.anything()', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new jasmineUnderTest.Any();
|
new jasmineUnderTest.Any();
|
||||||
}).toThrowError(TypeError, /constructor.*anything/);
|
}).toThrowError(TypeError, /constructor.*anything/);
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
describe("Anything", function() {
|
describe('Anything', function() {
|
||||||
it("matches a string", function() {
|
it('matches a string', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch('foo')).toBe(true);
|
expect(anything.asymmetricMatch('foo')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a number", function() {
|
it('matches a number', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(42)).toBe(true);
|
expect(anything.asymmetricMatch(42)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an object", function() {
|
it('matches an object', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an array", function() {
|
it('matches an array', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
|
expect(anything.asymmetricMatch([1, 2, 3])).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Map", function() {
|
it('matches a Map', function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
@@ -31,7 +31,7 @@ describe("Anything", function() {
|
|||||||
expect(anything.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
expect(anything.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Set", function() {
|
it('matches a Set', function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
@@ -39,7 +39,7 @@ describe("Anything", function() {
|
|||||||
expect(anything.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
expect(anything.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a TypedArray", function() {
|
it('matches a TypedArray', function() {
|
||||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
@@ -47,7 +47,7 @@ describe("Anything", function() {
|
|||||||
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
|
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Symbol", function() {
|
it('matches a Symbol', function() {
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
@@ -71,6 +71,6 @@ describe("Anything", function() {
|
|||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.jasmineToString()).toEqual("<jasmine.anything>");
|
expect(anything.jasmineToString()).toEqual('<jasmine.anything>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,47 +1,47 @@
|
|||||||
describe("ArrayContaining", function() {
|
describe('ArrayContaining', function() {
|
||||||
it("matches any actual to an empty array", function() {
|
it('matches any actual to an empty array', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining([]);
|
var containing = new jasmineUnderTest.ArrayContaining([]);
|
||||||
|
|
||||||
expect(containing.asymmetricMatch("foo")).toBe(true);
|
expect(containing.asymmetricMatch('foo')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not work when not passed an array", function() {
|
it('does not work when not passed an array', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining("foo");
|
var containing = new jasmineUnderTest.ArrayContaining('foo');
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
containing.asymmetricMatch([]);
|
containing.asymmetricMatch([]);
|
||||||
}).toThrowError(/not 'foo'/);
|
}).toThrowError(/not 'foo'/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches when the item is in the actual", function() {
|
it('matches when the item is in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["foo"], matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(['foo'], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches when additional items are in the actual", function() {
|
it('matches when additional items are in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["foo", "bar"], matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(['foo', 'bar'], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when the item is not in the actual", function() {
|
it('does not match when the item is not in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["bar"], matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(['bar'], matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when the actual is not an array", function() {
|
it('does not match when the actual is not an array', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch("foo", matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch('foo', matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToStrings itself", function() {
|
it('jasmineToStrings itself', function() {
|
||||||
var sample = [],
|
var sample = [],
|
||||||
matcher = new jasmineUnderTest.ArrayContaining(sample),
|
matcher = new jasmineUnderTest.ArrayContaining(sample),
|
||||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
@@ -52,17 +52,23 @@ describe("ArrayContaining", function() {
|
|||||||
expect(pp).toHaveBeenCalledWith(sample);
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom equality testers", function() {
|
it('uses custom equality testers', function() {
|
||||||
var tester = function(a, b) {
|
var tester = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (typeof a == "string" && typeof b == "string" &&
|
if (
|
||||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
typeof a == 'string' &&
|
||||||
|
typeof b == 'string' &&
|
||||||
|
a.substr(0, 3) == 'foo' &&
|
||||||
|
b.substr(0, 3) == 'foo'
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
|
var containing = new jasmineUnderTest.ArrayContaining(['fooVal']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: [tester]
|
||||||
|
});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["fooBar"], matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(['fooBar'], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,35 +1,37 @@
|
|||||||
describe("ArrayWithExactContents", function() {
|
describe('ArrayWithExactContents', function() {
|
||||||
it("matches an array with the same items in a different order", function() {
|
it('matches an array with the same items in a different order', function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch([2, 'a', /a/], matchersUtil)).toBe(true);
|
expect(matcher.asymmetricMatch([2, 'a', /a/], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not work when not passed an array", function() {
|
it('does not work when not passed an array', function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents("foo");
|
var matcher = new jasmineUnderTest.ArrayWithExactContents('foo');
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.asymmetricMatch([]);
|
matcher.asymmetricMatch([]);
|
||||||
}).toThrowError(/not 'foo'/);
|
}).toThrowError(/not 'foo'/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when an item is missing", function() {
|
it('does not match when an item is missing', function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||||
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(false);
|
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when there is an extra item", function() {
|
it('does not match when there is an extra item', function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToStrings itself", function() {
|
it('jasmineToStrings itself', function() {
|
||||||
var sample = [],
|
var sample = [],
|
||||||
matcher = new jasmineUnderTest.ArrayWithExactContents(sample),
|
matcher = new jasmineUnderTest.ArrayWithExactContents(sample),
|
||||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
@@ -40,17 +42,23 @@ describe("ArrayWithExactContents", function() {
|
|||||||
expect(pp).toHaveBeenCalledWith(sample);
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom equality testers", function() {
|
it('uses custom equality testers', function() {
|
||||||
var tester = function(a, b) {
|
var tester = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (typeof a == "string" && typeof b == "string" &&
|
if (
|
||||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
typeof a == 'string' &&
|
||||||
|
typeof b == 'string' &&
|
||||||
|
a.substr(0, 3) == 'foo' &&
|
||||||
|
b.substr(0, 3) == 'foo'
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(["fooVal"]);
|
var matcher = new jasmineUnderTest.ArrayWithExactContents(['fooVal']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: [tester]
|
||||||
|
});
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(["fooBar"], matchersUtil)).toBe(true);
|
expect(matcher.asymmetricMatch(['fooBar'], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
describe("Empty", function () {
|
describe('Empty', function() {
|
||||||
it("matches an empty object", function () {
|
it('matches an empty object', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
var empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch({})).toBe(true);
|
expect(empty.asymmetricMatch({})).toBe(true);
|
||||||
expect(empty.asymmetricMatch({undefined: false})).toBe(false);
|
expect(empty.asymmetricMatch({ undefined: false })).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an empty array", function () {
|
it('matches an empty array', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
var empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch([])).toBe(true);
|
expect(empty.asymmetricMatch([])).toBe(true);
|
||||||
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
|
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an empty string", function () {
|
it('matches an empty string', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
var empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch("")).toBe(true);
|
expect(empty.asymmetricMatch('')).toBe(true);
|
||||||
expect(empty.asymmetricMatch('')).toBe(true);
|
expect(empty.asymmetricMatch('')).toBe(true);
|
||||||
expect(empty.asymmetricMatch('12312')).toBe(false);
|
expect(empty.asymmetricMatch('12312')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an empty map", function () {
|
it('matches an empty map', function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var empty = new jasmineUnderTest.Empty();
|
var empty = new jasmineUnderTest.Empty();
|
||||||
var fullMap = new Map(); // eslint-disable-line compat/compat
|
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||||
@@ -31,7 +31,7 @@ describe("Empty", function () {
|
|||||||
expect(empty.asymmetricMatch(fullMap)).toBe(false);
|
expect(empty.asymmetricMatch(fullMap)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an empty set", function () {
|
it('matches an empty set', function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
var empty = new jasmineUnderTest.Empty();
|
var empty = new jasmineUnderTest.Empty();
|
||||||
var fullSet = new Set(); // eslint-disable-line compat/compat
|
var fullSet = new Set(); // eslint-disable-line compat/compat
|
||||||
@@ -41,11 +41,11 @@ describe("Empty", function () {
|
|||||||
expect(empty.asymmetricMatch(fullSet)).toBe(false);
|
expect(empty.asymmetricMatch(fullSet)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches an empty typed array", function() {
|
it('matches an empty typed array', function() {
|
||||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||||
var empty = new jasmineUnderTest.Empty();
|
var empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true); // eslint-disable-line compat/compat
|
expect(empty.asymmetricMatch(new Int16Array())).toBe(true); // eslint-disable-line compat/compat
|
||||||
expect(empty.asymmetricMatch(new Int16Array([1,2]))).toBe(false); // eslint-disable-line compat/compat
|
expect(empty.asymmetricMatch(new Int16Array([1, 2]))).toBe(false); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
describe("Falsy", function() {
|
describe('Falsy', function() {
|
||||||
it("is true for an empty string", function() {
|
it('is true for an empty string', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy();
|
var falsy = new jasmineUnderTest.Falsy();
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch("")).toBe(true);
|
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||||
expect(falsy.asymmetricMatch('asdasdad')).toBe(false);
|
expect(falsy.asymmetricMatch('asdasdad')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is false for a number that is 0", function() {
|
it('is false for a number that is 0', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Number);
|
var falsy = new jasmineUnderTest.Falsy(Number);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(1)).toBe(false);
|
expect(falsy.asymmetricMatch(1)).toBe(false);
|
||||||
expect(falsy.asymmetricMatch(0)).toBe(true);
|
expect(falsy.asymmetricMatch(0)).toBe(true);
|
||||||
expect(falsy.asymmetricMatch(-23)).toBe(false);
|
expect(falsy.asymmetricMatch(-23)).toBe(false);
|
||||||
expect(falsy.asymmetricMatch(-3.1)).toBe(false);
|
expect(falsy.asymmetricMatch(-3.1)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for a null or undefined", function() {
|
it('is true for a null or undefined', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Function);
|
var falsy = new jasmineUnderTest.Falsy(Function);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(null)).toBe(true);
|
expect(falsy.asymmetricMatch(null)).toBe(true);
|
||||||
expect(falsy.asymmetricMatch(undefined )).toBe(true);
|
expect(falsy.asymmetricMatch(undefined)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for NaN", function() {
|
it('is true for NaN', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Object);
|
var falsy = new jasmineUnderTest.Falsy(Object);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(NaN)).toBe(true);
|
expect(falsy.asymmetricMatch(NaN)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for a false Boolean", function() {
|
it('is true for a false Boolean', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Boolean);
|
var falsy = new jasmineUnderTest.Falsy(Boolean);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(false)).toBe(true);
|
expect(falsy.asymmetricMatch(false)).toBe(true);
|
||||||
expect(falsy.asymmetricMatch(true)).toBe(false);
|
expect(falsy.asymmetricMatch(true)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable compat/compat */
|
/* eslint-disable compat/compat */
|
||||||
describe('MapContaining', function() {
|
describe('MapContaining', function() {
|
||||||
function MapI(iterable) { // for IE11
|
function MapI(iterable) {
|
||||||
|
// for IE11
|
||||||
var map = new Map();
|
var map = new Map();
|
||||||
iterable.forEach(function(kv) {
|
iterable.forEach(function(kv) {
|
||||||
map.set(kv[0], kv[1]);
|
map.set(kv[0], kv[1]);
|
||||||
@@ -12,7 +13,6 @@ describe('MapContaining', function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('matches any actual map to an empty map', function() {
|
it('matches any actual map to an empty map', function() {
|
||||||
var actualMap = new MapI([['foo', 'bar']]);
|
var actualMap = new MapI([['foo', 'bar']]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(new Map());
|
var containing = new jasmineUnderTest.MapContaining(new Map());
|
||||||
@@ -23,14 +23,11 @@ describe('MapContaining', function() {
|
|||||||
it('matches when all the key/value pairs in sample have matches in actual', function() {
|
it('matches when all the key/value pairs in sample have matches in actual', function() {
|
||||||
var actualMap = new MapI([
|
var actualMap = new MapI([
|
||||||
['foo', [1, 2, 3]],
|
['foo', [1, 2, 3]],
|
||||||
[{'foo': 'bar'}, 'baz'],
|
[{ foo: 'bar' }, 'baz'],
|
||||||
['other', 'any'],
|
['other', 'any']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
|
||||||
[{'foo': 'bar'}, 'baz'],
|
|
||||||
['foo', [1, 2, 3]],
|
|
||||||
]);
|
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
@@ -40,13 +37,10 @@ describe('MapContaining', function() {
|
|||||||
it('does not match when a key is not in actual', function() {
|
it('does not match when a key is not in actual', function() {
|
||||||
var actualMap = new MapI([
|
var actualMap = new MapI([
|
||||||
['foo', [1, 2, 3]],
|
['foo', [1, 2, 3]],
|
||||||
[{'foo': 'not a bar'}, 'baz'],
|
[{ foo: 'not a bar' }, 'baz']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
|
||||||
[{'foo': 'bar'}, 'baz'],
|
|
||||||
['foo', [1, 2, 3]],
|
|
||||||
]);
|
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
@@ -54,15 +48,9 @@ describe('MapContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value is not in actual', function() {
|
it('does not match when a value is not in actual', function() {
|
||||||
var actualMap = new MapI([
|
var actualMap = new MapI([['foo', [1, 2, 3]], [{ foo: 'bar' }, 'baz']]);
|
||||||
['foo', [1, 2, 3]],
|
|
||||||
[{'foo': 'bar'}, 'baz'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2]]]);
|
||||||
[{'foo': 'bar'}, 'baz'],
|
|
||||||
['foo', [1, 2]],
|
|
||||||
]);
|
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
@@ -73,18 +61,12 @@ describe('MapContaining', function() {
|
|||||||
var actualMap = new MapI([
|
var actualMap = new MapI([
|
||||||
['foo1', 'not a bar'],
|
['foo1', 'not a bar'],
|
||||||
['foo2', 'bar'],
|
['foo2', 'bar'],
|
||||||
['baz', [1, 2, 3, 4]],
|
['baz', [1, 2, 3, 4]]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([
|
||||||
[
|
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||||
'bar'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'baz',
|
|
||||||
jasmineUnderTest.arrayContaining([2, 3])
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
@@ -93,20 +75,11 @@ describe('MapContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a key in sample has no asymmetric matches in actual', function() {
|
it('does not match when a key in sample has no asymmetric matches in actual', function() {
|
||||||
var actualMap = new MapI([
|
var actualMap = new MapI([['a-foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||||
['a-foo1', 'bar'],
|
|
||||||
['baz', [1, 2, 3, 4]],
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([
|
||||||
[
|
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||||
'bar'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'baz',
|
|
||||||
jasmineUnderTest.arrayContaining([2, 3])
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
@@ -115,20 +88,11 @@ describe('MapContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
||||||
var actualMap = new MapI([
|
var actualMap = new MapI([['foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||||
['foo1', 'bar'],
|
|
||||||
['baz', [1, 2, 3, 4]],
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([
|
||||||
[
|
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
['baz', jasmineUnderTest.arrayContaining([4, 5])]
|
||||||
'bar'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'baz',
|
|
||||||
jasmineUnderTest.arrayContaining([4, 5])
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
@@ -140,18 +104,12 @@ describe('MapContaining', function() {
|
|||||||
var actualMap = new MapI([
|
var actualMap = new MapI([
|
||||||
['foo', new MapI([['foo1', 1], ['foo2', 2]])],
|
['foo', new MapI([['foo1', 1], ['foo2', 2]])],
|
||||||
[new MapI([[1, 'bar1'], [2, 'bar2']]), 'bar'],
|
[new MapI([[1, 'bar1'], [2, 'bar2']]), 'bar'],
|
||||||
['other', 'any'],
|
['other', 'any']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([
|
||||||
[
|
['foo', new jasmineUnderTest.MapContaining(new MapI([['foo1', 1]]))],
|
||||||
'foo',
|
[new jasmineUnderTest.MapContaining(new MapI([[2, 'bar2']])), 'bar']
|
||||||
new jasmineUnderTest.MapContaining(new MapI([['foo1', 1]]))
|
|
||||||
],
|
|
||||||
[
|
|
||||||
new jasmineUnderTest.MapContaining(new MapI([[2, 'bar2']])),
|
|
||||||
'bar'
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
@@ -162,25 +120,41 @@ describe('MapContaining', function() {
|
|||||||
it('uses custom equality testers', function() {
|
it('uses custom equality testers', function() {
|
||||||
function tester(a, b) {
|
function tester(a, b) {
|
||||||
// treat all negative numbers as equal
|
// treat all negative numbers as equal
|
||||||
return (typeof a == 'number' && typeof b == 'number') ? (a < 0 && b < 0) : a === b;
|
return typeof a == 'number' && typeof b == 'number'
|
||||||
|
? a < 0 && b < 0
|
||||||
|
: a === b;
|
||||||
}
|
}
|
||||||
var actualMap = new MapI([['foo', -1]]);
|
var actualMap = new MapI([['foo', -1]]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(new MapI([['foo', -2]]));
|
var containing = new jasmineUnderTest.MapContaining(
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
new MapI([['foo', -2]])
|
||||||
|
);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: [tester]
|
||||||
|
});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when actual is not a map', function() {
|
it('does not match when actual is not a map', function() {
|
||||||
var containingMap = new MapI([['foo', 'bar']]);
|
var containingMap = new MapI([['foo', 'bar']]);
|
||||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')).toBe(false);
|
expect(
|
||||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch(-1)).toBe(false);
|
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')
|
||||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch({'foo': 'bar'})).toBe(false);
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch(-1)
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch({
|
||||||
|
foo: 'bar'
|
||||||
|
})
|
||||||
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error when sample is not a map', function() {
|
it('throws an error when sample is not a map', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new jasmineUnderTest.MapContaining({'foo': 'bar'}).asymmetricMatch(new Map());
|
new jasmineUnderTest.MapContaining({ foo: 'bar' }).asymmetricMatch(
|
||||||
|
new Map()
|
||||||
|
);
|
||||||
}).toThrowError(/You must provide a map/);
|
}).toThrowError(/You must provide a map/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
describe("NotEmpty", function () {
|
describe('NotEmpty', function() {
|
||||||
it("matches a non empty object", function () {
|
it('matches a non empty object', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch({undefined: false})).toBe(true);
|
expect(notEmpty.asymmetricMatch({ undefined: false })).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch({})).toBe(false);
|
expect(notEmpty.asymmetricMatch({})).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a non empty array", function () {
|
it('matches a non empty array', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
|
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch([])).toBe(false);
|
expect(notEmpty.asymmetricMatch([])).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a non empty string", function () {
|
it('matches a non empty string', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
|
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch("")).toBe(false);
|
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||||
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a non empty map", function () {
|
it('matches a non empty map', function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
var fullMap = new Map(); // eslint-disable-line compat/compat
|
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||||
@@ -32,7 +32,7 @@ describe("NotEmpty", function () {
|
|||||||
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a non empty set", function () {
|
it('matches a non empty set', function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
var filledSet = new Set(); // eslint-disable-line compat/compat
|
var filledSet = new Set(); // eslint-disable-line compat/compat
|
||||||
@@ -43,11 +43,11 @@ describe("NotEmpty", function () {
|
|||||||
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
|
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a non empty typed array", function() {
|
it('matches a non empty typed array', function() {
|
||||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch(new Int16Array([1,2,3]))).toBe(true); // eslint-disable-line compat/compat
|
expect(notEmpty.asymmetricMatch(new Int16Array([1, 2, 3]))).toBe(true); // eslint-disable-line compat/compat
|
||||||
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false); // eslint-disable-line compat/compat
|
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,47 +1,55 @@
|
|||||||
describe("ObjectContaining", function() {
|
describe('ObjectContaining', function() {
|
||||||
|
it('matches any object actual to an empty object', function() {
|
||||||
it("matches any object actual to an empty object", function() {
|
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({foo: 1}, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch({ foo: 1 }, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when the actual is not an object", function() {
|
it('does not match when the actual is not an object', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||||
|
|
||||||
[1, true, undefined, "a string"].forEach(function(actual) {
|
[1, true, undefined, 'a string'].forEach(function(actual) {
|
||||||
expect(containing.asymmetricMatch(actual)).toBe(false);
|
expect(containing.asymmetricMatch(actual)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match an empty object actual", function() {
|
it('does not match an empty object actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining("foo");
|
var containing = new jasmineUnderTest.ObjectContaining('foo');
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
containing.asymmetricMatch({})
|
containing.asymmetricMatch({});
|
||||||
}).toThrowError(/not 'foo'/)
|
}).toThrowError(/not 'foo'/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches when the key/value pair is present in the actual", function() {
|
it('matches when the key/value pair is present in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"}, matchersUtil)).toBe(true);
|
expect(
|
||||||
|
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
||||||
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when the key/value pair is not present in the actual", function() {
|
it('does not match when the key/value pair is not present in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"}, matchersUtil)).toBe(false);
|
expect(
|
||||||
|
containing.asymmetricMatch(
|
||||||
|
{ bar: 'barVal', quux: 'quuxVal' },
|
||||||
|
matchersUtil
|
||||||
|
)
|
||||||
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when the key is present but the value is different in the actual", function() {
|
it('does not match when the key is present but the value is different in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "other"});
|
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'other' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"}, matchersUtil)).toBe(false);
|
expect(
|
||||||
|
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
||||||
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
@@ -53,46 +61,55 @@ describe("ObjectContaining", function() {
|
|||||||
'<jasmine.objectContaining(sample)>'
|
'<jasmine.objectContaining(sample)>'
|
||||||
);
|
);
|
||||||
expect(pp).toHaveBeenCalledWith(sample);
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches recursively", function() {
|
it('matches recursively', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({one: new jasmineUnderTest.ObjectContaining({two: {}})});
|
var containing = new jasmineUnderTest.ObjectContaining({
|
||||||
|
one: new jasmineUnderTest.ObjectContaining({ two: {} })
|
||||||
|
});
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({one: {two: {}}}, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch({ one: { two: {} } }, matchersUtil)).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches when key is present with undefined value", function() {
|
it('matches when key is present with undefined value', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({ one: undefined }, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch({ one: undefined }, matchersUtil)).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match when key with undefined value is not present", function() {
|
it('does not match when key with undefined value is not present', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({}, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch({}, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches defined properties", function(){
|
it('matches defined properties', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
var definedPropertyObject = {};
|
var definedPropertyObject = {};
|
||||||
Object.defineProperty(definedPropertyObject, "foo", {
|
Object.defineProperty(definedPropertyObject, 'foo', {
|
||||||
get: function() { return "fooVal" }
|
get: function() {
|
||||||
|
return 'fooVal';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
expect(containing.asymmetricMatch(definedPropertyObject, matchersUtil)).toBe(true);
|
expect(
|
||||||
|
containing.asymmetricMatch(definedPropertyObject, matchersUtil)
|
||||||
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches prototype properties", function(){
|
it('matches prototype properties', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
var prototypeObject = {foo: "fooVal"};
|
var prototypeObject = { foo: 'fooVal' };
|
||||||
var obj;
|
var obj;
|
||||||
|
|
||||||
if (Object.create) {
|
if (Object.create) {
|
||||||
@@ -107,23 +124,31 @@ describe("ObjectContaining", function() {
|
|||||||
expect(containing.asymmetricMatch(obj, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(obj, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom equality testers", function() {
|
it('uses custom equality testers', function() {
|
||||||
var tester = function(a, b) {
|
var tester = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (typeof a == "string" && typeof b == "string" &&
|
if (
|
||||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
typeof a == 'string' &&
|
||||||
|
typeof b == 'string' &&
|
||||||
|
a.substr(0, 3) == 'foo' &&
|
||||||
|
b.substr(0, 3) == 'foo'
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: [tester]
|
||||||
|
});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({foo: "fooBar"}, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch({ foo: 'fooBar' }, matchersUtil)).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("valuesForDiff_", function() {
|
describe('valuesForDiff_', function() {
|
||||||
describe("when other is not an object", function() {
|
describe('when other is not an object', function() {
|
||||||
it("sets self to jasmineToString()", function () {
|
it('sets self to jasmineToString()', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({}),
|
var containing = new jasmineUnderTest.ObjectContaining({}),
|
||||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
result = containing.valuesForDiff_('a', pp);
|
result = containing.valuesForDiff_('a', pp);
|
||||||
@@ -135,27 +160,31 @@ describe("ObjectContaining", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when other is an object", function() {
|
describe('when other is an object', function() {
|
||||||
it("includes keys that are present in both other and sample", function() {
|
it('includes keys that are present in both other and sample', function() {
|
||||||
var sample = {a: 1, b: 2},
|
var sample = { a: 1, b: 2 },
|
||||||
other = {a: 3, b: 4},
|
other = { a: 3, b: 4 },
|
||||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
result = containing.valuesForDiff_(other);
|
result = containing.valuesForDiff_(other);
|
||||||
|
|
||||||
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
expect(result.self).not.toBeInstanceOf(
|
||||||
|
jasmineUnderTest.ObjectContaining
|
||||||
|
);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
self: sample,
|
self: sample,
|
||||||
other: other
|
other: other
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("includes keys that are present only in sample", function() {
|
it('includes keys that are present only in sample', function() {
|
||||||
var sample = {a: 1, b: 2},
|
var sample = { a: 1, b: 2 },
|
||||||
other = {a: 3},
|
other = { a: 3 },
|
||||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
result = containing.valuesForDiff_(other);
|
result = containing.valuesForDiff_(other);
|
||||||
|
|
||||||
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
expect(result.self).not.toBeInstanceOf(
|
||||||
|
jasmineUnderTest.ObjectContaining
|
||||||
|
);
|
||||||
expect(containing.valuesForDiff_(other)).toEqual({
|
expect(containing.valuesForDiff_(other)).toEqual({
|
||||||
self: sample,
|
self: sample,
|
||||||
other: {
|
other: {
|
||||||
@@ -165,13 +194,15 @@ describe("ObjectContaining", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("omits keys that are present only in other", function() {
|
it('omits keys that are present only in other', function() {
|
||||||
var sample = {a: 1, b: 2},
|
var sample = { a: 1, b: 2 },
|
||||||
other = {a: 3, b: 4, c: 5},
|
other = { a: 3, b: 4, c: 5 },
|
||||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
result = containing.valuesForDiff_(other);
|
result = containing.valuesForDiff_(other);
|
||||||
|
|
||||||
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
expect(result.self).not.toBeInstanceOf(
|
||||||
|
jasmineUnderTest.ObjectContaining
|
||||||
|
);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
self: sample,
|
self: sample,
|
||||||
other: {
|
other: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable compat/compat */
|
/* eslint-disable compat/compat */
|
||||||
describe('SetContaining', function() {
|
describe('SetContaining', function() {
|
||||||
function SetI(iterable) { // for IE11
|
function SetI(iterable) {
|
||||||
|
// for IE11
|
||||||
var set = new Set();
|
var set = new Set();
|
||||||
iterable.forEach(function(v) {
|
iterable.forEach(function(v) {
|
||||||
set.add(v);
|
set.add(v);
|
||||||
@@ -12,7 +13,6 @@ describe('SetContaining', function() {
|
|||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('matches any actual set to an empty set', function() {
|
it('matches any actual set to an empty set', function() {
|
||||||
var actualSet = new SetI(['foo', 'bar']);
|
var actualSet = new SetI(['foo', 'bar']);
|
||||||
var containing = new jasmineUnderTest.SetContaining(new Set());
|
var containing = new jasmineUnderTest.SetContaining(new Set());
|
||||||
@@ -21,13 +21,9 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches when all the values in sample have matches in actual', function() {
|
it('matches when all the values in sample have matches in actual', function() {
|
||||||
var actualSet = new SetI([
|
var actualSet = new SetI([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||||
{'foo': 'bar'}, 'baz', [1, 2, 3]
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingSet = new SetI([
|
var containingSet = new SetI([[1, 2, 3], { foo: 'bar' }]);
|
||||||
[1, 2, 3], {'foo': 'bar'}
|
|
||||||
]);
|
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
@@ -35,13 +31,9 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value is not in actual', function() {
|
it('does not match when a value is not in actual', function() {
|
||||||
var actualSet = new SetI([
|
var actualSet = new SetI([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||||
{'foo': 'bar'}, 'baz', [1, 2, 3]
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingSet = new SetI([
|
var containingSet = new SetI([[1, 2], { foo: 'bar' }]);
|
||||||
[1, 2], {'foo': 'bar'}
|
|
||||||
]);
|
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
@@ -49,13 +41,11 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches when all the values in sample have asymmetric matches in actual', function() {
|
it('matches when all the values in sample have asymmetric matches in actual', function() {
|
||||||
var actualSet = new SetI([
|
var actualSet = new SetI([[1, 2, 3, 4], 'other', 'foo1']);
|
||||||
[1, 2, 3, 4], 'other', 'foo1'
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingSet = new SetI([
|
var containingSet = new SetI([
|
||||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||||
jasmineUnderTest.arrayContaining([2, 3]),
|
jasmineUnderTest.arrayContaining([2, 3])
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
@@ -64,13 +54,11 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
||||||
var actualSet = new SetI([
|
var actualSet = new SetI(['a-foo1', [1, 2, 3, 4], 'other']);
|
||||||
'a-foo1', [1, 2, 3, 4], 'other'
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingSet = new SetI([
|
var containingSet = new SetI([
|
||||||
jasmine.stringMatching(/^foo\d/),
|
jasmine.stringMatching(/^foo\d/),
|
||||||
jasmine.arrayContaining([2, 3]),
|
jasmine.arrayContaining([2, 3])
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
@@ -79,12 +67,11 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches recursively', function() {
|
it('matches recursively', function() {
|
||||||
var actualSet = new SetI([
|
var actualSet = new SetI(['foo', new SetI([1, 'bar', 2]), 'other']);
|
||||||
'foo', new SetI([1, 'bar', 2]), 'other'
|
|
||||||
]);
|
|
||||||
|
|
||||||
var containingSet = new SetI([
|
var containingSet = new SetI([
|
||||||
new jasmineUnderTest.SetContaining(new SetI(['bar'])), 'foo'
|
new jasmineUnderTest.SetContaining(new SetI(['bar'])),
|
||||||
|
'foo'
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
@@ -95,25 +82,37 @@ describe('SetContaining', function() {
|
|||||||
it('uses custom equality testers', function() {
|
it('uses custom equality testers', function() {
|
||||||
function tester(a, b) {
|
function tester(a, b) {
|
||||||
// treat all negative numbers as equal
|
// treat all negative numbers as equal
|
||||||
return (typeof a == 'number' && typeof b == 'number') ? (a < 0 && b < 0) : a === b;
|
return typeof a == 'number' && typeof b == 'number'
|
||||||
|
? a < 0 && b < 0
|
||||||
|
: a === b;
|
||||||
}
|
}
|
||||||
var actualSet = new SetI(['foo', -1]);
|
var actualSet = new SetI(['foo', -1]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(new SetI([-2, 'foo']));
|
var containing = new jasmineUnderTest.SetContaining(new SetI([-2, 'foo']));
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: [tester]
|
||||||
|
});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when actual is not a set', function() {
|
it('does not match when actual is not a set', function() {
|
||||||
var containingSet = new SetI(['foo']);
|
var containingSet = new SetI(['foo']);
|
||||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')).toBe(false);
|
expect(
|
||||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(1)).toBe(false);
|
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')
|
||||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(['foo'])).toBe(false);
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(1)
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(['foo'])
|
||||||
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error when sample is not a set', function() {
|
it('throws an error when sample is not a set', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new jasmineUnderTest.SetContaining({'foo': 'bar'}).asymmetricMatch(new Set());
|
new jasmineUnderTest.SetContaining({ foo: 'bar' }).asymmetricMatch(
|
||||||
|
new Set()
|
||||||
|
);
|
||||||
}).toThrowError(/You must provide a set/);
|
}).toThrowError(/You must provide a set/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
describe("StringMatching", function() {
|
describe('StringMatching', function() {
|
||||||
it("matches a string against a provided regexp", function() {
|
it('matches a string against a provided regexp', function() {
|
||||||
var matcher = new jasmineUnderTest.StringMatching(/foo/);
|
var matcher = new jasmineUnderTest.StringMatching(/foo/);
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a string against provided string", function() {
|
it('matches a string against provided string', function() {
|
||||||
var matcher = new jasmineUnderTest.StringMatching('foo');
|
var matcher = new jasmineUnderTest.StringMatching('foo');
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("raises an Error when the expected is not a String or RegExp", function() {
|
it('raises an Error when the expected is not a String or RegExp', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new jasmineUnderTest.StringMatching({});
|
new jasmineUnderTest.StringMatching({});
|
||||||
}).toThrowError(/not a String or a RegExp/);
|
}).toThrowError(/not a String or a RegExp/);
|
||||||
@@ -22,6 +22,8 @@ describe("StringMatching", function() {
|
|||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var matching = new jasmineUnderTest.StringMatching(/^foo/);
|
var matching = new jasmineUnderTest.StringMatching(/^foo/);
|
||||||
|
|
||||||
expect(matching.jasmineToString()).toEqual("<jasmine.stringMatching(/^foo/)>");
|
expect(matching.jasmineToString()).toEqual(
|
||||||
|
'<jasmine.stringMatching(/^foo/)>'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
describe("Truthy", function () {
|
describe('Truthy', function() {
|
||||||
it("is true for a non empty string", function () {
|
it('is true for a non empty string', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch("foo")).toBe(true);
|
expect(truthy.asymmetricMatch('foo')).toBe(true);
|
||||||
expect(truthy.asymmetricMatch("")).toBe(false);
|
expect(truthy.asymmetricMatch('')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for a number that is not 0", function () {
|
it('is true for a number that is not 0', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(1)).toBe(true);
|
expect(truthy.asymmetricMatch(1)).toBe(true);
|
||||||
@@ -15,49 +15,47 @@ describe("Truthy", function () {
|
|||||||
expect(truthy.asymmetricMatch(-3.1)).toBe(true);
|
expect(truthy.asymmetricMatch(-3.1)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for a function", function () {
|
it('is true for a function', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(function () {
|
expect(truthy.asymmetricMatch(function() {})).toBe(true);
|
||||||
})).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for an Object", function () {
|
it('is true for an Object', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for a truthful Boolean", function () {
|
it('is true for a truthful Boolean', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(true)).toBe(true);
|
expect(truthy.asymmetricMatch(true)).toBe(true);
|
||||||
expect(truthy.asymmetricMatch(false)).toBe(false);
|
expect(truthy.asymmetricMatch(false)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for an empty object", function () {
|
it('is true for an empty object', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for an empty array", function () {
|
it('is true for an empty array', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch([])).toBe(true);
|
expect(truthy.asymmetricMatch([])).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for a date", function () {
|
it('is true for a date', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(new Date())).toBe(true);
|
expect(truthy.asymmetricMatch(new Date())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is true for a infiniti", function () {
|
it('is true for a infiniti', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
var truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(Infinity)).toBe(true);
|
expect(truthy.asymmetricMatch(Infinity)).toBe(true);
|
||||||
expect(truthy.asymmetricMatch(-Infinity)).toBe(true);
|
expect(truthy.asymmetricMatch(-Infinity)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -62,4 +62,17 @@ describe('base helpers', function() {
|
|||||||
expect(jasmineUnderTest.isSet({})).toBe(false);
|
expect(jasmineUnderTest.isSet({})).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isURL', function() {
|
||||||
|
it('returns true when the object is a URL', function() {
|
||||||
|
jasmine.getEnv().requireUrls();
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
expect(jasmineUnderTest.isURL(new URL('http://localhost/'))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when the object is not a URL', function() {
|
||||||
|
jasmine.getEnv().requireUrls();
|
||||||
|
expect(jasmineUnderTest.isURL({})).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
describe('Asymmetric equality testers (Integration)', function () {
|
describe('Asymmetric equality testers (Integration)', function() {
|
||||||
function verifyPasses(expectations, setup) {
|
function verifyPasses(expectations, setup) {
|
||||||
it('passes', function (done) {
|
it('passes', function(done) {
|
||||||
var env = new jasmineUnderTest.Env();
|
var env = new jasmineUnderTest.Env();
|
||||||
env.it('a spec', function () {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function (result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
expect(result.passedExpectations.length)
|
expect(result.passedExpectations.length)
|
||||||
.withContext('Number of passed expectations')
|
.withContext('Number of passed expectations')
|
||||||
@@ -14,115 +14,122 @@ describe('Asymmetric equality testers (Integration)', function () {
|
|||||||
expect(result.failedExpectations.length)
|
expect(result.failedExpectations.length)
|
||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(0);
|
.toEqual(0);
|
||||||
expect(result.failedExpectations[0] && result.failedExpectations[0].message)
|
expect(
|
||||||
|
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||||
|
)
|
||||||
.withContext('Failure message')
|
.withContext('Failure message')
|
||||||
.toBeUndefined();
|
.toBeUndefined();
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFails(expectations) {
|
function verifyFails(expectations) {
|
||||||
it('fails', function (done) {
|
it('fails', function(done) {
|
||||||
var env = new jasmineUnderTest.Env();
|
var env = new jasmineUnderTest.Env();
|
||||||
env.it('a spec', function () {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function (result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('failed');
|
expect(result.status).toEqual('failed');
|
||||||
expect(result.failedExpectations.length)
|
expect(result.failedExpectations.length)
|
||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(1);
|
.toEqual(1);
|
||||||
expect(result.failedExpectations[0].message)
|
expect(result.failedExpectations[0].message)
|
||||||
.withContext('Failed with a thrown error rather than a matcher failure')
|
.withContext(
|
||||||
|
'Failed with a thrown error rather than a matcher failure'
|
||||||
|
)
|
||||||
.not.toMatch(/^Error: /);
|
.not.toMatch(/^Error: /);
|
||||||
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
.not.toEqual('');
|
.not.toEqual('');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('any', function () {
|
describe('any', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(5).toEqual(jasmineUnderTest.any(Number));
|
env.expect(5).toEqual(jasmineUnderTest.any(Number));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect("five").toEqual(jasmineUnderTest.any(Number));
|
env.expect('five').toEqual(jasmineUnderTest.any(Number));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('anything', function () {
|
describe('anything', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.expect('').toEqual(jasmineUnderTest.anything());
|
env.expect('').toEqual(jasmineUnderTest.anything());
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect(null).toEqual(jasmineUnderTest.anything());
|
env.expect(null).toEqual(jasmineUnderTest.anything());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('arrayContaining', function () {
|
describe('arrayContaining', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.addCustomEqualityTester(function (a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
env.expect([1, 2, 3]).toEqual(jasmineUnderTest.arrayContaining(["2"]));
|
env.expect([1, 2, 3]).toEqual(jasmineUnderTest.arrayContaining(['2']));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect(null).toEqual(jasmineUnderTest.arrayContaining([2]));
|
env.expect(null).toEqual(jasmineUnderTest.arrayContaining([2]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('arrayWithExactContents', function () {
|
describe('arrayWithExactContents', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.addCustomEqualityTester(function (a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
env.expect([1, 2]).toEqual(jasmineUnderTest.arrayWithExactContents(["2", "1"]));
|
env
|
||||||
|
.expect([1, 2])
|
||||||
|
.toEqual(jasmineUnderTest.arrayWithExactContents(['2', '1']));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect([]).toEqual(jasmineUnderTest.arrayWithExactContents([2]));
|
env.expect([]).toEqual(jasmineUnderTest.arrayWithExactContents([2]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('empty', function () {
|
describe('empty', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.expect([]).toEqual(jasmineUnderTest.empty());
|
env.expect([]).toEqual(jasmineUnderTest.empty());
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect([1]).toEqual(jasmineUnderTest.empty());
|
env.expect([1]).toEqual(jasmineUnderTest.empty());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('falsy', function () {
|
describe('falsy', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(false).toEqual(jasmineUnderTest.falsy());
|
env.expect(false).toEqual(jasmineUnderTest.falsy());
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect(true).toEqual(jasmineUnderTest.falsy());
|
env.expect(true).toEqual(jasmineUnderTest.falsy());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mapContaining', function () {
|
describe('mapContaining', function() {
|
||||||
if (jasmine.getEnv().hasFunctioningMaps()) {
|
if (jasmine.getEnv().hasFunctioningMaps()) {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
var actual = new Map();
|
var actual = new Map();
|
||||||
actual.set('a', "2");
|
actual.set('a', '2');
|
||||||
var expected = new Map();
|
var expected = new Map();
|
||||||
expected.set('a', 2);
|
expected.set('a', 2);
|
||||||
|
|
||||||
env.addCustomEqualityTester(function (a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,54 +137,62 @@ describe('Asymmetric equality testers (Integration)', function () {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
it('passes', function() {
|
it('passes', function() {
|
||||||
jasmine.getEnv().pending('Browser has incomplete or missing support for Maps');
|
jasmine
|
||||||
|
.getEnv()
|
||||||
|
.pending('Browser has incomplete or missing support for Maps');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jasmine.getEnv().hasFunctioningMaps()) {
|
if (jasmine.getEnv().hasFunctioningMaps()) {
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect('something').toEqual(jasmineUnderTest.mapContaining(new Map()));
|
env
|
||||||
|
.expect('something')
|
||||||
|
.toEqual(jasmineUnderTest.mapContaining(new Map()));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
it('fails', function() {
|
it('fails', function() {
|
||||||
jasmine.getEnv().pending('Browser has incomplete or missing support for Maps');
|
jasmine
|
||||||
|
.getEnv()
|
||||||
|
.pending('Browser has incomplete or missing support for Maps');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('notEmpty', function () {
|
describe('notEmpty', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.expect([1]).toEqual(jasmineUnderTest.notEmpty());
|
env.expect([1]).toEqual(jasmineUnderTest.notEmpty());
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect([]).toEqual(jasmineUnderTest.notEmpty());
|
env.expect([]).toEqual(jasmineUnderTest.notEmpty());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('objectContaining', function () {
|
describe('objectContaining', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.addCustomEqualityTester(function (a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
env.expect({a: 1, b: 2}).toEqual(jasmineUnderTest.objectContaining({a: "1"}));
|
env
|
||||||
|
.expect({ a: 1, b: 2 })
|
||||||
|
.toEqual(jasmineUnderTest.objectContaining({ a: '1' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect({}).toEqual(jasmineUnderTest.objectContaining({a: "1"}));
|
env.expect({}).toEqual(jasmineUnderTest.objectContaining({ a: '1' }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setContaining', function () {
|
describe('setContaining', function() {
|
||||||
if (jasmine.getEnv().hasFunctioningSets()) {
|
if (jasmine.getEnv().hasFunctioningSets()) {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
var actual = new Set();
|
var actual = new Set();
|
||||||
actual.add("1");
|
actual.add('1');
|
||||||
var expected = new Set();
|
var expected = new Set();
|
||||||
actual.add(1);
|
actual.add(1);
|
||||||
|
|
||||||
env.addCustomEqualityTester(function (a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -185,37 +200,43 @@ describe('Asymmetric equality testers (Integration)', function () {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
it('pases', function() {
|
it('pases', function() {
|
||||||
jasmine.getEnv().pending('Browser has incomplete or missing support for Sets');
|
jasmine
|
||||||
|
.getEnv()
|
||||||
|
.pending('Browser has incomplete or missing support for Sets');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jasmine.getEnv().hasFunctioningSets()) {
|
if (jasmine.getEnv().hasFunctioningSets()) {
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect('something').toEqual(jasmineUnderTest.setContaining(new Set()));
|
env
|
||||||
|
.expect('something')
|
||||||
|
.toEqual(jasmineUnderTest.setContaining(new Set()));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
it('fails', function() {
|
it('fails', function() {
|
||||||
jasmine.getEnv().pending('Browser has incomplete or missing support for Sets');
|
jasmine
|
||||||
|
.getEnv()
|
||||||
|
.pending('Browser has incomplete or missing support for Sets');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('stringMatching', function () {
|
describe('stringMatching', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.expect('foo').toEqual(jasmineUnderTest.stringMatching(/o/));
|
env.expect('foo').toEqual(jasmineUnderTest.stringMatching(/o/));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect('bar').toEqual(jasmineUnderTest.stringMatching(/o/));
|
env.expect('bar').toEqual(jasmineUnderTest.stringMatching(/o/));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('truthy', function () {
|
describe('truthy', function() {
|
||||||
verifyPasses(function (env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(true).toEqual(jasmineUnderTest.truthy());
|
env.expect(true).toEqual(jasmineUnderTest.truthy());
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function (env) {
|
verifyFails(function(env) {
|
||||||
env.expect(false).toEqual(jasmineUnderTest.truthy());
|
env.expect(false).toEqual(jasmineUnderTest.truthy());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
env.configure({random: false});
|
env.configure({ random: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@@ -17,7 +17,11 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
env.it('spec using custom async matcher', function() {
|
env.it('spec using custom async matcher', function() {
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
return { compare: function() { return Promise.resolve({ pass: true }); } };
|
return {
|
||||||
|
compare: function() {
|
||||||
|
return Promise.resolve({ pass: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -28,8 +32,8 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
||||||
@@ -39,8 +43,12 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() { return Promise.resolve({ pass: true }); },
|
compare: function() {
|
||||||
negativeCompare: function() { return Promise.resolve({ pass: true }); }
|
return Promise.resolve({ pass: true });
|
||||||
|
},
|
||||||
|
negativeCompare: function() {
|
||||||
|
return Promise.resolve({ pass: true });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -52,8 +60,8 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
|
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
|
||||||
@@ -74,30 +82,34 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
"Expected 'a' to be real."
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: remove this in the next major release.
|
// TODO: remove this in the next major release.
|
||||||
it("passes the jasmine utility and current equality testers to the matcher factory", function(done) {
|
it('passes the jasmine utility and current equality testers to the matcher factory', function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcherFactory = function () {
|
var matcherFactory = function() {
|
||||||
return {
|
return {
|
||||||
compare: function () {
|
compare: function() {
|
||||||
return Promise.resolve({pass: true});
|
return Promise.resolve({ pass: true });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy").and.callFake(matcherFactory),
|
matcherFactorySpy = jasmine
|
||||||
customEqualityFn = function () {
|
.createSpy('matcherFactorySpy')
|
||||||
|
.and.callFake(matcherFactory),
|
||||||
|
customEqualityFn = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
env.it("spec with expectation", function() {
|
env.it('spec with expectation', function() {
|
||||||
env.addCustomEqualityTester(customEqualityFn);
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: matcherFactorySpy
|
toBeReal: matcherFactorySpy
|
||||||
@@ -113,39 +125,43 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("provides custom equality testers to the matcher factory via matchersUtil", function(done) {
|
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcherFactory = function (matchersUtil) {
|
var matcherFactory = function(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function (actual, expected) {
|
compare: function(actual, expected) {
|
||||||
return Promise.resolve({pass: matchersUtil.equals(actual[0], expected)});
|
return Promise.resolve({
|
||||||
|
pass: matchersUtil.equals(actual[0], expected)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
customEqualityFn = jasmine.createSpy("customEqualityFn").and.callFake(function (a, b) {
|
customEqualityFn = jasmine
|
||||||
return a.toString() === b;
|
.createSpy('customEqualityFn')
|
||||||
});
|
.and.callFake(function(a, b) {
|
||||||
|
return a.toString() === b;
|
||||||
|
});
|
||||||
|
|
||||||
env.it("spec with expectation", function() {
|
env.it('spec with expectation', function() {
|
||||||
env.addCustomEqualityTester(customEqualityFn);
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeArrayWithFirstElement: matcherFactory
|
toBeArrayWithFirstElement: matcherFactory
|
||||||
});
|
});
|
||||||
|
|
||||||
return env.expectAsync([1, 2]).toBeArrayWithFirstElement("1");
|
return env.expectAsync([1, 2]).toBeArrayWithFirstElement('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
var specExpectations = function(result) {
|
||||||
expect(customEqualityFn).toHaveBeenCalledWith(1, "1");
|
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
||||||
expect(result.failedExpectations).toEqual([]);
|
expect(result.failedExpectations).toEqual([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,52 +1,65 @@
|
|||||||
describe("Custom Matchers (Integration)", function () {
|
describe('Custom Matchers (Integration)', function() {
|
||||||
var env;
|
var env;
|
||||||
var fakeTimer;
|
var fakeTimer;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
env.configure({random: false});
|
env.configure({ random: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows adding more matchers local to a spec", function (done) {
|
it('allows adding more matchers local to a spec', function(done) {
|
||||||
env.it('spec defining a custom matcher', function () {
|
env.it('spec defining a custom matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
matcherForSpec: function () {
|
matcherForSpec: function() {
|
||||||
return {
|
return {
|
||||||
compare: function (actual, expected) {
|
compare: function(actual, expected) {
|
||||||
return {pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected};
|
return {
|
||||||
|
pass: false,
|
||||||
|
message:
|
||||||
|
'matcherForSpec: actual: ' +
|
||||||
|
actual +
|
||||||
|
'; expected: ' +
|
||||||
|
expected
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
env.expect("zzz").matcherForSpec("yyy");
|
env.expect('zzz').matcherForSpec('yyy');
|
||||||
});
|
});
|
||||||
|
|
||||||
env.it("spec without custom matcher defined", function() {
|
env.it('spec without custom matcher defined', function() {
|
||||||
expect(env.expect("zzz").matcherForSpec).toBeUndefined();
|
expect(env.expect('zzz').matcherForSpec).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specDoneSpy = jasmine.createSpy("specDoneSpy");
|
var specDoneSpy = jasmine.createSpy('specDoneSpy');
|
||||||
var expectations = function() {
|
var expectations = function() {
|
||||||
var firstSpecResult = specDoneSpy.calls.first().args[0];
|
var firstSpecResult = specDoneSpy.calls.first().args[0];
|
||||||
expect(firstSpecResult.status).toEqual("failed");
|
expect(firstSpecResult.status).toEqual('failed');
|
||||||
expect(firstSpecResult.failedExpectations[0].message).toEqual("matcherForSpec: actual: zzz; expected: yyy");
|
expect(firstSpecResult.failedExpectations[0].message).toEqual(
|
||||||
|
'matcherForSpec: actual: zzz; expected: yyy'
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
env.addReporter({ specDone:specDoneSpy, jasmineDone: expectations});
|
env.addReporter({ specDone: specDoneSpy });
|
||||||
|
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes the spec if the custom matcher passes", function(done) {
|
it('passes the spec if the custom matcher passes', function(done) {
|
||||||
env.it("spec using custom matcher", function() {
|
env.it('spec using custom matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
return { compare: function() { return { pass: true }; } };
|
return {
|
||||||
|
compare: function() {
|
||||||
|
return { pass: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -57,66 +70,80 @@ describe("Custom Matchers (Integration)", function () {
|
|||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers", function(done) {
|
it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', function(done) {
|
||||||
env.it("spec using custom equality matcher", function() {
|
env.it('spec using custom equality matcher', function() {
|
||||||
var customEqualityFn = function(a, b) {
|
var customEqualityFn = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (typeof a == "string" && typeof b == "string" &&
|
if (
|
||||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
typeof a == 'string' &&
|
||||||
|
typeof b == 'string' &&
|
||||||
|
a.substr(0, 3) == 'foo' &&
|
||||||
|
b.substr(0, 3) == 'foo'
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addCustomEqualityTester(customEqualityFn);
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
env.expect({foo: 'fooValue'}).toEqual(jasmineUnderTest.objectContaining({foo: 'fooBar'}));
|
env
|
||||||
env.expect(['fooValue', 'things']).toEqual(jasmineUnderTest.arrayContaining(['fooBar']));
|
.expect({ foo: 'fooValue' })
|
||||||
env.expect(['fooValue']).toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
.toEqual(jasmineUnderTest.objectContaining({ foo: 'fooBar' }));
|
||||||
|
env
|
||||||
|
.expect(['fooValue', 'things'])
|
||||||
|
.toEqual(jasmineUnderTest.arrayContaining(['fooBar']));
|
||||||
|
env
|
||||||
|
.expect(['fooValue'])
|
||||||
|
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("supports asymmetric equality testers that take a list of custom equality testers", function(done) {
|
it('supports asymmetric equality testers that take a list of custom equality testers', function(done) {
|
||||||
// TODO: remove this in the next major release.
|
// TODO: remove this in the next major release.
|
||||||
spyOn(jasmineUnderTest, 'getEnv').and.returnValue(env);
|
spyOn(jasmineUnderTest, 'getEnv').and.returnValue(env);
|
||||||
|
|
||||||
env.it("spec using custom asymmetric equality tester", function() {
|
env.it('spec using custom asymmetric equality tester', function() {
|
||||||
var customEqualityFn = function(a, b) {
|
var customEqualityFn = function(a, b) {
|
||||||
if (a === 2 && b === "two") {
|
if (a === 2 && b === 'two') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var arrayWithFirstElement = function(sample) {
|
var arrayWithFirstElement = function(sample) {
|
||||||
return {
|
return {
|
||||||
asymmetricMatch: function (actual, customEqualityTesters) {
|
asymmetricMatch: function(actual, customEqualityTesters) {
|
||||||
return jasmineUnderTest.matchersUtil.equals(sample, actual[0], customEqualityTesters);
|
return jasmineUnderTest.matchersUtil.equals(
|
||||||
|
sample,
|
||||||
|
actual[0],
|
||||||
|
customEqualityTesters
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addCustomEqualityTester(customEqualityFn);
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
env.expect(["two"]).toEqual(arrayWithFirstElement(2));
|
env.expect(['two']).toEqual(arrayWithFirstElement(2));
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("displays an appropriate failure message if a custom equality matcher fails", function(done) {
|
it('displays an appropriate failure message if a custom equality matcher fails', function(done) {
|
||||||
env.it("spec using custom equality matcher", function() {
|
env.it('spec using custom equality matcher', function() {
|
||||||
var customEqualityFn = function(a, b) {
|
var customEqualityFn = function(a, b) {
|
||||||
// "foo" is not equal to anything
|
// "foo" is not equal to anything
|
||||||
if (a === 'foo' || b === 'foo') {
|
if (a === 'foo' || b === 'foo') {
|
||||||
@@ -125,7 +152,7 @@ describe("Custom Matchers (Integration)", function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
env.addCustomEqualityTester(customEqualityFn);
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
env.expect({foo: 'foo'}).toEqual({foo: 'foo'});
|
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
var specExpectations = function(result) {
|
||||||
@@ -135,17 +162,21 @@ describe("Custom Matchers (Integration)", function () {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses the negative compare function for a negative comparison, if provided", function(done) {
|
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
||||||
env.it("spec with custom negative comparison matcher", function() {
|
env.it('spec with custom negative comparison matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() { return { pass: true }; },
|
compare: function() {
|
||||||
negativeCompare: function() { return { pass: true }; }
|
return { pass: true };
|
||||||
|
},
|
||||||
|
negativeCompare: function() {
|
||||||
|
return { pass: true };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -157,11 +188,11 @@ describe("Custom Matchers (Integration)", function () {
|
|||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
|
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
|
||||||
env.it('spec with an expectation', function() {
|
env.it('spec with an expectation', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -169,25 +200,29 @@ describe("Custom Matchers (Integration)", function () {
|
|||||||
compare: function() {
|
compare: function() {
|
||||||
return { pass: false };
|
return { pass: false };
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
env.expect("a").toBeReal();
|
env.expect('a').toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
"Expected 'a' to be real."
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes the expected and actual arguments to the comparison function", function(done) {
|
it('passes the expected and actual arguments to the comparison function', function(done) {
|
||||||
var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
|
var argumentSpy = jasmine
|
||||||
|
.createSpy('argument spy')
|
||||||
|
.and.returnValue({ pass: true });
|
||||||
|
|
||||||
env.it('spec with an expectation', function () {
|
env.it('spec with an expectation', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
return { compare: argumentSpy };
|
return { compare: argumentSpy };
|
||||||
@@ -195,28 +230,37 @@ describe("Custom Matchers (Integration)", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
env.expect(true).toBeReal();
|
env.expect(true).toBeReal();
|
||||||
env.expect(true).toBeReal("arg");
|
env.expect(true).toBeReal('arg');
|
||||||
env.expect(true).toBeReal("arg1", "arg2");
|
env.expect(true).toBeReal('arg1', 'arg2');
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function() {
|
var specExpectations = function() {
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true);
|
expect(argumentSpy).toHaveBeenCalledWith(true);
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true, "arg");
|
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true, "arg1", "arg2");
|
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: remove this in the next major release.
|
// TODO: remove this in the next major release.
|
||||||
it("passes the jasmine utility and current equality testers to the matcher factory", function(done) {
|
it('passes the jasmine utility and current equality testers to the matcher factory', function(done) {
|
||||||
var matcherFactory = function() { return { compare: function() { return {pass: true}; }}; },
|
var matcherFactory = function() {
|
||||||
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy").and.callFake(matcherFactory),
|
return {
|
||||||
customEqualityFn = function() { return true; };
|
compare: function() {
|
||||||
|
return { pass: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
matcherFactorySpy = jasmine
|
||||||
|
.createSpy('matcherFactorySpy')
|
||||||
|
.and.callFake(matcherFactory),
|
||||||
|
customEqualityFn = function() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
env.it('spec with expectation', function() {
|
||||||
env.it("spec with expectation", function() {
|
|
||||||
env.addCustomEqualityTester(customEqualityFn);
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: matcherFactorySpy
|
toBeReal: matcherFactorySpy
|
||||||
@@ -232,37 +276,39 @@ describe("Custom Matchers (Integration)", function () {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("provides custom equality testers to the matcher factory via matchersUtil", function (done) {
|
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
||||||
var matcherFactory = function (matchersUtil) {
|
var matcherFactory = function(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function (actual, expected) {
|
compare: function(actual, expected) {
|
||||||
return {pass: matchersUtil.equals(actual[0], expected)};
|
return { pass: matchersUtil.equals(actual[0], expected) };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
customEqualityFn = jasmine.createSpy("customEqualityFn").and.callFake(function (a, b) {
|
customEqualityFn = jasmine
|
||||||
return a.toString() === b;
|
.createSpy('customEqualityFn')
|
||||||
});
|
.and.callFake(function(a, b) {
|
||||||
|
return a.toString() === b;
|
||||||
|
});
|
||||||
|
|
||||||
env.it("spec with expectation", function () {
|
env.it('spec with expectation', function() {
|
||||||
env.addCustomEqualityTester(customEqualityFn);
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeArrayWithFirstElement: matcherFactory
|
toBeArrayWithFirstElement: matcherFactory
|
||||||
});
|
});
|
||||||
|
|
||||||
env.expect([1, 2]).toBeArrayWithFirstElement("1");
|
env.expect([1, 2]).toBeArrayWithFirstElement('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function (result) {
|
var specExpectations = function(result) {
|
||||||
expect(customEqualityFn).toHaveBeenCalledWith(1, "1");
|
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
||||||
expect(result.failedExpectations).toEqual([]);
|
expect(result.failedExpectations).toEqual([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
describe("Custom object formatters", function() {
|
describe('Custom object formatters', function() {
|
||||||
var env;
|
var env;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
env.configure({random: false});
|
env.configure({ random: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("scopes custom object formatters to a spec", function(done) {
|
it('scopes custom object formatters to a spec', function(done) {
|
||||||
env.it('a spec with custom pretty-printer', function() {
|
env.it('a spec with custom pretty-printer', function() {
|
||||||
env.addCustomObjectFormatter(function(obj) { return 'custom(' + obj + ')'; });
|
env.addCustomObjectFormatter(function(obj) {
|
||||||
|
return 'custom(' + obj + ')';
|
||||||
|
});
|
||||||
env.expect(42).toBeUndefined();
|
env.expect(42).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,23 +23,29 @@ describe("Custom object formatters", function() {
|
|||||||
specResults.push(result);
|
specResults.push(result);
|
||||||
};
|
};
|
||||||
var expectations = function() {
|
var expectations = function() {
|
||||||
expect(specResults[0].failedExpectations[0].message).toEqual("Expected custom(42) to be undefined.");
|
expect(specResults[0].failedExpectations[0].message).toEqual(
|
||||||
expect(specResults[1].failedExpectations[0].message).toEqual("Expected 42 to be undefined.");
|
'Expected custom(42) to be undefined.'
|
||||||
|
);
|
||||||
|
expect(specResults[1].failedExpectations[0].message).toEqual(
|
||||||
|
'Expected 42 to be undefined.'
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
env.addReporter({ specDone:specDone, jasmineDone: expectations});
|
env.addReporter({ specDone: specDone });
|
||||||
|
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("scopes custom object formatters to a suite", function(done) {
|
it('scopes custom object formatters to a suite', function(done) {
|
||||||
env.it('a spec without custom pretty-printer', function() {
|
env.it('a spec without custom pretty-printer', function() {
|
||||||
env.expect(42).toBeUndefined();
|
env.expect(42).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
env.describe('with custom pretty-printer', function() {
|
env.describe('with custom pretty-printer', function() {
|
||||||
env.beforeEach(function() {
|
env.beforeAll(function() {
|
||||||
env.addCustomObjectFormatter(function(obj) { return 'custom(' + obj + ')'; });
|
env.addCustomObjectFormatter(function(obj) {
|
||||||
|
return 'custom(' + obj + ')';
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
@@ -50,18 +58,24 @@ describe("Custom object formatters", function() {
|
|||||||
specResults.push(result);
|
specResults.push(result);
|
||||||
};
|
};
|
||||||
var expectations = function() {
|
var expectations = function() {
|
||||||
expect(specResults[0].failedExpectations[0].message).toEqual("Expected 42 to be undefined.");
|
expect(specResults[0].failedExpectations[0].message).toEqual(
|
||||||
expect(specResults[1].failedExpectations[0].message).toEqual("Expected custom(42) to be undefined.");
|
'Expected 42 to be undefined.'
|
||||||
|
);
|
||||||
|
expect(specResults[1].failedExpectations[0].message).toEqual(
|
||||||
|
'Expected custom(42) to be undefined.'
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
env.addReporter({ specDone:specDone, jasmineDone: expectations});
|
env.addReporter({ specDone: specDone });
|
||||||
|
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception if you try to add a custom object formatter outside a runable", function() {
|
it('throws an exception if you try to add a custom object formatter outside a runable', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
env.addCustomObjectFormatter(function() {});
|
env.addCustomObjectFormatter(function() {});
|
||||||
}).toThrowError('Custom object formatters must be added in a before function or a spec')
|
}).toThrowError(
|
||||||
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
env.configure({random: false});
|
env.configure({ random: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@@ -11,10 +11,9 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows adding more strategies local to a suite', function(done) {
|
it('allows adding more strategies local to a suite', function(done) {
|
||||||
var plan = jasmine.createSpy('custom strategy plan')
|
var plan = jasmine.createSpy('custom strategy plan').and.returnValue(42);
|
||||||
.and.returnValue(42);
|
var strategy = jasmine.createSpy('custom strategy').and.returnValue(plan);
|
||||||
var strategy = jasmine.createSpy('custom strategy')
|
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||||
.and.returnValue(plan);
|
|
||||||
|
|
||||||
env.describe('suite defining a custom spy strategy', function() {
|
env.describe('suite defining a custom spy strategy', function() {
|
||||||
env.beforeEach(function() {
|
env.beforeEach(function() {
|
||||||
@@ -33,20 +32,20 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
function jasmineDone(result) {
|
function expectations() {
|
||||||
|
var result = jasmineDone.calls.argsFor(0)[0];
|
||||||
expect(result.overallStatus).toEqual('passed');
|
expect(result.overallStatus).toEqual('passed');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
env.addReporter({ jasmineDone: jasmineDone });
|
env.addReporter({ jasmineDone: jasmineDone });
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows adding more strategies local to a spec', function(done) {
|
it('allows adding more strategies local to a spec', function(done) {
|
||||||
var plan = jasmine.createSpy('custom strategy plan')
|
var plan = jasmine.createSpy('custom strategy plan').and.returnValue(42);
|
||||||
.and.returnValue(42);
|
var strategy = jasmine.createSpy('custom strategy').and.returnValue(plan);
|
||||||
var strategy = jasmine.createSpy('custom strategy')
|
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||||
.and.returnValue(plan);
|
|
||||||
|
|
||||||
env.it('spec defining a custom spy strategy', function() {
|
env.it('spec defining a custom spy strategy', function() {
|
||||||
env.addSpyStrategy('frobnicate', strategy);
|
env.addSpyStrategy('frobnicate', strategy);
|
||||||
@@ -60,26 +59,28 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
function jasmineDone(result) {
|
function expectations() {
|
||||||
|
var result = jasmineDone.calls.argsFor(0)[0];
|
||||||
expect(result.overallStatus).toEqual('passed');
|
expect(result.overallStatus).toEqual('passed');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
env.addReporter({ jasmineDone: jasmineDone });
|
env.addReporter({ jasmineDone: jasmineDone });
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows using custom strategies on a per-argument basis', function(done) {
|
it('allows using custom strategies on a per-argument basis', function(done) {
|
||||||
var plan = jasmine.createSpy('custom strategy plan')
|
var plan = jasmine.createSpy('custom strategy plan').and.returnValue(42);
|
||||||
.and.returnValue(42);
|
var strategy = jasmine.createSpy('custom strategy').and.returnValue(plan);
|
||||||
var strategy = jasmine.createSpy('custom strategy')
|
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||||
.and.returnValue(plan);
|
|
||||||
|
|
||||||
env.it('spec defining a custom spy strategy', function() {
|
env.it('spec defining a custom spy strategy', function() {
|
||||||
env.addSpyStrategy('frobnicate', strategy);
|
env.addSpyStrategy('frobnicate', strategy);
|
||||||
var spy = env.createSpy('something')
|
var spy = env
|
||||||
|
.createSpy('something')
|
||||||
.and.returnValue('no args return')
|
.and.returnValue('no args return')
|
||||||
.withArgs(1, 2, 3).and.frobnicate(17);
|
.withArgs(1, 2, 3)
|
||||||
|
.and.frobnicate(17);
|
||||||
|
|
||||||
expect(spy()).toEqual('no args return');
|
expect(spy()).toEqual('no args return');
|
||||||
expect(plan).not.toHaveBeenCalled();
|
expect(plan).not.toHaveBeenCalled();
|
||||||
@@ -91,13 +92,14 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
function jasmineDone(result) {
|
function expectations() {
|
||||||
|
var result = jasmineDone.calls.argsFor(0)[0];
|
||||||
expect(result.overallStatus).toEqual('passed');
|
expect(result.overallStatus).toEqual('passed');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
env.addReporter({ jasmineDone: jasmineDone });
|
env.addReporter({ jasmineDone: jasmineDone });
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows multiple custom strategies to be used', function(done) {
|
it('allows multiple custom strategies to be used', function(done) {
|
||||||
@@ -105,7 +107,8 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
strategy1 = jasmine.createSpy('strat 1').and.returnValue(plan1),
|
strategy1 = jasmine.createSpy('strat 1').and.returnValue(plan1),
|
||||||
plan2 = jasmine.createSpy('plan 2').and.returnValue(24),
|
plan2 = jasmine.createSpy('plan 2').and.returnValue(24),
|
||||||
strategy2 = jasmine.createSpy('strat 2').and.returnValue(plan2),
|
strategy2 = jasmine.createSpy('strat 2').and.returnValue(plan2),
|
||||||
specDone = jasmine.createSpy('specDone');
|
specDone = jasmine.createSpy('specDone'),
|
||||||
|
jasmineDone = jasmine.createSpy('jasmineDone');
|
||||||
|
|
||||||
env.beforeEach(function() {
|
env.beforeEach(function() {
|
||||||
env.addSpyStrategy('frobnicate', strategy1);
|
env.addSpyStrategy('frobnicate', strategy1);
|
||||||
@@ -130,13 +133,14 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
expect(plan2).toHaveBeenCalled();
|
expect(plan2).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
function jasmineDone(result) {
|
function expectations() {
|
||||||
|
var result = jasmineDone.calls.argsFor(0)[0];
|
||||||
expect(result.overallStatus).toEqual('passed');
|
expect(result.overallStatus).toEqual('passed');
|
||||||
expect(specDone.calls.count()).toBe(2);
|
expect(specDone.calls.count()).toBe(2);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
env.addReporter({ jasmineDone: jasmineDone, specDone: specDone });
|
env.addReporter({ jasmineDone: jasmineDone, specDone: specDone });
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ describe('Default Spy Strategy (Integration)', function() {
|
|||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
env.configure({random: false});
|
env.configure({ random: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@@ -13,7 +13,7 @@ describe('Default Spy Strategy (Integration)', function() {
|
|||||||
it('allows defining a default spy strategy', function(done) {
|
it('allows defining a default spy strategy', function(done) {
|
||||||
env.describe('suite with default strategy', function() {
|
env.describe('suite with default strategy', function() {
|
||||||
env.beforeEach(function() {
|
env.beforeEach(function() {
|
||||||
env.setDefaultSpyStrategy(function (and) {
|
env.setDefaultSpyStrategy(function(and) {
|
||||||
and.returnValue(42);
|
and.returnValue(42);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -29,21 +29,27 @@ describe('Default Spy Strategy (Integration)', function() {
|
|||||||
expect(spy()).toBeUndefined();
|
expect(spy()).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
function jasmineDone(result) {
|
function expectations() {
|
||||||
|
var result = jasmineDone.calls.argsFor(0)[0];
|
||||||
expect(result.overallStatus).toEqual('passed');
|
expect(result.overallStatus).toEqual('passed');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||||
env.addReporter({ jasmineDone: jasmineDone });
|
env.addReporter({ jasmineDone: jasmineDone });
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the default spy strategy defined when the spy is created', function (done) {
|
it('uses the default spy strategy defined when the spy is created', function(done) {
|
||||||
env.it('spec', function() {
|
env.it('spec', function() {
|
||||||
var a = env.createSpy('a');
|
var a = env.createSpy('a');
|
||||||
env.setDefaultSpyStrategy(function (and) { and.returnValue(42); });
|
env.setDefaultSpyStrategy(function(and) {
|
||||||
|
and.returnValue(42);
|
||||||
|
});
|
||||||
var b = env.createSpy('b');
|
var b = env.createSpy('b');
|
||||||
env.setDefaultSpyStrategy(function (and) { and.stub(); });
|
env.setDefaultSpyStrategy(function(and) {
|
||||||
|
and.stub();
|
||||||
|
});
|
||||||
var c = env.createSpy('c');
|
var c = env.createSpy('c');
|
||||||
env.setDefaultSpyStrategy();
|
env.setDefaultSpyStrategy();
|
||||||
var d = env.createSpy('d');
|
var d = env.createSpy('d');
|
||||||
@@ -61,12 +67,14 @@ describe('Default Spy Strategy (Integration)', function() {
|
|||||||
expect(d.and.isConfigured()).toBe(false);
|
expect(d.and.isConfigured()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
function jasmineDone(result) {
|
function expectations() {
|
||||||
|
var result = jasmineDone.calls.argsFor(0)[0];
|
||||||
expect(result.overallStatus).toEqual('passed');
|
expect(result.overallStatus).toEqual('passed');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||||
env.addReporter({ jasmineDone: jasmineDone });
|
env.addReporter({ jasmineDone: jasmineDone });
|
||||||
env.execute();
|
env.execute(null, expectations);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -23,13 +23,15 @@ describe('Matchers (Integration)', function() {
|
|||||||
expect(result.failedExpectations.length)
|
expect(result.failedExpectations.length)
|
||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(0);
|
.toEqual(0);
|
||||||
expect(result.failedExpectations[0] && result.failedExpectations[0].message)
|
expect(
|
||||||
|
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||||
|
)
|
||||||
.withContext('Failure message')
|
.withContext('Failure message')
|
||||||
.toBeUndefined();
|
.toBeUndefined();
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,38 +47,44 @@ describe('Matchers (Integration)', function() {
|
|||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(1);
|
.toEqual(1);
|
||||||
expect(result.failedExpectations[0].message)
|
expect(result.failedExpectations[0].message)
|
||||||
.withContext('Failed with a thrown error rather than a matcher failure')
|
.withContext(
|
||||||
|
'Failed with a thrown error rather than a matcher failure'
|
||||||
|
)
|
||||||
.not.toMatch(/^Error: /);
|
.not.toMatch(/^Error: /);
|
||||||
expect(result.failedExpectations[0].message)
|
expect(result.failedExpectations[0].message)
|
||||||
.withContext('Failed with a thrown type error rather than a matcher failure')
|
.withContext(
|
||||||
|
'Failed with a thrown type error rather than a matcher failure'
|
||||||
|
)
|
||||||
.not.toMatch(/^TypeError: /);
|
.not.toMatch(/^TypeError: /);
|
||||||
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
.not.toEqual('');
|
.not.toEqual('');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFailsWithCustomObjectFormatters(config) {
|
function verifyFailsWithCustomObjectFormatters(config) {
|
||||||
it('uses custom object formatters', function(done) {
|
it('uses custom object formatters', function(done) {
|
||||||
env.it('a spec', function () {
|
env.it('a spec', function() {
|
||||||
env.addCustomObjectFormatter(config.formatter);
|
env.addCustomObjectFormatter(config.formatter);
|
||||||
config.expectations(env);
|
config.expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function (result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('failed');
|
expect(result.status).toEqual('failed');
|
||||||
expect(result.failedExpectations.length)
|
expect(result.failedExpectations.length)
|
||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(1);
|
.toEqual(1);
|
||||||
expect(result.failedExpectations[0].message)
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
.toEqual(config.expectedMessage);
|
config.expectedMessage
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,13 +104,15 @@ describe('Matchers (Integration)', function() {
|
|||||||
expect(result.failedExpectations.length)
|
expect(result.failedExpectations.length)
|
||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(0);
|
.toEqual(0);
|
||||||
expect(result.failedExpectations[0] && result.failedExpectations[0].message)
|
expect(
|
||||||
|
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||||
|
)
|
||||||
.withContext('Failure message')
|
.withContext('Failure message')
|
||||||
.toBeUndefined();
|
.toBeUndefined();
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,14 +130,17 @@ describe('Matchers (Integration)', function() {
|
|||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(1);
|
.toEqual(1);
|
||||||
expect(result.failedExpectations[0].message)
|
expect(result.failedExpectations[0].message)
|
||||||
.withContext('Failed with a thrown error rather than a matcher failure')
|
.withContext(
|
||||||
|
'Failed with a thrown error rather than a matcher failure'
|
||||||
|
)
|
||||||
.not.toMatch(/^Error: /);
|
.not.toMatch(/^Error: /);
|
||||||
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
expect(result.failedExpectations[0].matcherName)
|
||||||
|
.withContext('Matcher name')
|
||||||
.not.toEqual('');
|
.not.toEqual('');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,26 +148,26 @@ describe('Matchers (Integration)', function() {
|
|||||||
it('uses custom object formatters', function(done) {
|
it('uses custom object formatters', function(done) {
|
||||||
var env = new jasmineUnderTest.Env();
|
var env = new jasmineUnderTest.Env();
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
env.it('a spec', function () {
|
env.it('a spec', function() {
|
||||||
env.addCustomObjectFormatter(config.formatter);
|
env.addCustomObjectFormatter(config.formatter);
|
||||||
return config.expectations(env);
|
return config.expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function (result) {
|
var specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('failed');
|
expect(result.status).toEqual('failed');
|
||||||
expect(result.failedExpectations.length)
|
expect(result.failedExpectations.length)
|
||||||
.withContext('Number of failed expectations')
|
.withContext('Number of failed expectations')
|
||||||
.toEqual(1);
|
.toEqual(1);
|
||||||
expect(result.failedExpectations[0].message)
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
.toEqual(config.expectedMessage);
|
config.expectedMessage
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute();
|
env.execute(null, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
describe('nothing', function() {
|
describe('nothing', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect().nothing();
|
env.expect().nothing();
|
||||||
@@ -330,16 +343,18 @@ describe('Matchers (Integration)', function() {
|
|||||||
env.expect(1).toBePositiveInfinity();
|
env.expect(1).toBePositiveInfinity();
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected |1| to be Infinity.'
|
expectedMessage: 'Expected |1| to be Infinity.'
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeResolved', function() {
|
describe('toBeResolved', function() {
|
||||||
verifyPassesAsync(function(env) {
|
verifyPassesAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeResolved(); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.resolve()).toBeResolved();
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.reject()).toBeResolved(); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.reject()).toBeResolved();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -348,11 +363,13 @@ describe('Matchers (Integration)', function() {
|
|||||||
env.addCustomEqualityTester(function(a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
return env.expectAsync(Promise.resolve('5')).toBeResolvedTo(5); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.resolve('5')).toBeResolvedTo(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('bar'); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsWithCustomObjectFormattersAsync({
|
verifyFailsWithCustomObjectFormattersAsync({
|
||||||
@@ -360,20 +377,24 @@ describe('Matchers (Integration)', function() {
|
|||||||
return '|' + val + '|';
|
return '|' + val + '|';
|
||||||
},
|
},
|
||||||
expectations: function(env) {
|
expectations: function(env) {
|
||||||
return env.expectAsync(Promise.resolve('x')).toBeResolvedTo('y'); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.resolve('x')).toBeResolvedTo('y');
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected a promise to be resolved to |y| ' +
|
expectedMessage:
|
||||||
|
'Expected a promise to be resolved to |y| ' +
|
||||||
'but it was resolved to |x|.'
|
'but it was resolved to |x|.'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeRejected', function() {
|
describe('toBeRejected', function() {
|
||||||
verifyPassesAsync(function(env) {
|
verifyPassesAsync(function(env) {
|
||||||
return env.expectAsync(Promise.reject('nope')).toBeRejected(); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.reject('nope')).toBeRejected();
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeRejected(); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.resolve()).toBeRejected();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -382,11 +403,13 @@ describe('Matchers (Integration)', function() {
|
|||||||
env.addCustomEqualityTester(function(a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
return env.expectAsync(Promise.reject('5')).toBeRejectedWith(5); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.reject('5')).toBeRejectedWith(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeRejectedWith('nope'); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.resolve()).toBeRejectedWith('nope');
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsWithCustomObjectFormattersAsync({
|
verifyFailsWithCustomObjectFormattersAsync({
|
||||||
@@ -394,20 +417,28 @@ describe('Matchers (Integration)', function() {
|
|||||||
return '|' + val + '|';
|
return '|' + val + '|';
|
||||||
},
|
},
|
||||||
expectations: function(env) {
|
expectations: function(env) {
|
||||||
return env.expectAsync(Promise.reject('x')).toBeRejectedWith('y'); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.reject('x')).toBeRejectedWith('y');
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected a promise to be rejected with |y| ' +
|
expectedMessage:
|
||||||
|
'Expected a promise to be rejected with |y| ' +
|
||||||
'but it was rejected with |x|.'
|
'but it was rejected with |x|.'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeRejectedWithError', function() {
|
describe('toBeRejectedWithError', function() {
|
||||||
verifyPassesAsync(function(env) {
|
verifyPassesAsync(function(env) {
|
||||||
return env.expectAsync(Promise.reject(new Error())).toBeRejectedWithError(Error); // eslint-disable-line compat/compat
|
return (
|
||||||
|
env
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
.expectAsync(Promise.reject(new Error()))
|
||||||
|
.toBeRejectedWithError(Error)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error); // eslint-disable-line compat/compat
|
// eslint-disable-next-line compat/compat
|
||||||
|
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsWithCustomObjectFormattersAsync({
|
verifyFailsWithCustomObjectFormattersAsync({
|
||||||
@@ -415,9 +446,15 @@ describe('Matchers (Integration)', function() {
|
|||||||
return '|' + val + '|';
|
return '|' + val + '|';
|
||||||
},
|
},
|
||||||
expectations: function(env) {
|
expectations: function(env) {
|
||||||
return env.expectAsync(Promise.reject('foo')).toBeRejectedWithError('foo'); // eslint-disable-line compat/compat
|
return (
|
||||||
|
env
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
.expectAsync(Promise.reject('foo'))
|
||||||
|
.toBeRejectedWithError('foo')
|
||||||
|
);
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected a promise to be rejected with Error: |foo| ' +
|
expectedMessage:
|
||||||
|
'Expected a promise to be rejected with Error: |foo| ' +
|
||||||
'but it was rejected with |foo|.'
|
'but it was rejected with |foo|.'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -486,7 +523,7 @@ describe('Matchers (Integration)', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
expectations: function(env) {
|
expectations: function(env) {
|
||||||
env.expect([{foo: 4}]).toEqual([{foo: 5}]);
|
env.expect([{ foo: 4 }]).toEqual([{ foo: 5 }]);
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected $[0].foo = four to equal five.'
|
expectedMessage: 'Expected $[0].foo = four to equal five.'
|
||||||
});
|
});
|
||||||
@@ -494,11 +531,11 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
describe('toHaveSize', function() {
|
describe('toHaveSize', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(['a','b']).toHaveSize(2);
|
env.expect(['a', 'b']).toHaveSize(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(['a','b']).toHaveSize(1);
|
env.expect(['a', 'b']).toHaveSize(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -517,14 +554,16 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
describe('toHaveBeenCalledBefore', function() {
|
describe('toHaveBeenCalledBefore', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
var a = env.createSpy('a'), b = env.createSpy('b');
|
var a = env.createSpy('a'),
|
||||||
|
b = env.createSpy('b');
|
||||||
a();
|
a();
|
||||||
b();
|
b();
|
||||||
env.expect(a).toHaveBeenCalledBefore(b);
|
env.expect(a).toHaveBeenCalledBefore(b);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
var a = env.createSpy('a'), b = env.createSpy('b');
|
var a = env.createSpy('a'),
|
||||||
|
b = env.createSpy('b');
|
||||||
b();
|
b();
|
||||||
a();
|
a();
|
||||||
env.expect(a).toHaveBeenCalledBefore(b);
|
env.expect(a).toHaveBeenCalledBefore(b);
|
||||||
@@ -567,7 +606,8 @@ describe('Matchers (Integration)', function() {
|
|||||||
var spy = env.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
env.expect(spy).toHaveBeenCalledWith('x');
|
env.expect(spy).toHaveBeenCalledWith('x');
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected spy foo to have been called with:\n' +
|
expectedMessage:
|
||||||
|
'Expected spy foo to have been called with:\n' +
|
||||||
' |x|\n' +
|
' |x|\n' +
|
||||||
'but it was never called.'
|
'but it was never called.'
|
||||||
});
|
});
|
||||||
@@ -622,7 +662,11 @@ describe('Matchers (Integration)', function() {
|
|||||||
env.addCustomEqualityTester(function(a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
});
|
});
|
||||||
env.expect(function() { throw '5'; }).toThrow(5);
|
env
|
||||||
|
.expect(function() {
|
||||||
|
throw '5';
|
||||||
|
})
|
||||||
|
.toThrow(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
@@ -635,9 +679,11 @@ describe('Matchers (Integration)', function() {
|
|||||||
},
|
},
|
||||||
expectations: function(env) {
|
expectations: function(env) {
|
||||||
var spy = env.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
env.expect(function() {
|
env
|
||||||
throw 'x'
|
.expect(function() {
|
||||||
}).not.toThrow();
|
throw 'x';
|
||||||
|
})
|
||||||
|
.not.toThrow();
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected function not to throw, but it threw |x|.'
|
expectedMessage: 'Expected function not to throw, but it threw |x|.'
|
||||||
});
|
});
|
||||||
@@ -645,11 +691,15 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
describe('toThrowError', function() {
|
describe('toThrowError', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(function() { throw new Error(); }).toThrowError();
|
env
|
||||||
|
.expect(function() {
|
||||||
|
throw new Error();
|
||||||
|
})
|
||||||
|
.toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(function() { }).toThrowError();
|
env.expect(function() {}).toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsWithCustomObjectFormatters({
|
verifyFailsWithCustomObjectFormatters({
|
||||||
@@ -658,9 +708,11 @@ describe('Matchers (Integration)', function() {
|
|||||||
},
|
},
|
||||||
expectations: function(env) {
|
expectations: function(env) {
|
||||||
var spy = env.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
env.expect(function() {
|
env
|
||||||
throw 'x'
|
.expect(function() {
|
||||||
}).toThrowError();
|
throw 'x';
|
||||||
|
})
|
||||||
|
.toThrowError();
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected function to throw an Error, but it threw |x|.'
|
expectedMessage: 'Expected function to throw an Error, but it threw |x|.'
|
||||||
});
|
});
|
||||||
@@ -672,11 +724,15 @@ describe('Matchers (Integration)', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(throws).toThrowMatching(function() { return true; });
|
env.expect(throws).toThrowMatching(function() {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(throws).toThrowMatching(function() { return false; });
|
env.expect(throws).toThrowMatching(function() {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsWithCustomObjectFormatters({
|
verifyFailsWithCustomObjectFormatters({
|
||||||
@@ -685,13 +741,16 @@ describe('Matchers (Integration)', function() {
|
|||||||
},
|
},
|
||||||
expectations: function(env) {
|
expectations: function(env) {
|
||||||
var spy = env.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
env.expect(function() {
|
env
|
||||||
throw new Error('nope')
|
.expect(function() {
|
||||||
}).toThrowMatching(function() {
|
throw new Error('nope');
|
||||||
return false;
|
})
|
||||||
});
|
.toThrowMatching(function() {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
expectedMessage: 'Expected function to throw an exception matching ' +
|
expectedMessage:
|
||||||
|
'Expected function to throw an exception matching ' +
|
||||||
'a predicate, but it threw Error with message |nope|.'
|
'a predicate, but it threw Error with message |nope|.'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,132 +1,159 @@
|
|||||||
describe("DiffBuilder", function () {
|
describe('DiffBuilder', function() {
|
||||||
it("records the actual and expected objects", function () {
|
it('records the actual and expected objects', function() {
|
||||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({x: 'actual'}, {x: 'expected'});
|
diffBuilder.setRoots({ x: 'actual' }, { x: 'expected' });
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
|
|
||||||
expect(diffBuilder.getMessage()).toEqual("Expected Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
|
expect(diffBuilder.getMessage()).toEqual(
|
||||||
|
"Expected Object({ x: 'actual' }) to equal Object({ x: 'expected' })."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints the path at which the difference was found", function () {
|
it('prints the path at which the difference was found', function() {
|
||||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({foo: {x: 'actual'}}, {foo: {x: 'expected'}});
|
diffBuilder.setRoots({ foo: { x: 'actual' } }, { foo: { x: 'expected' } });
|
||||||
|
|
||||||
diffBuilder.withPath('foo', function () {
|
diffBuilder.withPath('foo', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(diffBuilder.getMessage()).toEqual("Expected $.foo = Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
|
expect(diffBuilder.getMessage()).toEqual(
|
||||||
|
"Expected $.foo = Object({ x: 'actual' }) to equal Object({ x: 'expected' })."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints multiple messages, separated by newlines", function () {
|
it('prints multiple messages, separated by newlines', function() {
|
||||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({foo: 1, bar: 3}, {foo: 2, bar: 4});
|
diffBuilder.setRoots({ foo: 1, bar: 3 }, { foo: 2, bar: 4 });
|
||||||
|
|
||||||
diffBuilder.withPath('foo', function () {
|
diffBuilder.withPath('foo', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
diffBuilder.withPath('bar', function () {
|
diffBuilder.withPath('bar', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
|
|
||||||
var message =
|
var message =
|
||||||
"Expected $.foo = 1 to equal 2.\n" +
|
'Expected $.foo = 1 to equal 2.\n' + 'Expected $.bar = 3 to equal 4.';
|
||||||
"Expected $.bar = 3 to equal 4.";
|
|
||||||
|
|
||||||
expect(diffBuilder.getMessage()).toEqual(message);
|
expect(diffBuilder.getMessage()).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows customization of the message", function () {
|
it('allows customization of the message', function() {
|
||||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||||
diffBuilder.setRoots({x: 'bar'}, {x: 'foo'});
|
diffBuilder.setRoots({ x: 'bar' }, { x: 'foo' });
|
||||||
|
|
||||||
function darthVaderFormatter(actual, expected, path) {
|
function darthVaderFormatter(actual, expected, path) {
|
||||||
return "I find your lack of " + expected + " disturbing. (was " + actual + ", at " + path + ")"
|
return (
|
||||||
|
'I find your lack of ' +
|
||||||
|
expected +
|
||||||
|
' disturbing. (was ' +
|
||||||
|
actual +
|
||||||
|
', at ' +
|
||||||
|
path +
|
||||||
|
')'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
diffBuilder.withPath('x', function () {
|
diffBuilder.withPath('x', function() {
|
||||||
diffBuilder.recordMismatch(darthVaderFormatter);
|
diffBuilder.recordMismatch(darthVaderFormatter);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(diffBuilder.getMessage()).toEqual("I find your lack of foo disturbing. (was bar, at $.x)");
|
expect(diffBuilder.getMessage()).toEqual(
|
||||||
|
'I find your lack of foo disturbing. (was bar, at $.x)'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses the injected pretty-printer", function () {
|
it('uses the injected pretty-printer', function() {
|
||||||
var prettyPrinter = function (val) {
|
var prettyPrinter = function(val) {
|
||||||
return '|' + val + '|';
|
return '|' + val + '|';
|
||||||
},
|
},
|
||||||
diffBuilder = jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
diffBuilder = jasmineUnderTest.DiffBuilder({
|
||||||
prettyPrinter.customFormat_ = function () {
|
prettyPrinter: prettyPrinter
|
||||||
};
|
});
|
||||||
|
prettyPrinter.customFormat_ = function() {};
|
||||||
|
|
||||||
diffBuilder.setRoots({foo: 'actual'}, {foo: 'expected'});
|
diffBuilder.setRoots({ foo: 'actual' }, { foo: 'expected' });
|
||||||
diffBuilder.withPath('foo', function () {
|
diffBuilder.withPath('foo', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(diffBuilder.getMessage()).toEqual("Expected $.foo = |actual| to equal |expected|.");
|
expect(diffBuilder.getMessage()).toEqual(
|
||||||
|
'Expected $.foo = |actual| to equal |expected|.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes the injected pretty-printer to the diff formatter", function () {
|
it('passes the injected pretty-printer to the diff formatter', function() {
|
||||||
var diffFormatter = jasmine.createSpy('diffFormatter'),
|
var diffFormatter = jasmine.createSpy('diffFormatter'),
|
||||||
prettyPrinter = function () {
|
prettyPrinter = function() {},
|
||||||
},
|
diffBuilder = jasmineUnderTest.DiffBuilder({
|
||||||
diffBuilder = jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
prettyPrinter: prettyPrinter
|
||||||
prettyPrinter.customFormat_ = function () {
|
});
|
||||||
};
|
prettyPrinter.customFormat_ = function() {};
|
||||||
|
|
||||||
diffBuilder.setRoots({x: 'bar'}, {x: 'foo'});
|
diffBuilder.setRoots({ x: 'bar' }, { x: 'foo' });
|
||||||
diffBuilder.withPath('x', function () {
|
diffBuilder.withPath('x', function() {
|
||||||
diffBuilder.recordMismatch(diffFormatter);
|
diffBuilder.recordMismatch(diffFormatter);
|
||||||
});
|
});
|
||||||
|
|
||||||
diffBuilder.getMessage();
|
diffBuilder.getMessage();
|
||||||
|
|
||||||
expect(diffFormatter).toHaveBeenCalledWith('bar', 'foo', jasmine.anything(), prettyPrinter);
|
expect(diffFormatter).toHaveBeenCalledWith(
|
||||||
|
'bar',
|
||||||
|
'foo',
|
||||||
|
jasmine.anything(),
|
||||||
|
prettyPrinter
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom object formatters on leaf nodes", function() {
|
it('uses custom object formatters on leaf nodes', function() {
|
||||||
var formatter = function(x) {
|
var formatter = function(x) {
|
||||||
if (typeof x === 'number') {
|
if (typeof x === 'number') {
|
||||||
return '[number:' + x + ']';
|
return '[number:' + x + ']';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
||||||
var diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
var diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||||
|
prettyPrinter: prettyPrinter
|
||||||
|
});
|
||||||
|
|
||||||
diffBuilder.setRoots(5, 4);
|
diffBuilder.setRoots(5, 4);
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
|
|
||||||
expect(diffBuilder.getMessage()).toEqual('Expected [number:5] to equal [number:4].');
|
expect(diffBuilder.getMessage()).toEqual(
|
||||||
|
'Expected [number:5] to equal [number:4].'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses custom object formatters on non leaf nodes', function() {
|
||||||
it("uses custom object formatters on non leaf nodes", function () {
|
var formatter = function(x) {
|
||||||
var formatter = function (x) {
|
|
||||||
if (x.hasOwnProperty('a')) {
|
if (x.hasOwnProperty('a')) {
|
||||||
return '[thing with a=' + x.a + ', b=' + JSON.stringify(x.b) + ']';
|
return '[thing with a=' + x.a + ', b=' + JSON.stringify(x.b) + ']';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
||||||
var diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
var diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||||
var expectedMsg = 'Expected $[0].foo = [thing with a=1, b={"x":42}] to equal [thing with a=1, b={"x":43}].\n' +
|
prettyPrinter: prettyPrinter
|
||||||
|
});
|
||||||
|
var expectedMsg =
|
||||||
|
'Expected $[0].foo = [thing with a=1, b={"x":42}] to equal [thing with a=1, b={"x":43}].\n' +
|
||||||
"Expected $[0].bar = 'yes' to equal 'no'.";
|
"Expected $[0].bar = 'yes' to equal 'no'.";
|
||||||
|
|
||||||
diffBuilder.setRoots(
|
diffBuilder.setRoots(
|
||||||
[{foo: {a: 1, b: {x: 42}}, bar: 'yes'}],
|
[{ foo: { a: 1, b: { x: 42 } }, bar: 'yes' }],
|
||||||
[{foo: {a: 1, b: {x: 43}}, bar: 'no'}]
|
[{ foo: { a: 1, b: { x: 43 } }, bar: 'no' }]
|
||||||
);
|
);
|
||||||
|
|
||||||
diffBuilder.withPath(0, function () {
|
diffBuilder.withPath(0, function() {
|
||||||
diffBuilder.withPath('foo', function () {
|
diffBuilder.withPath('foo', function() {
|
||||||
diffBuilder.withPath('b', function () {
|
diffBuilder.withPath('b', function() {
|
||||||
diffBuilder.withPath('x', function () {
|
diffBuilder.withPath('x', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
diffBuilder.withPath('bar', function () {
|
diffBuilder.withPath('bar', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -136,14 +163,16 @@ describe("DiffBuilder", function () {
|
|||||||
|
|
||||||
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ at the root', function() {
|
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ at the root', function() {
|
||||||
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
||||||
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
|
diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||||
expectedMsg = 'Expected $.foo = 1 to equal 2.\n' +
|
prettyPrinter: prettyPrinter
|
||||||
"Expected $.baz = undefined to equal 3.";
|
}),
|
||||||
|
expectedMsg =
|
||||||
|
'Expected $.foo = 1 to equal 2.\n' +
|
||||||
|
'Expected $.baz = undefined to equal 3.';
|
||||||
|
|
||||||
diffBuilder.setRoots(
|
diffBuilder.setRoots(
|
||||||
{foo: 1, bar: 2},
|
{ foo: 1, bar: 2 },
|
||||||
jasmine.objectContaining({foo: 2, baz: 3})
|
jasmine.objectContaining({ foo: 2, baz: 3 })
|
||||||
);
|
);
|
||||||
|
|
||||||
diffBuilder.withPath('foo', function() {
|
diffBuilder.withPath('foo', function() {
|
||||||
@@ -158,21 +187,23 @@ describe("DiffBuilder", function () {
|
|||||||
|
|
||||||
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ below the root', function() {
|
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ below the root', function() {
|
||||||
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
||||||
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
|
diffBuilder = new jasmineUnderTest.DiffBuilder({
|
||||||
expectedMsg = 'Expected $.x.foo = 1 to equal 2.\n' +
|
prettyPrinter: prettyPrinter
|
||||||
"Expected $.x.baz = undefined to equal 3.";
|
}),
|
||||||
|
expectedMsg =
|
||||||
|
'Expected $.x.foo = 1 to equal 2.\n' +
|
||||||
|
'Expected $.x.baz = undefined to equal 3.';
|
||||||
|
|
||||||
diffBuilder.setRoots(
|
diffBuilder.setRoots(
|
||||||
{x: {foo: 1, bar: 2}},
|
{ x: { foo: 1, bar: 2 } },
|
||||||
{x: jasmine.objectContaining({foo: 2, baz: 3})}
|
{ x: jasmine.objectContaining({ foo: 2, baz: 3 }) }
|
||||||
);
|
);
|
||||||
|
|
||||||
diffBuilder.withPath('x', function() {
|
diffBuilder.withPath('x', function() {
|
||||||
diffBuilder.withPath('foo', function () {
|
diffBuilder.withPath('foo', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
diffBuilder.withPath('baz', function () {
|
diffBuilder.withPath('baz', function() {
|
||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
describe('MismatchTree', function () {
|
describe('MismatchTree', function() {
|
||||||
describe('#add', function () {
|
describe('#add', function() {
|
||||||
describe('When the path is empty', function () {
|
describe('When the path is empty', function() {
|
||||||
it('flags the root node as mismatched', function () {
|
it('flags the root node as mismatched', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
tree.add(new jasmineUnderTest.ObjectPath([]));
|
tree.add(new jasmineUnderTest.ObjectPath([]));
|
||||||
expect(tree.isMismatch).toBe(true);
|
expect(tree.isMismatch).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When the path is not empty', function () {
|
describe('When the path is not empty', function() {
|
||||||
it('flags the node as mismatched', function () {
|
it('flags the node as mismatched', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
@@ -17,7 +17,7 @@ describe('MismatchTree', function () {
|
|||||||
expect(tree.child('a').child('b').isMismatch).toBe(true);
|
expect(tree.child('a').child('b').isMismatch).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not flag ancestors as mismatched', function () {
|
it('does not flag ancestors as mismatched', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
@@ -27,7 +27,7 @@ describe('MismatchTree', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stores the formatter on only the target node', function () {
|
it('stores the formatter on only the target node', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||||
@@ -37,7 +37,7 @@ describe('MismatchTree', function () {
|
|||||||
expect(tree.child('a').child('b').formatter).toBe(formatter);
|
expect(tree.child('a').child('b').formatter).toBe(formatter);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stores the path to the node', function () {
|
it('stores the path to the node', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||||
@@ -46,8 +46,8 @@ describe('MismatchTree', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#traverse', function () {
|
describe('#traverse', function() {
|
||||||
it('calls the callback for all nodes that are or contain mismatches', function () {
|
it('calls the callback for all nodes that are or contain mismatches', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||||
tree.add(new jasmineUnderTest.ObjectPath(['c']));
|
tree.add(new jasmineUnderTest.ObjectPath(['c']));
|
||||||
@@ -56,20 +56,28 @@ describe('MismatchTree', function () {
|
|||||||
tree.traverse(visit);
|
tree.traverse(visit);
|
||||||
|
|
||||||
expect(visit).toHaveBeenCalledWith(
|
expect(visit).toHaveBeenCalledWith(
|
||||||
new jasmineUnderTest.ObjectPath([]), false, undefined
|
new jasmineUnderTest.ObjectPath([]),
|
||||||
|
false,
|
||||||
|
undefined
|
||||||
);
|
);
|
||||||
expect(visit).toHaveBeenCalledWith(
|
expect(visit).toHaveBeenCalledWith(
|
||||||
new jasmineUnderTest.ObjectPath(['a']), false, undefined
|
new jasmineUnderTest.ObjectPath(['a']),
|
||||||
|
false,
|
||||||
|
undefined
|
||||||
);
|
);
|
||||||
expect(visit).toHaveBeenCalledWith(
|
expect(visit).toHaveBeenCalledWith(
|
||||||
new jasmineUnderTest.ObjectPath(['a', 'b']), true, formatter
|
new jasmineUnderTest.ObjectPath(['a', 'b']),
|
||||||
|
true,
|
||||||
|
formatter
|
||||||
);
|
);
|
||||||
expect(visit).toHaveBeenCalledWith(
|
expect(visit).toHaveBeenCalledWith(
|
||||||
new jasmineUnderTest.ObjectPath(['c']), true, undefined
|
new jasmineUnderTest.ObjectPath(['c']),
|
||||||
|
true,
|
||||||
|
undefined
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not call the callback if there are no mismatches', function () {
|
it('does not call the callback if there are no mismatches', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
var visit = jasmine.createSpy('visit');
|
var visit = jasmine.createSpy('visit');
|
||||||
|
|
||||||
@@ -78,12 +86,12 @@ describe('MismatchTree', function () {
|
|||||||
expect(visit).not.toHaveBeenCalled();
|
expect(visit).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('visits parents before children', function () {
|
it('visits parents before children', function() {
|
||||||
var tree = new jasmineUnderTest.MismatchTree();
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
var visited = [];
|
var visited = [];
|
||||||
|
|
||||||
tree.traverse(function (path) {
|
tree.traverse(function(path) {
|
||||||
visited.push(path);
|
visited.push(path);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -101,7 +109,7 @@ describe('MismatchTree', function () {
|
|||||||
tree.add(new jasmineUnderTest.ObjectPath([1]));
|
tree.add(new jasmineUnderTest.ObjectPath([1]));
|
||||||
var visited = [];
|
var visited = [];
|
||||||
|
|
||||||
tree.traverse(function (path) {
|
tree.traverse(function(path) {
|
||||||
visited.push(path);
|
visited.push(path);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -118,7 +126,7 @@ describe('MismatchTree', function () {
|
|||||||
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
var visited = [];
|
var visited = [];
|
||||||
|
|
||||||
tree.traverse(function (path) {
|
tree.traverse(function(path) {
|
||||||
visited.push(path);
|
visited.push(path);
|
||||||
return path.depth() === 0;
|
return path.depth() === 0;
|
||||||
});
|
});
|
||||||
@@ -130,7 +138,5 @@ describe('MismatchTree', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatter() {
|
function formatter() {}
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
describe('NullDiffBuilder', function () {
|
describe('NullDiffBuilder', function() {
|
||||||
it('responds to withPath() by calling the passed function', function () {
|
it('responds to withPath() by calling the passed function', function() {
|
||||||
var spy = jasmine.createSpy('callback');
|
var spy = jasmine.createSpy('callback');
|
||||||
jasmineUnderTest.NullDiffBuilder().withPath('does not matter', spy);
|
jasmineUnderTest.NullDiffBuilder().withPath('does not matter', spy);
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ describe('toBePending', function() {
|
|||||||
actual = new Promise(function() {});
|
actual = new Promise(function() {});
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ describe('toBePending', function() {
|
|||||||
actual = Promise.resolve();
|
actual = Promise.resolve();
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,21 +32,19 @@ describe('toBePending', function() {
|
|||||||
actual = Promise.reject(new Error('promise was rejected'));
|
actual = Promise.reject(new Error('promise was rejected'));
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
return matcher.compare(actual);
|
return matcher.compare(actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(f).toThrowError(
|
expect(f).toThrowError('Expected toBePending to be called on a promise.');
|
||||||
'Expected toBePending to be called on a promise.'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ describe('toBeRejected', function() {
|
|||||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ describe('toBeRejected', function() {
|
|||||||
actual = Promise.resolve();
|
actual = Promise.resolve();
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -33,8 +33,6 @@ describe('toBeRejected', function() {
|
|||||||
return matcher.compare(actual);
|
return matcher.compare(actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(f).toThrowError(
|
expect(f).toThrowError('Expected toBeRejected to be called on a promise.');
|
||||||
'Expected toBeRejected to be called on a promise.'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,174 +1,253 @@
|
|||||||
/* eslint-disable compat/compat */
|
/* eslint-disable compat/compat */
|
||||||
describe('#toBeRejectedWithError', function () {
|
describe('#toBeRejectedWithError', function() {
|
||||||
it('passes when Error type matches', function () {
|
it('passes when Error type matches', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new TypeError('foo'));
|
actual = Promise.reject(new TypeError('foo'));
|
||||||
|
|
||||||
return matcher.compare(actual, TypeError).then(function (result) {
|
return matcher.compare(actual, TypeError).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with TypeError, but it was.'
|
pass: true,
|
||||||
}));
|
message:
|
||||||
|
'Expected a promise not to be rejected with TypeError, but it was.'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes when Error type and message matches', function () {
|
it('passes when Error type and message matches', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new TypeError('foo'));
|
actual = Promise.reject(new TypeError('foo'));
|
||||||
|
|
||||||
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
|
return matcher.compare(actual, TypeError, 'foo').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with TypeError: \'foo\', but it was.'
|
pass: true,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise not to be rejected with TypeError: 'foo', but it was."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes when Error matches and is exactly Error', function() {
|
it('passes when Error matches and is exactly Error', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new Error());
|
actual = Promise.reject(new Error());
|
||||||
|
|
||||||
return matcher.compare(actual, Error).then(function (result) {
|
return matcher.compare(actual, Error).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with Error, but it was.'
|
pass: true,
|
||||||
}));
|
message:
|
||||||
|
'Expected a promise not to be rejected with Error, but it was.'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes when Error message matches a string', function () {
|
it('passes when Error message matches a string', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new Error('foo'));
|
actual = Promise.reject(new Error('foo'));
|
||||||
|
|
||||||
return matcher.compare(actual, 'foo').then(function (result) {
|
return matcher.compare(actual, 'foo').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with Error: \'foo\', but it was.'
|
pass: true,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise not to be rejected with Error: 'foo', but it was."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes when Error message matches a RegExp', function () {
|
it('passes when Error message matches a RegExp', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new Error('foo'));
|
actual = Promise.reject(new Error('foo'));
|
||||||
|
|
||||||
return matcher.compare(actual, /foo/).then(function (result) {
|
return matcher.compare(actual, /foo/).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with Error: /foo/, but it was.'
|
pass: true,
|
||||||
}));
|
message:
|
||||||
|
'Expected a promise not to be rejected with Error: /foo/, but it was.'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes when Error message is empty', function () {
|
it('passes when Error message is empty', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new Error());
|
actual = Promise.reject(new Error());
|
||||||
|
|
||||||
return matcher.compare(actual, '').then(function (result) {
|
return matcher.compare(actual, '').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with Error: \'\', but it was.'
|
pass: true,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise not to be rejected with Error: '', but it was."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes when no arguments', function () {
|
it('passes when no arguments', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new Error());
|
actual = Promise.reject(new Error());
|
||||||
|
|
||||||
return matcher.compare(actual, void 0).then(function (result) {
|
return matcher.compare(actual, void 0).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with Error, but it was.'
|
pass: true,
|
||||||
}));
|
message:
|
||||||
|
'Expected a promise not to be rejected with Error, but it was.'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails when resolved', function () {
|
it('fails when resolved', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.resolve(new Error('foo'));
|
actual = Promise.resolve(new Error('foo'));
|
||||||
|
|
||||||
return matcher.compare(actual, 'foo').then(function (result) {
|
return matcher.compare(actual, 'foo').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: false,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise to be rejected but it was resolved.'
|
pass: false,
|
||||||
}));
|
message: 'Expected a promise to be rejected but it was resolved.'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails when rejected with non Error type', function () {
|
it('fails when rejected with non Error type', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject('foo');
|
actual = Promise.reject('foo');
|
||||||
|
|
||||||
return matcher.compare(actual, 'foo').then(function (result) {
|
return matcher.compare(actual, 'foo').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: false,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise to be rejected with Error: \'foo\' but it was rejected with \'foo\'.'
|
pass: false,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise to be rejected with Error: 'foo' but it was rejected with 'foo'."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails when Error type mismatches', function () {
|
it('fails when Error type mismatches', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new Error('foo'));
|
actual = Promise.reject(new Error('foo'));
|
||||||
|
|
||||||
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
|
return matcher.compare(actual, TypeError, 'foo').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: false,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise to be rejected with TypeError: \'foo\' but it was rejected with type Error.'
|
pass: false,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise to be rejected with TypeError: 'foo' but it was rejected with type Error."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails when Error message mismatches', function () {
|
it('fails when Error message mismatches', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = Promise.reject(new Error('foo'));
|
actual = Promise.reject(new Error('foo'));
|
||||||
|
|
||||||
return matcher.compare(actual, 'bar').then(function (result) {
|
return matcher.compare(actual, 'bar').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: false,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise to be rejected with Error: \'bar\' but it was rejected with Error: foo.'
|
pass: false,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise to be rejected with Error: 'bar' but it was rejected with Error: foo."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
@@ -1,74 +1,91 @@
|
|||||||
/* eslint-disable compat/compat */
|
/* eslint-disable compat/compat */
|
||||||
describe('#toBeRejectedWith', function () {
|
describe('#toBeRejectedWith', function() {
|
||||||
it('should return true if the promise is rejected with the expected value', function () {
|
it('should return true if the promise is rejected with the expected value', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||||
actual = Promise.reject({error: 'PEBCAK'});
|
actual = Promise.reject({ error: 'PEBCAK' });
|
||||||
|
|
||||||
return matcher.compare(actual, {error: 'PEBCAK'}).then(function (result) {
|
return matcher.compare(actual, { error: 'PEBCAK' }).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if the promise resolves', function () {
|
it('should fail if the promise resolves', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||||
actual = Promise.resolve();
|
actual = Promise.resolve();
|
||||||
|
|
||||||
return matcher.compare(actual, '').then(function (result) {
|
return matcher.compare(actual, '').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if the promise is rejected with a different value', function () {
|
it('should fail if the promise is rejected with a different value', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||||
actual = Promise.reject('A Bad Apple');
|
actual = Promise.reject('A Bad Apple');
|
||||||
|
|
||||||
return matcher.compare(actual, 'Some Cool Thing').then(function (result) {
|
return matcher.compare(actual, 'Some Cool Thing').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: false,
|
jasmine.objectContaining({
|
||||||
message: "Expected a promise to be rejected with 'Some Cool Thing' but it was rejected with 'A Bad Apple'.",
|
pass: false,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise to be rejected with 'Some Cool Thing' but it was rejected with 'A Bad Apple'."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should build its error correctly when negated', function () {
|
it('should build its error correctly when negated', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||||
actual = Promise.reject(true);
|
actual = Promise.reject(true);
|
||||||
|
|
||||||
return matcher.compare(actual, true).then(function (result) {
|
return matcher.compare(actual, true).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be rejected with true.'
|
pass: true,
|
||||||
}));
|
message: 'Expected a promise not to be rejected with true.'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support custom equality testers', function () {
|
it('should support custom equality testers', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var customEqualityTesters = [function() { return true; }],
|
var customEqualityTesters = [
|
||||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
function() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: customEqualityTesters
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||||
actual = Promise.reject('actual');
|
actual = Promise.reject('actual');
|
||||||
|
|
||||||
return matcher.compare(actual, 'expected').then(function(result) {
|
return matcher.compare(actual, 'expected').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ describe('toBeResolved', function() {
|
|||||||
actual = Promise.resolve();
|
actual = Promise.resolve();
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ describe('toBeResolved', function() {
|
|||||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -33,8 +33,6 @@ describe('toBeResolved', function() {
|
|||||||
return matcher.compare(actual);
|
return matcher.compare(actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(f).toThrowError(
|
expect(f).toThrowError('Expected toBeResolved to be called on a promise.');
|
||||||
'Expected toBeResolved to be called on a promise.'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,62 +5,80 @@ describe('#toBeResolvedTo', function() {
|
|||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||||
actual = Promise.resolve({foo: 42});
|
actual = Promise.resolve({ foo: 42 });
|
||||||
|
|
||||||
return matcher.compare(actual, {foo: 42}).then(function(result) {
|
return matcher.compare(actual, { foo: 42 }).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails if the promise is rejected', function() {
|
it('fails if the promise is rejected', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||||
actual = Promise.reject('AsyncExpectationSpec error');
|
actual = Promise.reject('AsyncExpectationSpec error');
|
||||||
|
|
||||||
return matcher.compare(actual, '').then(function(result) {
|
return matcher.compare(actual, '').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: false,
|
jasmine.objectContaining({
|
||||||
message: "Expected a promise to be resolved to '' but it was rejected.",
|
pass: false,
|
||||||
}));
|
message:
|
||||||
|
"Expected a promise to be resolved to '' but it was rejected."
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails if the promise is resolved to a different value', function() {
|
it('fails if the promise is resolved to a different value', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||||
actual = Promise.resolve({foo: 17});
|
actual = Promise.resolve({ foo: 17 });
|
||||||
|
|
||||||
return matcher.compare(actual, {foo: 42}).then(function(result) {
|
return matcher.compare(actual, { foo: 42 }).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: false,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise to be resolved to Object({ foo: 42 }) but it was resolved to Object({ foo: 17 }).',
|
pass: false,
|
||||||
}));
|
message:
|
||||||
|
'Expected a promise to be resolved to Object({ foo: 42 }) but it was resolved to Object({ foo: 17 }).'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('builds its message correctly when negated', function() {
|
it('builds its message correctly when negated', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||||
actual = Promise.resolve(true);
|
actual = Promise.resolve(true);
|
||||||
|
|
||||||
return matcher.compare(actual, true).then(function(result) {
|
return matcher.compare(actual, true).then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({
|
expect(result).toEqual(
|
||||||
pass: true,
|
jasmine.objectContaining({
|
||||||
message: 'Expected a promise not to be resolved to true.'
|
pass: true,
|
||||||
}));
|
message: 'Expected a promise not to be resolved to true.'
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports custom equality testers', function() {
|
it('supports custom equality testers', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var customEqualityTesters = [function() { return true; }],
|
var customEqualityTesters = [
|
||||||
|
function() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
],
|
||||||
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
customTesters: customEqualityTesters,
|
customTesters: customEqualityTesters,
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
@@ -69,12 +87,14 @@ describe('#toBeResolvedTo', function() {
|
|||||||
actual = Promise.resolve('actual');
|
actual = Promise.resolve('actual');
|
||||||
|
|
||||||
return matcher.compare(actual, 'expected').then(function(result) {
|
return matcher.compare(actual, 'expected').then(function(result) {
|
||||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeCloseTo", function() {
|
describe('toBeCloseTo', function() {
|
||||||
it("passes when within two decimal places by default", function() {
|
it('passes when within two decimal places by default', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ describe("toBeCloseTo", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when not within two decimal places by default", function() {
|
it('fails when not within two decimal places by default', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ describe("toBeCloseTo", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("accepts an optional precision argument", function() {
|
it('accepts an optional precision argument', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -47,23 +47,29 @@ describe("toBeCloseTo", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when one of the arguments is null", function() {
|
it('fails when one of the arguments is null', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo();
|
var matcher = jasmineUnderTest.matchers.toBeCloseTo();
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare(null, null);
|
matcher.compare(null, null);
|
||||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(null).');
|
}).toThrowError(
|
||||||
|
'Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(null).'
|
||||||
|
);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare(0, null);
|
matcher.compare(0, null);
|
||||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(0).toBeCloseTo(null).');
|
}).toThrowError(
|
||||||
|
'Cannot use toBeCloseTo with null. Arguments evaluated to: expect(0).toBeCloseTo(null).'
|
||||||
|
);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare(null, 0);
|
matcher.compare(null, 0);
|
||||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(0).');
|
}).toThrowError(
|
||||||
|
'Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(0).'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rounds expected values", function() {
|
it('rounds expected values', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -91,15 +97,15 @@ describe("toBeCloseTo", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles edge cases with rounding", function () {
|
it('handles edge cases with rounding', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
// these cases resulted in false negatives in version of V8
|
// these cases resulted in false negatives in version of V8
|
||||||
// included in Node.js 12 and Chrome 74 (and Edge Chromium)
|
// included in Node.js 12 and Chrome 74 (and Edge Chromium)
|
||||||
result = matcher.compare(4.030904708957288, 4.0309, 5);
|
result = matcher.compare(4.030904708957288, 4.0309, 5);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
result = matcher.compare(4.82665525779431,4.82666, 5);
|
result = matcher.compare(4.82665525779431, 4.82666, 5);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
result = matcher.compare(-2.82665525779431, -2.82666, 5);
|
result = matcher.compare(-2.82665525779431, -2.82666, 5);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
describe("toBeDefined", function() {
|
describe('toBeDefined', function() {
|
||||||
it("matches for defined values", function() {
|
it('matches for defined values', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeDefined(),
|
var matcher = jasmineUnderTest.matchers.toBeDefined(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|
||||||
result = matcher.compare('foo');
|
result = matcher.compare('foo');
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when matching undefined values", function() {
|
it('fails when matching undefined values', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeDefined(),
|
var matcher = jasmineUnderTest.matchers.toBeDefined(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(void 0);
|
result = matcher.compare(void 0);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeFalse", function() {
|
describe('toBeFalse', function() {
|
||||||
it("passes for false", function() {
|
it('passes for false', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ describe("toBeFalse", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for non-false", function() {
|
it('fails for non-false', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ describe("toBeFalse", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for falsy", function() {
|
it('fails for falsy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
describe("toBeFalsy", function() {
|
describe('toBeFalsy', function() {
|
||||||
it("passes for 'falsy' values", function() {
|
it("passes for 'falsy' values", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeFalsy(),
|
var matcher = jasmineUnderTest.matchers.toBeFalsy(),
|
||||||
result;
|
result;
|
||||||
@@ -15,6 +15,9 @@ describe("toBeFalsy", function() {
|
|||||||
result = matcher.compare(null);
|
result = matcher.compare(null);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
|
result = matcher.compare(undefined);
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
result = matcher.compare(void 0);
|
result = matcher.compare(void 0);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -29,10 +32,16 @@ describe("toBeFalsy", function() {
|
|||||||
result = matcher.compare(1);
|
result = matcher.compare(1);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
|
|
||||||
result = matcher.compare("foo");
|
result = matcher.compare('foo');
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
|
|
||||||
result = matcher.compare({});
|
result = matcher.compare({});
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
|
|
||||||
|
result = matcher.compare([]);
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
|
||||||
|
result = matcher.compare(function() {});
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeGreaterThanOrEqual", function() {
|
describe('toBeGreaterThanOrEqual', function() {
|
||||||
it("passes when actual >= expected", function() {
|
it('passes when actual >= expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeGreaterThanOrEqual(),
|
var matcher = jasmineUnderTest.matchers.toBeGreaterThanOrEqual(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ describe("toBeGreaterThanOrEqual", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when actual < expected", function() {
|
it('fails when actual < expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeGreaterThanOrEqual(),
|
var matcher = jasmineUnderTest.matchers.toBeGreaterThanOrEqual(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -25,5 +25,5 @@ describe("toBeGreaterThanOrEqual", function() {
|
|||||||
|
|
||||||
result = matcher.compare(1, 1.0000001);
|
result = matcher.compare(1, 1.0000001);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeGreaterThan", function() {
|
describe('toBeGreaterThan', function() {
|
||||||
it("passes when actual > expected", function() {
|
it('passes when actual > expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeGreaterThan(),
|
var matcher = jasmineUnderTest.matchers.toBeGreaterThan(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ describe("toBeGreaterThan", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when actual <= expected", function() {
|
it('fails when actual <= expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeGreaterThan(),
|
var matcher = jasmineUnderTest.matchers.toBeGreaterThan(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|||||||
@@ -92,13 +92,14 @@ describe('toBeInstanceOf', function() {
|
|||||||
|
|
||||||
describe('when expecting Function', function() {
|
describe('when expecting Function', function() {
|
||||||
it('passes for a function', function() {
|
it('passes for a function', function() {
|
||||||
var fn = function() { };
|
var fn = function() {};
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
||||||
var result = matcher.compare(fn, Function);
|
var result = matcher.compare(fn, Function);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
pass: true,
|
pass: true,
|
||||||
message: 'Expected instance of Function not to be an instance of Function'
|
message:
|
||||||
|
'Expected instance of Function not to be an instance of Function'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -111,13 +112,14 @@ describe('toBeInstanceOf', function() {
|
|||||||
var result = matcher.compare(fn, Function);
|
var result = matcher.compare(fn, Function);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
pass: true,
|
pass: true,
|
||||||
message: 'Expected instance of AsyncFunction not to be an instance of Function'
|
message:
|
||||||
|
'Expected instance of AsyncFunction not to be an instance of Function'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when expecting Object', function() {
|
describe('when expecting Object', function() {
|
||||||
function Animal() { }
|
function Animal() {}
|
||||||
|
|
||||||
it('passes for any object', function() {
|
it('passes for any object', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
||||||
@@ -164,14 +166,15 @@ describe('toBeInstanceOf', function() {
|
|||||||
var result = matcher.compare(object, Object);
|
var result = matcher.compare(object, Object);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
pass: true,
|
pass: true,
|
||||||
message: 'Expected instance of null({ }) not to be an instance of Object'
|
message:
|
||||||
|
'Expected instance of null({ }) not to be an instance of Object'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when expecting a user-defined class', function() {
|
describe('when expecting a user-defined class', function() {
|
||||||
// Base class
|
// Base class
|
||||||
function Animal() { }
|
function Animal() {}
|
||||||
|
|
||||||
// Subclasses, defined using syntax that is as old as possible
|
// Subclasses, defined using syntax that is as old as possible
|
||||||
function Dog() {
|
function Dog() {
|
||||||
@@ -218,8 +221,10 @@ describe('toBeInstanceOf', function() {
|
|||||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare({}, 'Error');
|
matcher.compare({}, 'Error');
|
||||||
}).toThrowError('<toBeInstanceOf> : Expected value is not a constructor function\n' +
|
}).toThrowError(
|
||||||
'Usage: expect(value).toBeInstanceOf(<ConstructorFunction>)');
|
'<toBeInstanceOf> : Expected value is not a constructor function\n' +
|
||||||
|
'Usage: expect(value).toBeInstanceOf(<ConstructorFunction>)'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('raises an error if missing an expected value', function() {
|
it('raises an error if missing an expected value', function() {
|
||||||
@@ -228,7 +233,9 @@ describe('toBeInstanceOf', function() {
|
|||||||
});
|
});
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare({}, undefined);
|
matcher.compare({}, undefined);
|
||||||
}).toThrowError('<toBeInstanceOf> : Expected value is not a constructor function\n' +
|
}).toThrowError(
|
||||||
'Usage: expect(value).toBeInstanceOf(<ConstructorFunction>)');
|
'<toBeInstanceOf> : Expected value is not a constructor function\n' +
|
||||||
|
'Usage: expect(value).toBeInstanceOf(<ConstructorFunction>)'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeLessThanOrEqual", function() {
|
describe('toBeLessThanOrEqual', function() {
|
||||||
it("passes when actual <= expected", function() {
|
it('passes when actual <= expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeLessThanOrEqual(),
|
var matcher = jasmineUnderTest.matchers.toBeLessThanOrEqual(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -11,12 +11,12 @@ describe("toBeLessThanOrEqual", function() {
|
|||||||
|
|
||||||
result = matcher.compare(1, 1.0000001);
|
result = matcher.compare(1, 1.0000001);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
result = matcher.compare(1.0, 1.0);
|
result = matcher.compare(1.0, 1.0);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when actual < expected", function() {
|
it('fails when actual < expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeLessThanOrEqual(),
|
var matcher = jasmineUnderTest.matchers.toBeLessThanOrEqual(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeLessThan", function() {
|
describe('toBeLessThan', function() {
|
||||||
it("passes when actual < expected", function() {
|
it('passes when actual < expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeLessThan(),
|
var matcher = jasmineUnderTest.matchers.toBeLessThan(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ describe("toBeLessThan", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when actual <= expected", function() {
|
it('fails when actual <= expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeLessThan(),
|
var matcher = jasmineUnderTest.matchers.toBeLessThan(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
describe("toBeNaN", function() {
|
describe('toBeNaN', function() {
|
||||||
it("passes for NaN with a custom .not fail", function() {
|
it('passes for NaN with a custom .not fail', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNaN(),
|
var matcher = jasmineUnderTest.matchers.toBeNaN(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(Number.NaN);
|
result = matcher.compare(Number.NaN);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected actual not to be NaN.");
|
expect(result.message).toEqual('Expected actual not to be NaN.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for anything not a NaN", function() {
|
it('fails for anything not a NaN', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNaN(),
|
var matcher = jasmineUnderTest.matchers.toBeNaN(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -28,12 +28,12 @@ describe("toBeNaN", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a custom message on failure", function() {
|
it('has a custom message on failure', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNaN({
|
var matcher = jasmineUnderTest.matchers.toBeNaN({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
result = matcher.compare(0);
|
result = matcher.compare(0);
|
||||||
|
|
||||||
expect(result.message()).toEqual("Expected 0 to be NaN.");
|
expect(result.message()).toEqual('Expected 0 to be NaN.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
describe("toBeNegativeInfinity", function() {
|
describe('toBeNegativeInfinity', function() {
|
||||||
it("fails for anything that isn't -Infinity", function() {
|
it("fails for anything that isn't -Infinity", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
|
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
|
||||||
result;
|
result;
|
||||||
@@ -13,21 +13,20 @@ describe("toBeNegativeInfinity", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a custom message on failure", function() {
|
it('has a custom message on failure', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity({
|
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
result = matcher.compare(0);
|
result = matcher.compare(0);
|
||||||
|
|
||||||
expect(result.message()).toEqual("Expected 0 to be -Infinity.")
|
expect(result.message()).toEqual('Expected 0 to be -Infinity.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("succeeds for -Infinity", function() {
|
it('succeeds for -Infinity', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
|
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
|
||||||
result = matcher.compare(Number.NEGATIVE_INFINITY);
|
result = matcher.compare(Number.NEGATIVE_INFINITY);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected actual not to be -Infinity.")
|
expect(result.message).toEqual('Expected actual not to be -Infinity.');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeNull", function() {
|
describe('toBeNull', function() {
|
||||||
it("passes for null", function() {
|
it('passes for null', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNull(),
|
var matcher = jasmineUnderTest.matchers.toBeNull(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ describe("toBeNull", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for non-null", function() {
|
it('fails for non-null', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeNull(),
|
var matcher = jasmineUnderTest.matchers.toBeNull(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
describe("toBePositiveInfinity", function() {
|
describe('toBePositiveInfinity', function() {
|
||||||
it("fails for anything that isn't Infinity", function() {
|
it("fails for anything that isn't Infinity", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
|
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
|
||||||
result;
|
result;
|
||||||
@@ -13,21 +13,20 @@ describe("toBePositiveInfinity", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a custom message on failure", function() {
|
it('has a custom message on failure', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity({
|
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
result = matcher.compare(0);
|
result = matcher.compare(0);
|
||||||
|
|
||||||
expect(result.message()).toEqual("Expected 0 to be Infinity.")
|
expect(result.message()).toEqual('Expected 0 to be Infinity.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("succeeds for Infinity", function() {
|
it('succeeds for Infinity', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
|
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
|
||||||
result = matcher.compare(Number.POSITIVE_INFINITY);
|
result = matcher.compare(Number.POSITIVE_INFINITY);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected actual not to be Infinity.")
|
expect(result.message).toEqual('Expected actual not to be Infinity.');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBe", function() {
|
describe('toBe', function() {
|
||||||
it("passes with no message when actual === expected", function() {
|
it('passes with no message when actual === expected', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
@@ -8,29 +8,37 @@ describe("toBe", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes with a custom message when expected is an array", function() {
|
it('passes with a custom message when expected is an array', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result,
|
result,
|
||||||
array = [1];
|
array = [1];
|
||||||
|
|
||||||
result = matcher.compare(array, array);
|
result = matcher.compare(array, array);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toBe("Expected [ 1 ] not to be [ 1 ]. Tip: To check for deep equality, use .toEqual() instead of .toBe().")
|
expect(result.message).toBe(
|
||||||
|
'Expected [ 1 ] not to be [ 1 ]. Tip: To check for deep equality, use .toEqual() instead of .toBe().'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes with a custom message when expected is an object", function() {
|
it('passes with a custom message when expected is an object', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result,
|
result,
|
||||||
obj = {foo: "bar"};
|
obj = { foo: 'bar' };
|
||||||
|
|
||||||
result = matcher.compare(obj, obj);
|
result = matcher.compare(obj, obj);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toBe("Expected Object({ foo: 'bar' }) not to be Object({ foo: 'bar' }). Tip: To check for deep equality, use .toEqual() instead of .toBe().")
|
expect(result.message).toBe(
|
||||||
|
"Expected Object({ foo: 'bar' }) not to be Object({ foo: 'bar' }). Tip: To check for deep equality, use .toEqual() instead of .toBe()."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails with no message when actual !== expected", function() {
|
it('fails with no message when actual !== expected', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
@@ -40,35 +48,47 @@ describe("toBe", function() {
|
|||||||
expect(result.message).toBeUndefined();
|
expect(result.message).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails with a custom message when expected is an array", function() {
|
it('fails with a custom message when expected is an array', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare([1], [1]);
|
result = matcher.compare([1], [1]);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toBe("Expected [ 1 ] to be [ 1 ]. Tip: To check for deep equality, use .toEqual() instead of .toBe().")
|
expect(result.message).toBe(
|
||||||
|
'Expected [ 1 ] to be [ 1 ]. Tip: To check for deep equality, use .toEqual() instead of .toBe().'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails with a custom message when expected is an object", function() {
|
it('fails with a custom message when expected is an object', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare({foo: "bar"}, {foo: "bar"});
|
result = matcher.compare({ foo: 'bar' }, { foo: 'bar' });
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toBe("Expected Object({ foo: 'bar' }) to be Object({ foo: 'bar' }). Tip: To check for deep equality, use .toEqual() instead of .toBe().")
|
expect(result.message).toBe(
|
||||||
|
"Expected Object({ foo: 'bar' }) to be Object({ foo: 'bar' }). Tip: To check for deep equality, use .toEqual() instead of .toBe()."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("works with custom object formatters when expected is an object", function() {
|
it('works with custom object formatters when expected is an object', function() {
|
||||||
var formatter = function(x) { return '<' + x.foo + '>'; },
|
var formatter = function(x) {
|
||||||
|
return '<' + x.foo + '>';
|
||||||
|
},
|
||||||
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: prettyPrinter}),
|
matchersUtil = new jasmineUnderTest.MatchersUtil({ pp: prettyPrinter }),
|
||||||
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare({foo: "bar"}, {foo: "bar"});
|
result = matcher.compare({ foo: 'bar' }, { foo: 'bar' });
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toBe("Expected <bar> to be <bar>. Tip: To check for deep equality, use .toEqual() instead of .toBe().")
|
expect(result.message).toBe(
|
||||||
|
'Expected <bar> to be <bar>. Tip: To check for deep equality, use .toEqual() instead of .toBe().'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toBeTrue", function() {
|
describe('toBeTrue', function() {
|
||||||
it("passes for true", function() {
|
it('passes for true', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeTrue(),
|
var matcher = jasmineUnderTest.matchers.toBeTrue(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ describe("toBeTrue", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for non-true", function() {
|
it('fails for non-true', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeTrue(),
|
var matcher = jasmineUnderTest.matchers.toBeTrue(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
describe("toBeTruthy", function() {
|
describe('toBeTruthy', function() {
|
||||||
it("passes for 'truthy' values", function() {
|
it("passes for 'truthy' values", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeTruthy(),
|
var matcher = jasmineUnderTest.matchers.toBeTruthy(),
|
||||||
result;
|
result;
|
||||||
@@ -9,11 +9,17 @@ describe("toBeTruthy", function() {
|
|||||||
result = matcher.compare(1);
|
result = matcher.compare(1);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
result = matcher.compare("foo");
|
result = matcher.compare('foo');
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
result = matcher.compare({});
|
result = matcher.compare({});
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
|
result = matcher.compare([]);
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
|
result = matcher.compare(function() {});
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails for 'falsy' values", function() {
|
it("fails for 'falsy' values", function() {
|
||||||
@@ -32,6 +38,9 @@ describe("toBeTruthy", function() {
|
|||||||
result = matcher.compare(null);
|
result = matcher.compare(null);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
|
|
||||||
|
result = matcher.compare(undefined);
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
|
||||||
result = matcher.compare(void 0);
|
result = matcher.compare(void 0);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
describe("toBeUndefined", function() {
|
describe('toBeUndefined', function() {
|
||||||
it("passes for undefined values", function() {
|
it('passes for undefined values', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeUndefined(),
|
var matcher = jasmineUnderTest.matchers.toBeUndefined(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(void 0);
|
result = matcher.compare(void 0);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when matching defined values", function() {
|
it('fails when matching defined values', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeUndefined(),
|
var matcher = jasmineUnderTest.matchers.toBeUndefined(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare('foo');
|
result = matcher.compare('foo');
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
describe("toContain", function() {
|
describe('toContain', function() {
|
||||||
it("delegates to jasmineUnderTest.matchersUtil.contains", function() {
|
it('delegates to jasmineUnderTest.matchersUtil.contains', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare("ABC", "B");
|
result = matcher.compare('ABC', 'B');
|
||||||
expect(matchersUtil.contains).toHaveBeenCalledWith("ABC", "B");
|
expect(matchersUtil.contains).toHaveBeenCalledWith('ABC', 'B');
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("works with custom equality testers", function() {
|
it('works with custom equality testers', function() {
|
||||||
var tester = function (a, b) {
|
var tester = function(a, b) {
|
||||||
return a.toString() === b.toString();
|
return a.toString() === b.toString();
|
||||||
},
|
},
|
||||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]}),
|
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: [tester]
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,29 +1,29 @@
|
|||||||
describe("toHaveBeenCalledBefore", function() {
|
describe('toHaveBeenCalledBefore', function() {
|
||||||
it("throws an exception when the actual is not a spy", function() {
|
it('throws an exception when the actual is not a spy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
fn = function() {},
|
fn = function() {},
|
||||||
spy = new jasmineUnderTest.Env().createSpy('a spy');
|
spy = new jasmineUnderTest.Env().createSpy('a spy');
|
||||||
|
|
||||||
expect(function () {
|
expect(function() {
|
||||||
matcher.compare(fn, spy);
|
matcher.compare(fn, spy);
|
||||||
}).toThrowError(Error, /Expected a spy, but got Function./);
|
}).toThrowError(Error, /Expected a spy, but got Function./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when the expected is not a spy", function() {
|
it('throws an exception when the expected is not a spy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
spy = new jasmineUnderTest.Env().createSpy('a spy'),
|
spy = new jasmineUnderTest.Env().createSpy('a spy'),
|
||||||
fn = function() {};
|
fn = function() {};
|
||||||
|
|
||||||
expect(function () {
|
expect(function() {
|
||||||
matcher.compare(spy, fn);
|
matcher.compare(spy, fn);
|
||||||
}).toThrowError(Error, /Expected a spy, but got Function./);
|
}).toThrowError(Error, /Expected a spy, but got Function./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was not called", function () {
|
it('fails when the actual was not called', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Spy('second spy');
|
secondSpy = new jasmineUnderTest.Spy('second spy');
|
||||||
@@ -32,10 +32,12 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
result = matcher.compare(firstSpy, secondSpy);
|
result = matcher.compare(firstSpy, secondSpy);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toMatch(/Expected spy first spy to have been called./);
|
expect(result.message).toMatch(
|
||||||
|
/Expected spy first spy to have been called./
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the expected was not called", function () {
|
it('fails when the expected was not called', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Spy('second spy');
|
secondSpy = new jasmineUnderTest.Spy('second spy');
|
||||||
@@ -44,10 +46,12 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
result = matcher.compare(firstSpy, secondSpy);
|
result = matcher.compare(firstSpy, secondSpy);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toMatch(/Expected spy second spy to have been called./);
|
expect(result.message).toMatch(
|
||||||
|
/Expected spy second spy to have been called./
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual is called after the expected", function () {
|
it('fails when the actual is called after the expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
@@ -58,10 +62,12 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
result = matcher.compare(firstSpy, secondSpy);
|
result = matcher.compare(firstSpy, secondSpy);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual('Expected spy first spy to have been called before spy second spy');
|
expect(result.message).toEqual(
|
||||||
|
'Expected spy first spy to have been called before spy second spy'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual is called before and after the expected", function () {
|
it('fails when the actual is called before and after the expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
@@ -73,10 +79,12 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
result = matcher.compare(firstSpy, secondSpy);
|
result = matcher.compare(firstSpy, secondSpy);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual('Expected latest call to spy first spy to have been called before first call to spy second spy (no interleaved calls)');
|
expect(result.message).toEqual(
|
||||||
|
'Expected latest call to spy first spy to have been called before first call to spy second spy (no interleaved calls)'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the expected is called before and after the actual", function () {
|
it('fails when the expected is called before and after the actual', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
@@ -88,10 +96,12 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
result = matcher.compare(firstSpy, secondSpy);
|
result = matcher.compare(firstSpy, secondSpy);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual('Expected first call to spy second spy to have been called after latest call to spy first spy (no interleaved calls)');
|
expect(result.message).toEqual(
|
||||||
|
'Expected first call to spy second spy to have been called after latest call to spy first spy (no interleaved calls)'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes when the actual is called before the expected", function () {
|
it('passes when the actual is called before the expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
@@ -102,6 +112,8 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
result = matcher.compare(firstSpy, secondSpy);
|
result = matcher.compare(firstSpy, secondSpy);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual('Expected spy first spy to not have been called before spy second spy, but it was');
|
expect(result.message).toEqual(
|
||||||
|
'Expected spy first spy to not have been called before spy second spy, but it was'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
describe("toHaveBeenCalledOnceWith", function () {
|
describe('toHaveBeenCalledOnceWith', function() {
|
||||||
|
it('passes when the actual was called only once and with matching parameters', function() {
|
||||||
it("passes when the actual was called only once and with matching parameters", function () {
|
var pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
var util = jasmineUnderTest.matchersUtil,
|
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -10,13 +10,23 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
result = matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected spy called-spy to have been called 0 times, multiple times, or once, but with arguments different from:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'b' ].\n\n");
|
expect(result.message).toEqual(
|
||||||
|
"Expected spy called-spy to have been called 0 times, multiple times, or once, but with arguments different from:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'b' ].\n\n"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("supports custom equality testers", function () {
|
it('supports custom equality testers', function() {
|
||||||
var customEqualityTesters = [function() { return true; }],
|
var customEqualityTesters = [
|
||||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
function() {
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(matchersUtil),
|
return true;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: customEqualityTesters
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(
|
||||||
|
matchersUtil
|
||||||
|
),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -26,8 +36,9 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was never called", function () {
|
it('fails when the actual was never called', function() {
|
||||||
var util = jasmineUnderTest.matchersUtil,
|
var pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
|
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -35,11 +46,14 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
result = matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut it was never called.\n\n");
|
expect(result.message).toEqual(
|
||||||
|
"Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut it was never called.\n\n"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called once with different parameters", function () {
|
it('fails when the actual was called once with different parameters', function() {
|
||||||
var util = jasmineUnderTest.matchersUtil,
|
var pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
|
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -48,11 +62,14 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
result = matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'c' ].\nExpected $[1] = 'c' to equal 'b'.\n\n");
|
expect(result.message).toEqual(
|
||||||
|
"Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'c' ].\nExpected $[1] = 'c' to equal 'b'.\n\n"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called multiple times with expected parameters", function () {
|
it('fails when the actual was called multiple times with expected parameters', function() {
|
||||||
var util = jasmineUnderTest.matchersUtil,
|
var pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
|
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -62,11 +79,14 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
result = matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'b' ].\n\n");
|
expect(result.message).toEqual(
|
||||||
|
"Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'b' ].\n\n"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called multiple times (one of them - with expected parameters)", function () {
|
it('fails when the actual was called multiple times (one of them - with expected parameters)', function() {
|
||||||
var util = jasmineUnderTest.matchersUtil,
|
var pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
|
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -76,13 +96,19 @@ describe("toHaveBeenCalledOnceWith", function () {
|
|||||||
result = matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'c' ].\n\n");
|
expect(result.message).toEqual(
|
||||||
|
"Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'c' ].\n\n"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when the actual is not a spy", function () {
|
it('throws an exception when the actual is not a spy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(),
|
var pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
fn = function () { };
|
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
|
fn = function() {};
|
||||||
|
|
||||||
expect(function () { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
|
expect(function() {
|
||||||
|
matcher.compare(fn);
|
||||||
|
}).toThrowError(/Expected a spy, but got Function./);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toHaveBeenCalled", function() {
|
describe('toHaveBeenCalled', function() {
|
||||||
it("passes when the actual was called, with a custom .not fail message", function() {
|
it('passes when the actual was called, with a custom .not fail message', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -8,10 +8,12 @@ describe("toHaveBeenCalled", function() {
|
|||||||
|
|
||||||
result = matcher.compare(calledSpy);
|
result = matcher.compare(calledSpy);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected spy called-spy not to have been called.");
|
expect(result.message).toEqual(
|
||||||
|
'Expected spy called-spy not to have been called.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was not called", function() {
|
it('fails when the actual was not called', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
@@ -20,30 +22,35 @@ describe("toHaveBeenCalled", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when the actual is not a spy", function() {
|
it('throws an exception when the actual is not a spy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled({
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
fn = function() {};
|
fn = function() {};
|
||||||
|
|
||||||
expect(function() { matcher.compare(fn) }).toThrowError(Error, /Expected a spy, but got Function./);
|
expect(function() {
|
||||||
|
matcher.compare(fn);
|
||||||
|
}).toThrowError(Error, /Expected a spy, but got Function./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when invoked with any arguments", function() {
|
it('throws an exception when invoked with any arguments', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
spy = new jasmineUnderTest.Spy('sample spy');
|
spy = new jasmineUnderTest.Spy('sample spy');
|
||||||
|
|
||||||
expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/);
|
expect(function() {
|
||||||
|
matcher.compare(spy, 'foo');
|
||||||
|
}).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a custom message on failure", function() {
|
it('has a custom message on failure', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
spy = new jasmineUnderTest.Spy('sample-spy'),
|
spy = new jasmineUnderTest.Spy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(spy);
|
result = matcher.compare(spy);
|
||||||
|
|
||||||
expect(result.message).toEqual("Expected spy sample-spy to have been called.");
|
expect(result.message).toEqual(
|
||||||
|
'Expected spy sample-spy to have been called.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
describe("toHaveBeenCalledTimes", function() {
|
describe('toHaveBeenCalledTimes', function() {
|
||||||
it("passes when the actual 0 matches the expected 0 ", function () {
|
it('passes when the actual 0 matches the expected 0 ', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
result = matcher.compare(calledSpy, 0);
|
result = matcher.compare(calledSpy, 0);
|
||||||
expect(result.pass).toBeTruthy();
|
expect(result.pass).toBeTruthy();
|
||||||
});
|
});
|
||||||
it("passes when the actual matches the expected", function() {
|
it('passes when the actual matches the expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -16,18 +16,20 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when expected numbers is not supplied", function(){
|
it('fails when expected numbers is not supplied', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
spy = new jasmineUnderTest.Spy('spy'),
|
spy = new jasmineUnderTest.Spy('spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
spy();
|
spy();
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare(spy);
|
matcher.compare(spy);
|
||||||
}).toThrowError(/The expected times failed is a required argument and must be a number./);
|
}).toThrowError(
|
||||||
|
/The expected times failed is a required argument and must be a number./
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called less than the expected", function() {
|
it('fails when the actual was called less than the expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
@@ -36,7 +38,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called more than expected", function() {
|
it('fails when the actual was called more than expected', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
@@ -48,7 +50,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when the actual is not a spy", function() {
|
it('throws an exception when the actual is not a spy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes({
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
@@ -59,7 +61,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
}).toThrowError(/Expected a spy, but got Function./);
|
}).toThrowError(/Expected a spy, but got Function./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a custom message on failure that tells it was called only once", function() {
|
it('has a custom message on failure that tells it was called only once', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
spy = new jasmineUnderTest.Spy('sample-spy'),
|
spy = new jasmineUnderTest.Spy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -69,10 +71,14 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
spy();
|
spy();
|
||||||
|
|
||||||
result = matcher.compare(spy, 1);
|
result = matcher.compare(spy, 1);
|
||||||
expect(result.message).toEqual('Expected spy sample-spy to have been called once. It was called ' + 4 + ' times.');
|
expect(result.message).toEqual(
|
||||||
|
'Expected spy sample-spy to have been called once. It was called ' +
|
||||||
|
4 +
|
||||||
|
' times.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a custom message on failure that tells how many times it was called", function() {
|
it('has a custom message on failure that tells how many times it was called', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
spy = new jasmineUnderTest.Spy('sample-spy'),
|
spy = new jasmineUnderTest.Spy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -82,7 +88,10 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
spy();
|
spy();
|
||||||
|
|
||||||
result = matcher.compare(spy, 2);
|
result = matcher.compare(spy, 2);
|
||||||
expect(result.message).toEqual('Expected spy sample-spy to have been called 2 times. It was called ' + 4 + ' times.');
|
expect(result.message).toEqual(
|
||||||
|
'Expected spy sample-spy to have been called 2 times. It was called ' +
|
||||||
|
4 +
|
||||||
|
' times.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,31 @@
|
|||||||
describe("toHaveBeenCalledWith", function() {
|
describe('toHaveBeenCalledWith', function() {
|
||||||
|
it('passes when the actual was called with matching parameters', function() {
|
||||||
it("passes when the actual was called with matching parameters", function() {
|
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true),
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(true),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
calledSpy('a', 'b');
|
calledSpy('a', 'b');
|
||||||
result = matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected spy called-spy not to have been called with:\n [ 'a', 'b' ]\nbut it was.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected spy called-spy not to have been called with:\n [ 'a', 'b' ]\nbut it was."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("supports custom equality testers", function() {
|
it('supports custom equality testers', function() {
|
||||||
var customEqualityTesters = [function() { return true; }],
|
var customEqualityTesters = [
|
||||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
function() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: customEqualityTesters
|
||||||
|
}),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
@@ -28,25 +35,31 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was not called", function() {
|
it('fails when the actual was not called', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false),
|
contains: jasmine
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
.createSpy('delegated-contains')
|
||||||
},
|
.and.returnValue(false),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
},
|
||||||
result;
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy);
|
result = matcher.compare(uncalledSpy);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected spy uncalled spy to have been called with:\n [ ]\nbut it was never called.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected spy uncalled spy to have been called with:\n [ ]\nbut it was never called.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called with different parameters", function() {
|
it('fails when the actual was called with different parameters', function() {
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
calledSpy = new jasmineUnderTest.Spy('called spy'),
|
}),
|
||||||
result;
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
|
calledSpy = new jasmineUnderTest.Spy('called spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
calledSpy('a');
|
calledSpy('a');
|
||||||
calledSpy('c', 'd');
|
calledSpy('c', 'd');
|
||||||
@@ -55,30 +68,32 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual(
|
expect(result.message()).toEqual(
|
||||||
"Expected spy called spy to have been called with:\n" +
|
'Expected spy called spy to have been called with:\n' +
|
||||||
" [ 'a', 'b' ]\n" +
|
" [ 'a', 'b' ]\n" +
|
||||||
"but actual calls were:\n" +
|
'but actual calls were:\n' +
|
||||||
" [ 'a' ],\n" +
|
" [ 'a' ],\n" +
|
||||||
" [ 'c', 'd' ],\n" +
|
" [ 'c', 'd' ],\n" +
|
||||||
" [ 'a', 'b', 'c' ].\n\n" +
|
" [ 'a', 'b', 'c' ].\n\n" +
|
||||||
"Call 0:\n" +
|
'Call 0:\n' +
|
||||||
" Expected $.length = 1 to equal 2.\n" +
|
' Expected $.length = 1 to equal 2.\n' +
|
||||||
" Expected $[1] = undefined to equal 'b'.\n" +
|
" Expected $[1] = undefined to equal 'b'.\n" +
|
||||||
"Call 1:\n" +
|
'Call 1:\n' +
|
||||||
" Expected $[0] = 'c' to equal 'a'.\n" +
|
" Expected $[0] = 'c' to equal 'a'.\n" +
|
||||||
" Expected $[1] = 'd' to equal 'b'.\n" +
|
" Expected $[1] = 'd' to equal 'b'.\n" +
|
||||||
"Call 2:\n" +
|
'Call 2:\n' +
|
||||||
" Expected $.length = 3 to equal 2.\n" +
|
' Expected $.length = 3 to equal 2.\n' +
|
||||||
" Unexpected $[2] = 'c' in array.");
|
" Unexpected $[2] = 'c' in array."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when the actual is not a spy", function() {
|
it('throws an exception when the actual is not a spy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith({
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
fn = function () {
|
fn = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
expect(function() { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
|
expect(function() {
|
||||||
|
matcher.compare(fn);
|
||||||
|
}).toThrowError(/Expected a spy, but got Function./);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ describe('toHaveClass', function() {
|
|||||||
|
|
||||||
it('fails for a DOM element that lacks the expected class', function() {
|
it('fails for a DOM element that lacks the expected class', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveClass(),
|
var matcher = jasmineUnderTest.matchers.toHaveClass(),
|
||||||
result = matcher.compare(this.domHelpers.createElementWithClassName(''), 'foo');
|
result = matcher.compare(
|
||||||
|
this.domHelpers.createElementWithClassName(''),
|
||||||
|
'foo'
|
||||||
|
);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -41,11 +44,11 @@ describe('toHaveClass', function() {
|
|||||||
|
|
||||||
var textNode = this.domHelpers.document.createTextNode('');
|
var textNode = this.domHelpers.document.createTextNode('');
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare(textNode, 'foo')
|
matcher.compare(textNode, 'foo');
|
||||||
}).toThrowError('HTMLNode is not a DOM element');
|
}).toThrowError('HTMLNode is not a DOM element');
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare({classList: ''}, 'foo');
|
matcher.compare({ classList: '' }, 'foo');
|
||||||
}).toThrowError("Object({ classList: '' }) is not a DOM element");
|
}).toThrowError("Object({ classList: '' }) is not a DOM element");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,28 +18,28 @@ describe('toHaveSize', function() {
|
|||||||
|
|
||||||
it('passes for an object with the proper number of keys', function() {
|
it('passes for an object with the proper number of keys', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
result = matcher.compare({a: 1, b: 2}, 2);
|
result = matcher.compare({ a: 1, b: 2 }, 2);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails for an object with a different number of keys', function() {
|
it('fails for an object with a different number of keys', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
result = matcher.compare({a: 1, b: 2}, 1);
|
result = matcher.compare({ a: 1, b: 2 }, 1);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes for an object with an explicit `length` property that matches', function() {
|
it('passes for an object with an explicit `length` property that matches', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
result = matcher.compare({a: 1, b: 2, length: 5}, 5);
|
result = matcher.compare({ a: 1, b: 2, length: 5 }, 5);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails for an object with an explicit `length` property that does not match', function() {
|
it('fails for an object with an explicit `length` property that does not match', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
result = matcher.compare({a: 1, b: 2, length: 5}, 1);
|
result = matcher.compare({ a: 1, b: 2, length: 5 }, 1);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -62,8 +62,8 @@ describe('toHaveSize', function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var map = new Map();
|
var map = new Map();
|
||||||
map.set('a',1);
|
map.set('a', 1);
|
||||||
map.set('b',2);
|
map.set('b', 2);
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
result = matcher.compare(map, 2);
|
result = matcher.compare(map, 2);
|
||||||
@@ -75,8 +75,8 @@ describe('toHaveSize', function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var map = new Map();
|
var map = new Map();
|
||||||
map.set('a',1);
|
map.set('a', 1);
|
||||||
map.set('b',2);
|
map.set('b', 2);
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
result = matcher.compare(map, 1);
|
result = matcher.compare(map, 1);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
describe("toMatch", function() {
|
describe('toMatch', function() {
|
||||||
|
it('passes when RegExps are equivalent', function() {
|
||||||
it("passes when RegExps are equivalent", function() {
|
|
||||||
var matcher = jasmineUnderTest.matchers.toMatch(),
|
var matcher = jasmineUnderTest.matchers.toMatch(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ describe("toMatch", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when RegExps are not equivalent", function() {
|
it('fails when RegExps are not equivalent', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toMatch(),
|
var matcher = jasmineUnderTest.matchers.toMatch(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ describe("toMatch", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes when the actual matches the expected string as a pattern", function() {
|
it('passes when the actual matches the expected string as a pattern', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toMatch(),
|
var matcher = jasmineUnderTest.matchers.toMatch(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ describe("toMatch", function() {
|
|||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual matches the expected string as a pattern", function() {
|
it('fails when the actual matches the expected string as a pattern', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toMatch(),
|
var matcher = jasmineUnderTest.matchers.toMatch(),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ describe("toMatch", function() {
|
|||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an Error when the expected is not a String or RegExp", function() {
|
it('throws an Error when the expected is not a String or RegExp', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toMatch();
|
var matcher = jasmineUnderTest.matchers.toMatch();
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -40,4 +39,3 @@ describe("toMatch", function() {
|
|||||||
}).toThrowError(/Expected is not a String or a RegExp/);
|
}).toThrowError(/Expected is not a String or a RegExp/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe("toThrowError", function() {
|
describe('toThrowError', function() {
|
||||||
it("throws an error when the actual is not a function", function() {
|
it('throws an error when the actual is not a function', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError();
|
var matcher = jasmineUnderTest.matchers.toThrowError();
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -7,10 +7,10 @@ describe("toThrowError", function() {
|
|||||||
}).toThrowError(/Actual is not a Function/);
|
}).toThrowError(/Actual is not a Function/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an error when the expected is not an Error, string, or RegExp", function() {
|
it('throws an error when the expected is not an Error, string, or RegExp', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error('foo');
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -18,21 +18,21 @@ describe("toThrowError", function() {
|
|||||||
}).toThrowError(/Expected is not an Error, string, or RegExp./);
|
}).toThrowError(/Expected is not an Error, string, or RegExp./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an error when the expected error type is not an Error", function() {
|
it('throws an error when the expected error type is not an Error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error('foo');
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare(fn, void 0, "foo");
|
matcher.compare(fn, void 0, 'foo');
|
||||||
}).toThrowError(/Expected error type is not an Error./);
|
}).toThrowError(/Expected error type is not an Error./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an error when the expected error message is not a string or RegExp", function() {
|
it('throws an error when the expected error message is not a string or RegExp', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error('foo');
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -40,7 +40,7 @@ describe("toThrowError", function() {
|
|||||||
}).toThrowError(/Expected error message is not a string or RegExp./);
|
}).toThrowError(/Expected error message is not a string or RegExp./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if actual does not throw at all", function() {
|
it('fails if actual does not throw at all', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
return true;
|
return true;
|
||||||
@@ -50,10 +50,10 @@ describe("toThrowError", function() {
|
|||||||
result = matcher.compare(fn);
|
result = matcher.compare(fn);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected function to throw an Error.");
|
expect(result.message).toEqual('Expected function to throw an Error.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if thrown is not an instanceof Error", function() {
|
it('fails if thrown is not an instanceof Error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
@@ -64,12 +64,14 @@ describe("toThrowError", function() {
|
|||||||
|
|
||||||
result = matcher.compare(fn);
|
result = matcher.compare(fn);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw an Error, but it threw 4.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function to throw an Error, but it threw 4.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when error is from another frame", function() {
|
describe('when error is from another frame', function() {
|
||||||
function isNotRunningInBrowser() {
|
function isNotRunningInBrowser() {
|
||||||
return typeof document === 'undefined'
|
return typeof document === 'undefined';
|
||||||
}
|
}
|
||||||
|
|
||||||
var iframe = null;
|
var iframe = null;
|
||||||
@@ -80,31 +82,36 @@ describe("toThrowError", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is an instanceof Error regardless of global that contains its constructor", function() {
|
it('passes if thrown is an instanceof Error regardless of global that contains its constructor', function() {
|
||||||
if (isNotRunningInBrowser()) {
|
if (isNotRunningInBrowser()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError();
|
var matcher = jasmineUnderTest.matchers.toThrowError();
|
||||||
iframe = document.body.appendChild(document.createElement("iframe"));
|
iframe = document.body.appendChild(document.createElement('iframe'));
|
||||||
iframe.src = "about:blank";
|
iframe.src = 'about:blank';
|
||||||
var iframeDocument = iframe.contentWindow.document;
|
var iframeDocument = iframe.contentWindow.document;
|
||||||
|
|
||||||
if (iframeDocument.body) {
|
if (iframeDocument.body) {
|
||||||
iframeDocument.body.appendChild(iframeDocument.createElement("script"))
|
iframeDocument.body.appendChild(
|
||||||
.textContent = "function method() { throw new Error('foo'); }";
|
iframeDocument.createElement('script')
|
||||||
|
).textContent = "function method() { throw new Error('foo'); }";
|
||||||
} else {
|
} else {
|
||||||
// IE 10 and older
|
// IE 10 and older
|
||||||
iframeDocument.write("<html><head><script>function method() { throw new Error('foo'); }</script></head></html>");
|
iframeDocument.write(
|
||||||
|
"<html><head><script>function method() { throw new Error('foo'); }</script></head></html>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = matcher.compare(iframe.contentWindow.method);
|
var result = matcher.compare(iframe.contentWindow.method);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected function not to throw an Error, but it threw Error.");
|
expect(result.message).toEqual(
|
||||||
|
'Expected function not to throw an Error, but it threw Error.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails with the correct message if thrown is a falsy value", function() {
|
it('fails with the correct message if thrown is a falsy value', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
@@ -115,10 +122,12 @@ describe("toThrowError", function() {
|
|||||||
|
|
||||||
result = matcher.compare(fn);
|
result = matcher.compare(fn);
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw an Error, but it threw undefined.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function to throw an Error, but it threw undefined.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is a type of Error, but there is no expected error", function() {
|
it('passes if thrown is a type of Error, but there is no expected error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError();
|
throw new TypeError();
|
||||||
@@ -128,70 +137,80 @@ describe("toThrowError", function() {
|
|||||||
result = matcher.compare(fn);
|
result = matcher.compare(fn);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected function not to throw an Error, but it threw TypeError.");
|
expect(result.message).toEqual(
|
||||||
|
'Expected function not to throw an Error, but it threw TypeError.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is an Error and the expected is the same message", function() {
|
it('passes if thrown is an Error and the expected is the same message', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error('foo');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, "foo");
|
result = matcher.compare(fn, 'foo');
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw an exception with message 'foo'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function not to throw an exception with message 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if thrown is an Error and the expected is not the same message", function() {
|
it('fails if thrown is an Error and the expected is not the same message', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error('foo');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, "bar");
|
result = matcher.compare(fn, 'bar');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw an exception with message 'bar', but it threw an exception with message 'foo'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function to throw an exception with message 'bar', but it threw an exception with message 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() {
|
it('passes if thrown is an Error and the expected is a RegExp that matches the message', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("a long message");
|
throw new Error('a long message');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, /long/);
|
result = matcher.compare(fn, /long/);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw an exception with a message matching /long/.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function not to throw an exception with a message matching /long/.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() {
|
it('fails if thrown is an Error and the expected is a RegExp that does not match the message', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("a long message");
|
throw new Error('a long message');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, /foo/);
|
result = matcher.compare(fn, /foo/);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw an exception with a message matching /foo/, but it threw an exception with message 'a long message'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function to throw an exception with a message matching /foo/, but it threw an exception with message 'a long message'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is an Error and the expected the same Error", function() {
|
it('passes if thrown is an Error and the expected the same Error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
@@ -201,12 +220,14 @@ describe("toThrowError", function() {
|
|||||||
result = matcher.compare(fn, Error);
|
result = matcher.compare(fn, Error);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw Error.");
|
expect(result.message()).toEqual('Expected function not to throw Error.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is a custom error that takes arguments and the expected is the same error", function() {
|
it('passes if thrown is a custom error that takes arguments and the expected is the same error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
CustomError = function CustomError(arg) { arg.x },
|
CustomError = function CustomError(arg) {
|
||||||
|
arg.x;
|
||||||
|
},
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new CustomError({ x: 1 });
|
throw new CustomError({ x: 1 });
|
||||||
},
|
},
|
||||||
@@ -217,10 +238,12 @@ describe("toThrowError", function() {
|
|||||||
result = matcher.compare(fn, CustomError);
|
result = matcher.compare(fn, CustomError);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw CustomError.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function not to throw CustomError.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if thrown is an Error and the expected is a different Error", function() {
|
it('fails if thrown is an Error and the expected is a different Error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
@@ -230,94 +253,108 @@ describe("toThrowError", function() {
|
|||||||
result = matcher.compare(fn, TypeError);
|
result = matcher.compare(fn, TypeError);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw TypeError, but it threw Error.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function to throw TypeError, but it threw Error.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
|
it('passes if thrown is a type of Error and it is equal to the expected Error and message', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError('foo');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, TypeError, "foo");
|
result = matcher.compare(fn, TypeError, 'foo');
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw TypeError with message 'foo'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function not to throw TypeError with message 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is a custom error that takes arguments and it is equal to the expected custom error and message", function() {
|
it('passes if thrown is a custom error that takes arguments and it is equal to the expected custom error and message', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
CustomError = function CustomError(arg) { this.message = arg.message; },
|
CustomError = function CustomError(arg) {
|
||||||
|
this.message = arg.message;
|
||||||
|
},
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new CustomError({message: "foo"});
|
throw new CustomError({ message: 'foo' });
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
CustomError.prototype = new Error();
|
CustomError.prototype = new Error();
|
||||||
|
|
||||||
result = matcher.compare(fn, CustomError, "foo");
|
result = matcher.compare(fn, CustomError, 'foo');
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw CustomError with message 'foo'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function not to throw CustomError with message 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
it('fails if thrown is a type of Error and the expected is a different Error', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError('foo');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, TypeError, "bar");
|
result = matcher.compare(fn, TypeError, 'bar');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw TypeError with message 'bar', but it threw TypeError with message 'foo'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function to throw TypeError with message 'bar', but it threw TypeError with message 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if thrown is a type of Error and has the same type as the expected Error and the message matches the expected message", function() {
|
it('passes if thrown is a type of Error and has the same type as the expected Error and the message matches the expected message', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError('foo');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, TypeError, /foo/);
|
result = matcher.compare(fn, TypeError, /foo/);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw TypeError with a message matching /foo/.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function not to throw TypeError with a message matching /foo/.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
it('fails if thrown is a type of Error and the expected is a different Error', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError('foo');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, TypeError, /bar/);
|
result = matcher.compare(fn, TypeError, /bar/);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw TypeError with a message matching /bar/, but it threw TypeError with message 'foo'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function to throw TypeError with a message matching /bar/, but it threw TypeError with message 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
describe("toThrowMatching", function() {
|
describe('toThrowMatching', function() {
|
||||||
it("throws an error when the actual is not a function", function() {
|
it('throws an error when the actual is not a function', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowMatching();
|
var matcher = jasmineUnderTest.matchers.toThrowMatching();
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare({}, function() { return true; });
|
matcher.compare({}, function() {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}).toThrowError(/Actual is not a Function/);
|
}).toThrowError(/Actual is not a Function/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an error when the expected is not a function", function() {
|
it('throws an error when the expected is not a function', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error('foo');
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -18,20 +20,22 @@ describe("toThrowMatching", function() {
|
|||||||
}).toThrowError(/Predicate is not a Function/);
|
}).toThrowError(/Predicate is not a Function/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if actual does not throw at all", function() {
|
it('fails if actual does not throw at all', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, function() { return true; });
|
result = matcher.compare(fn, function() {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected function to throw an exception.");
|
expect(result.message).toEqual('Expected function to throw an exception.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails with the correct message if thrown is a falsy value", function() {
|
it('fails with the correct message if thrown is a falsy value', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowMatching({
|
var matcher = jasmineUnderTest.matchers.toThrowMatching({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
@@ -40,38 +44,50 @@ describe("toThrowMatching", function() {
|
|||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, function() { return false; });
|
result = matcher.compare(fn, function() {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw an exception matching a predicate, but it threw undefined.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function to throw an exception matching a predicate, but it threw undefined.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if the argument is a function that returns true when called with the error", function() {
|
it('passes if the argument is a function that returns true when called with the error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||||
predicate = function(e) { return e.message === "nope" },
|
predicate = function(e) {
|
||||||
|
return e.message === 'nope';
|
||||||
|
},
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("nope");
|
throw new TypeError('nope');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, predicate);
|
result = matcher.compare(fn, predicate);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message).toEqual("Expected function not to throw an exception matching a predicate.");
|
expect(result.message).toEqual(
|
||||||
|
'Expected function not to throw an exception matching a predicate.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if the argument is a function that returns false when called with the error", function() {
|
it('fails if the argument is a function that returns false when called with the error', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrowMatching({
|
var matcher = jasmineUnderTest.matchers.toThrowMatching({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
predicate = function(e) { return e.message === "oh no" },
|
predicate = function(e) {
|
||||||
|
return e.message === 'oh no';
|
||||||
|
},
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("nope");
|
throw new TypeError('nope');
|
||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, predicate);
|
result = matcher.compare(fn, predicate);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw an exception matching a predicate, but it threw TypeError with message 'nope'.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function to throw an exception matching a predicate, but it threw TypeError with message 'nope'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
describe("toThrow", function() {
|
describe('toThrow', function() {
|
||||||
|
it('throws an error when the actual is not a function', function() {
|
||||||
it("throws an error when the actual is not a function", function() {
|
|
||||||
var matcher = jasmineUnderTest.matchers.toThrow();
|
var matcher = jasmineUnderTest.matchers.toThrow();
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -9,7 +8,7 @@ describe("toThrow", function() {
|
|||||||
}).toThrowError(/Actual is not a Function/);
|
}).toThrowError(/Actual is not a Function/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if actual does not throw", function() {
|
it('fails if actual does not throw', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrow(),
|
var matcher = jasmineUnderTest.matchers.toThrow(),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
return true;
|
return true;
|
||||||
@@ -19,10 +18,10 @@ describe("toThrow", function() {
|
|||||||
result = matcher.compare(fn);
|
result = matcher.compare(fn);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message).toEqual("Expected function to throw an exception.");
|
expect(result.message).toEqual('Expected function to throw an exception.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if it throws but there is no expected", function() {
|
it('passes if it throws but there is no expected', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
@@ -36,10 +35,12 @@ describe("toThrow", function() {
|
|||||||
result = matcher.compare(fn);
|
result = matcher.compare(fn);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw, but it threw 5.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function not to throw, but it threw 5.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes even if what is thrown is falsy", function() {
|
it('passes even if what is thrown is falsy', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toThrow({
|
var matcher = jasmineUnderTest.matchers.toThrow({
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
}),
|
}),
|
||||||
@@ -50,10 +51,12 @@ describe("toThrow", function() {
|
|||||||
|
|
||||||
result = matcher.compare(fn);
|
result = matcher.compare(fn);
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw, but it threw undefined.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function not to throw, but it threw undefined.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes if what is thrown is equivalent to what is expected", function() {
|
it('passes if what is thrown is equivalent to what is expected', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
@@ -67,10 +70,10 @@ describe("toThrow", function() {
|
|||||||
result = matcher.compare(fn, 5);
|
result = matcher.compare(fn, 5);
|
||||||
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
expect(result.message()).toEqual("Expected function not to throw 5.");
|
expect(result.message()).toEqual('Expected function not to throw 5.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if what is thrown is not equivalent to what is expected", function() {
|
it('fails if what is thrown is not equivalent to what is expected', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
@@ -81,13 +84,15 @@ describe("toThrow", function() {
|
|||||||
},
|
},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(fn, "foo");
|
result = matcher.compare(fn, 'foo');
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw 'foo', but it threw 5.");
|
expect(result.message()).toEqual(
|
||||||
|
"Expected function to throw 'foo', but it threw 5."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails if what is thrown is not equivalent to undefined", function() {
|
it('fails if what is thrown is not equivalent to undefined', function() {
|
||||||
var matchersUtil = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
pp: jasmineUnderTest.makePrettyPrinter()
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
@@ -101,6 +106,8 @@ describe("toThrow", function() {
|
|||||||
result = matcher.compare(fn, void 0);
|
result = matcher.compare(fn, void 0);
|
||||||
|
|
||||||
expect(result.pass).toBe(false);
|
expect(result.pass).toBe(false);
|
||||||
expect(result.message()).toEqual("Expected function to throw undefined, but it threw 5.");
|
expect(result.message()).toEqual(
|
||||||
|
'Expected function to throw undefined, but it threw 5.'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
17
spec/helpers/checkForUrl.js
Normal file
17
spec/helpers/checkForUrl.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
|
(function(env) {
|
||||||
|
function hasUrlConstructor() {
|
||||||
|
try {
|
||||||
|
new URL('http://localhost/');
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
env.requireUrls = function() {
|
||||||
|
if (!hasUrlConstructor()) {
|
||||||
|
env.pending('Environment does not support URLs');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(jasmine.getEnv());
|
||||||
22
spec/helpers/generator.js
Normal file
22
spec/helpers/generator.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
(function(env) {
|
||||||
|
function getGeneratorFuncCtor() {
|
||||||
|
try {
|
||||||
|
eval('var func = function*() {}');
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.getPrototypeOf(func).constructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
env.makeGeneratorFunction = function(text) {
|
||||||
|
var GeneratorFunction = getGeneratorFuncCtor();
|
||||||
|
return new GeneratorFunction(text || '');
|
||||||
|
};
|
||||||
|
|
||||||
|
env.requireGeneratorFunctions = function() {
|
||||||
|
if (!getGeneratorFuncCtor()) {
|
||||||
|
env.pending('Environment does not support generator functions');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(jasmine.getEnv());
|
||||||
@@ -104,6 +104,7 @@ describe('HtmlReporter', function() {
|
|||||||
passedExpectations: [],
|
passedExpectations: [],
|
||||||
failedExpectations: []
|
failedExpectations: []
|
||||||
});
|
});
|
||||||
|
/* eslint-disable-next-line no-console */
|
||||||
expect(console.warn).toHaveBeenCalledWith(
|
expect(console.warn).toHaveBeenCalledWith(
|
||||||
"Spec 'Some Name' has no expectations."
|
"Spec 'Some Name' has no expectations."
|
||||||
);
|
);
|
||||||
@@ -118,6 +119,7 @@ describe('HtmlReporter', function() {
|
|||||||
passedExpectations: [],
|
passedExpectations: [],
|
||||||
failedExpectations: []
|
failedExpectations: []
|
||||||
});
|
});
|
||||||
|
/* eslint-disable-next-line no-console */
|
||||||
expect(console.error).toHaveBeenCalledWith(
|
expect(console.error).toHaveBeenCalledWith(
|
||||||
"Spec 'Some Name' has no expectations."
|
"Spec 'Some Name' has no expectations."
|
||||||
);
|
);
|
||||||
@@ -270,12 +272,14 @@ describe('HtmlReporter', function() {
|
|||||||
reporter.jasmineStarted({});
|
reporter.jasmineStarted({});
|
||||||
reporter.specDone({
|
reporter.specDone({
|
||||||
status: 'passed',
|
status: 'passed',
|
||||||
|
fullName: 'a spec with a deprecation',
|
||||||
deprecationWarnings: [{ message: 'spec deprecation' }],
|
deprecationWarnings: [{ message: 'spec deprecation' }],
|
||||||
failedExpectations: [],
|
failedExpectations: [],
|
||||||
passedExpectations: []
|
passedExpectations: []
|
||||||
});
|
});
|
||||||
reporter.suiteDone({
|
reporter.suiteDone({
|
||||||
status: 'passed',
|
status: 'passed',
|
||||||
|
fullName: 'a suite with a deprecation',
|
||||||
deprecationWarnings: [{ message: 'suite deprecation' }],
|
deprecationWarnings: [{ message: 'suite deprecation' }],
|
||||||
failedExpectations: []
|
failedExpectations: []
|
||||||
});
|
});
|
||||||
@@ -287,12 +291,17 @@ describe('HtmlReporter', function() {
|
|||||||
var alertBars = container.querySelectorAll('.jasmine-alert .jasmine-bar');
|
var alertBars = container.querySelectorAll('.jasmine-alert .jasmine-bar');
|
||||||
|
|
||||||
expect(alertBars.length).toEqual(4);
|
expect(alertBars.length).toEqual(4);
|
||||||
expect(alertBars[1].innerHTML).toMatch(/spec deprecation/);
|
expect(alertBars[1].innerHTML).toMatch(
|
||||||
|
/spec deprecation.*\(in spec: a spec with a deprecation\)/
|
||||||
|
);
|
||||||
expect(alertBars[1].getAttribute('class')).toEqual(
|
expect(alertBars[1].getAttribute('class')).toEqual(
|
||||||
'jasmine-bar jasmine-warning'
|
'jasmine-bar jasmine-warning'
|
||||||
);
|
);
|
||||||
expect(alertBars[2].innerHTML).toMatch(/suite deprecation/);
|
expect(alertBars[2].innerHTML).toMatch(
|
||||||
|
/suite deprecation.*\(in suite: a suite with a deprecation\)/
|
||||||
|
);
|
||||||
expect(alertBars[3].innerHTML).toMatch(/global deprecation/);
|
expect(alertBars[3].innerHTML).toMatch(/global deprecation/);
|
||||||
|
expect(alertBars[3].innerHTML).not.toMatch(/in /);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,13 @@ module.exports = {
|
|||||||
specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'],
|
specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'],
|
||||||
helpers: [
|
helpers: [
|
||||||
'helpers/asyncAwait.js',
|
'helpers/asyncAwait.js',
|
||||||
|
'helpers/generator.js',
|
||||||
'helpers/BrowserFlags.js',
|
'helpers/BrowserFlags.js',
|
||||||
'helpers/checkForMap.js',
|
'helpers/checkForMap.js',
|
||||||
'helpers/checkForSet.js',
|
'helpers/checkForSet.js',
|
||||||
'helpers/checkForSymbol.js',
|
'helpers/checkForSymbol.js',
|
||||||
'helpers/checkForTypedArrays.js',
|
'helpers/checkForTypedArrays.js',
|
||||||
|
'helpers/checkForUrl.js',
|
||||||
'helpers/domHelpers.js',
|
'helpers/domHelpers.js',
|
||||||
'helpers/integrationMatchers.js',
|
'helpers/integrationMatchers.js',
|
||||||
'helpers/promises.js',
|
'helpers/promises.js',
|
||||||
|
|||||||
@@ -6,10 +6,12 @@
|
|||||||
],
|
],
|
||||||
"helpers": [
|
"helpers": [
|
||||||
"helpers/asyncAwait.js",
|
"helpers/asyncAwait.js",
|
||||||
|
"helpers/generator.js",
|
||||||
"helpers/checkForMap.js",
|
"helpers/checkForMap.js",
|
||||||
"helpers/checkForSet.js",
|
"helpers/checkForSet.js",
|
||||||
"helpers/checkForSymbol.js",
|
"helpers/checkForSymbol.js",
|
||||||
"helpers/checkForTypedArrays.js",
|
"helpers/checkForTypedArrays.js",
|
||||||
|
"helpers/checkForUrl.js",
|
||||||
"helpers/domHelpers.js",
|
"helpers/domHelpers.js",
|
||||||
"helpers/integrationMatchers.js",
|
"helpers/integrationMatchers.js",
|
||||||
"helpers/promises.js",
|
"helpers/promises.js",
|
||||||
|
|||||||
@@ -424,6 +424,9 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
resources.customAsyncMatchers = j$.util.clone(
|
resources.customAsyncMatchers = j$.util.clone(
|
||||||
runnableResources[parentRunnableId].customAsyncMatchers
|
runnableResources[parentRunnableId].customAsyncMatchers
|
||||||
);
|
);
|
||||||
|
resources.customObjectFormatters = j$.util.clone(
|
||||||
|
runnableResources[parentRunnableId].customObjectFormatters
|
||||||
|
);
|
||||||
resources.defaultStrategyFn =
|
resources.defaultStrategyFn =
|
||||||
runnableResources[parentRunnableId].defaultStrategyFn;
|
runnableResources[parentRunnableId].defaultStrategyFn;
|
||||||
}
|
}
|
||||||
@@ -581,12 +584,22 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
this.deprecated = function(deprecation) {
|
this.deprecated = function(deprecation) {
|
||||||
var runnable = currentRunnable() || topSuite;
|
var runnable = currentRunnable() || topSuite;
|
||||||
|
var context;
|
||||||
|
|
||||||
|
if (runnable === topSuite) {
|
||||||
|
context = '';
|
||||||
|
} else if (runnable === currentSuite()) {
|
||||||
|
context = ' (in suite: ' + runnable.getFullName() + ')';
|
||||||
|
} else {
|
||||||
|
context = ' (in spec: ' + runnable.getFullName() + ')';
|
||||||
|
}
|
||||||
|
|
||||||
runnable.addDeprecationWarning(deprecation);
|
runnable.addDeprecationWarning(deprecation);
|
||||||
if (
|
if (
|
||||||
typeof console !== 'undefined' &&
|
typeof console !== 'undefined' &&
|
||||||
typeof console.error === 'function'
|
typeof console.error === 'function'
|
||||||
) {
|
) {
|
||||||
console.error('DEPRECATION:', deprecation);
|
console.error('DEPRECATION: ' + deprecation + context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -705,7 +718,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
queueRunnerFactory
|
queueRunnerFactory
|
||||||
);
|
);
|
||||||
|
|
||||||
this.execute = function(runnablesToRun) {
|
// Both params are optional.
|
||||||
|
this.execute = function(runnablesToRun, onComplete) {
|
||||||
installGlobalErrors();
|
installGlobalErrors();
|
||||||
|
|
||||||
if (!runnablesToRun) {
|
if (!runnablesToRun) {
|
||||||
@@ -813,7 +827,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
failedExpectations: topSuite.result.failedExpectations,
|
failedExpectations: topSuite.result.failedExpectations,
|
||||||
deprecationWarnings: topSuite.result.deprecationWarnings
|
deprecationWarnings: topSuite.result.deprecationWarnings
|
||||||
},
|
},
|
||||||
function() {}
|
function() {
|
||||||
|
if (onComplete) {
|
||||||
|
onComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
|
stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
|
||||||
|
|
||||||
stackTrace.frames.forEach(function(frame) {
|
stackTrace.frames.forEach(function(frame) {
|
||||||
if (frame.file && frame.file !== jasmineFile) {
|
if (frame.file !== jasmineFile) {
|
||||||
result.push(frame.raw);
|
result.push(frame.raw);
|
||||||
} else if (result[result.length - 1] !== jasmineMarker) {
|
} else if (result[result.length - 1] !== jasmineMarker) {
|
||||||
result.push(jasmineMarker);
|
result.push(jasmineMarker);
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
if (j$.isError_(event.reason)) {
|
if (j$.isError_(event.reason)) {
|
||||||
event.reason.jasmineMessage =
|
event.reason.jasmineMessage =
|
||||||
'Unhandled promise rejection: ' + event.reason;
|
'Unhandled promise rejection: ' + event.reason;
|
||||||
onerror(event.reason);
|
global.onerror(event.reason);
|
||||||
} else {
|
} else {
|
||||||
onerror('Unhandled promise rejection: ' + event.reason);
|
global.onerror('Unhandled promise rejection: ' + event.reason);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -96,7 +96,11 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
handlers.push(listener);
|
handlers.push(listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.popListener = function popListener() {
|
this.popListener = function popListener(listener) {
|
||||||
|
if (!listener) {
|
||||||
|
throw new Error('popListener expects a listener');
|
||||||
|
}
|
||||||
|
|
||||||
handlers.pop();
|
handlers.pop();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
getJasmineRequireObj().QueueRunner = function(j$) {
|
getJasmineRequireObj().QueueRunner = function(j$) {
|
||||||
|
var nextid = 1;
|
||||||
|
|
||||||
function StopExecutionError() {}
|
function StopExecutionError() {}
|
||||||
StopExecutionError.prototype = new Error();
|
StopExecutionError.prototype = new Error();
|
||||||
j$.StopExecutionError = StopExecutionError;
|
j$.StopExecutionError = StopExecutionError;
|
||||||
@@ -18,6 +20,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
function emptyFn() {}
|
function emptyFn() {}
|
||||||
|
|
||||||
function QueueRunner(attrs) {
|
function QueueRunner(attrs) {
|
||||||
|
this.id_ = nextid++;
|
||||||
var queueableFns = attrs.queueableFns || [];
|
var queueableFns = attrs.queueableFns || [];
|
||||||
this.queueableFns = queueableFns.concat(attrs.cleanupFns || []);
|
this.queueableFns = queueableFns.concat(attrs.cleanupFns || []);
|
||||||
this.firstCleanupIx = queueableFns.length;
|
this.firstCleanupIx = queueableFns.length;
|
||||||
@@ -120,7 +123,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}),
|
}),
|
||||||
errored = false,
|
errored = false,
|
||||||
queueableFn = self.queueableFns[iterativeIndex],
|
queueableFn = self.queueableFns[iterativeIndex],
|
||||||
timeoutId;
|
timeoutId,
|
||||||
|
maybeThenable;
|
||||||
|
|
||||||
next.fail = function nextFail() {
|
next.fail = function nextFail() {
|
||||||
self.fail.apply(null, arguments);
|
self.fail.apply(null, arguments);
|
||||||
@@ -148,7 +152,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (queueableFn.fn.length === 0) {
|
if (queueableFn.fn.length === 0) {
|
||||||
var maybeThenable = queueableFn.fn.call(self.userContext);
|
maybeThenable = queueableFn.fn.call(self.userContext);
|
||||||
|
|
||||||
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
||||||
maybeThenable.then(next, onPromiseRejection);
|
maybeThenable.then(next, onPromiseRejection);
|
||||||
@@ -156,7 +160,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
return { completedSynchronously: false };
|
return { completedSynchronously: false };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
queueableFn.fn.call(self.userContext, next);
|
maybeThenable = queueableFn.fn.call(self.userContext, next);
|
||||||
|
this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable);
|
||||||
completedSynchronously = false;
|
completedSynchronously = false;
|
||||||
return { completedSynchronously: false };
|
return { completedSynchronously: false };
|
||||||
}
|
}
|
||||||
@@ -209,5 +214,28 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
||||||
|
if (retval && j$.isFunction_(retval.then)) {
|
||||||
|
// Issue a warning that matches the user's code
|
||||||
|
if (j$.isAsyncFunction_(fn)) {
|
||||||
|
this.deprecated(
|
||||||
|
'An asynchronous before/it/after ' +
|
||||||
|
'function was defined with the async keyword but also took a ' +
|
||||||
|
'done callback. This is not supported and will stop working in' +
|
||||||
|
' the future. Either remove the done callback (recommended) or ' +
|
||||||
|
'remove the async keyword.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.deprecated(
|
||||||
|
'An asynchronous before/it/after ' +
|
||||||
|
'function took a done callback but also returned a promise. ' +
|
||||||
|
'This is not supported and will stop working in the future. ' +
|
||||||
|
'Either remove the done callback (recommended) or change the ' +
|
||||||
|
'function to not return a promise.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return QueueRunner;
|
return QueueRunner;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
|||||||
var properties = normalizeKeyValues(propertyNames);
|
var properties = normalizeKeyValues(propertyNames);
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
descriptor = {
|
descriptor = {
|
||||||
|
enumerable: true,
|
||||||
get: self.createSpy(baseName + '.' + properties[i][0] + '.get'),
|
get: self.createSpy(baseName + '.' + properties[i][0] + '.get'),
|
||||||
set: self.createSpy(baseName + '.' + properties[i][0] + '.set')
|
set: self.createSpy(baseName + '.' + properties[i][0] + '.set')
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -168,7 +168,13 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @param {Function} fn The function to invoke with the passed parameters.
|
* @param {Function} fn The function to invoke with the passed parameters.
|
||||||
*/
|
*/
|
||||||
SpyStrategy.prototype.callFake = function(fn) {
|
SpyStrategy.prototype.callFake = function(fn) {
|
||||||
if (!(j$.isFunction_(fn) || j$.isAsyncFunction_(fn))) {
|
if (
|
||||||
|
!(
|
||||||
|
j$.isFunction_(fn) ||
|
||||||
|
j$.isAsyncFunction_(fn) ||
|
||||||
|
j$.isGeneratorFunction_(fn)
|
||||||
|
)
|
||||||
|
) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Argument passed to callFake should be a function, got ' + fn
|
'Argument passed to callFake should be a function, got ' + fn
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ getJasmineRequireObj().asymmetricEqualityTesterArgCompatShim = function(j$) {
|
|||||||
|
|
||||||
for (i = 0; i < props.length; i++) {
|
for (i = 0; i < props.length; i++) {
|
||||||
k = props[i];
|
k = props[i];
|
||||||
if (k !== 'length') {
|
// Skip length (dealt with above), and anything that collides with
|
||||||
|
// MatchesUtil e.g. an Array.prototype.contains method added by user code
|
||||||
|
if (k !== 'length' && !self[k]) {
|
||||||
copy(self, Array.prototype, k);
|
copy(self, Array.prototype, k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
getJasmineRequireObj().Any = function(j$) {
|
getJasmineRequireObj().Any = function(j$) {
|
||||||
|
|
||||||
function Any(expectedObject) {
|
function Any(expectedObject) {
|
||||||
if (typeof expectedObject === 'undefined') {
|
if (typeof expectedObject === 'undefined') {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
'jasmine.any() expects to be passed a constructor function. ' +
|
'jasmine.any() expects to be passed a constructor function. ' +
|
||||||
'Please pass one or use jasmine.anything() to match any object.'
|
'Please pass one or use jasmine.anything() to match any object.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.expectedObject = expectedObject;
|
this.expectedObject = expectedObject;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
getJasmineRequireObj().Anything = function(j$) {
|
getJasmineRequireObj().Anything = function(j$) {
|
||||||
|
|
||||||
function Anything() {}
|
function Anything() {}
|
||||||
|
|
||||||
Anything.prototype.asymmetricMatch = function(other) {
|
Anything.prototype.asymmetricMatch = function(other) {
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
|||||||
|
|
||||||
ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
|
ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
|
||||||
if (!j$.isArray_(this.sample)) {
|
if (!j$.isArray_(this.sample)) {
|
||||||
throw new Error('You must provide an array to arrayContaining, not ' + j$.pp(this.sample) + '.');
|
throw new Error(
|
||||||
|
'You must provide an array to arrayContaining, not ' +
|
||||||
|
j$.pp(this.sample) +
|
||||||
|
'.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the actual parameter is not an array, we can fail immediately, since it couldn't
|
// If the actual parameter is not an array, we can fail immediately, since it couldn't
|
||||||
@@ -25,8 +29,8 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayContaining.prototype.jasmineToString = function (pp) {
|
ArrayContaining.prototype.jasmineToString = function(pp) {
|
||||||
return '<jasmine.arrayContaining(' + pp(this.sample) +')>';
|
return '<jasmine.arrayContaining(' + pp(this.sample) + ')>';
|
||||||
};
|
};
|
||||||
|
|
||||||
return ArrayContaining;
|
return ArrayContaining;
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
getJasmineRequireObj().ArrayWithExactContents = function(j$) {
|
getJasmineRequireObj().ArrayWithExactContents = function(j$) {
|
||||||
|
|
||||||
function ArrayWithExactContents(sample) {
|
function ArrayWithExactContents(sample) {
|
||||||
this.sample = sample;
|
this.sample = sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayWithExactContents.prototype.asymmetricMatch = function(other, matchersUtil) {
|
ArrayWithExactContents.prototype.asymmetricMatch = function(
|
||||||
|
other,
|
||||||
|
matchersUtil
|
||||||
|
) {
|
||||||
if (!j$.isArray_(this.sample)) {
|
if (!j$.isArray_(this.sample)) {
|
||||||
throw new Error('You must provide an array to arrayWithExactContents, not ' + j$.pp(this.sample) + '.');
|
throw new Error(
|
||||||
|
'You must provide an array to arrayWithExactContents, not ' +
|
||||||
|
j$.pp(this.sample) +
|
||||||
|
'.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sample.length !== other.length) {
|
if (this.sample.length !== other.length) {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
getJasmineRequireObj().Empty = function (j$) {
|
getJasmineRequireObj().Empty = function(j$) {
|
||||||
|
|
||||||
function Empty() {}
|
function Empty() {}
|
||||||
|
|
||||||
Empty.prototype.asymmetricMatch = function (other) {
|
Empty.prototype.asymmetricMatch = function(other) {
|
||||||
if (j$.isString_(other) || j$.isArray_(other) || j$.isTypedArray_(other)) {
|
if (j$.isString_(other) || j$.isArray_(other) || j$.isTypedArray_(other)) {
|
||||||
return other.length === 0;
|
return other.length === 0;
|
||||||
}
|
}
|
||||||
@@ -17,7 +16,7 @@ getJasmineRequireObj().Empty = function (j$) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Empty.prototype.jasmineToString = function () {
|
Empty.prototype.jasmineToString = function() {
|
||||||
return '<jasmine.empty>';
|
return '<jasmine.empty>';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
getJasmineRequireObj().Falsy = function(j$) {
|
getJasmineRequireObj().Falsy = function(j$) {
|
||||||
|
|
||||||
function Falsy() {}
|
function Falsy() {}
|
||||||
|
|
||||||
Falsy.prototype.asymmetricMatch = function(other) {
|
Falsy.prototype.asymmetricMatch = function(other) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user