Compare commits
102 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d51da18808 | ||
|
|
6f3e85f755 | ||
|
|
d04b813cab | ||
|
|
70c416d5c9 | ||
|
|
226d3ba939 | ||
|
|
aa6cc31057 | ||
|
|
f8ae3eaeaa | ||
|
|
db6aa8f3f8 | ||
|
|
4e2f703615 | ||
|
|
ba2aae63be | ||
|
|
fb23277367 | ||
|
|
8cd4873e48 | ||
|
|
11b63e4e3e | ||
|
|
b3ab9fad9d | ||
|
|
13b967b59c | ||
|
|
0253d4fb71 | ||
|
|
44875673c1 | ||
|
|
3943cc2ddb | ||
|
|
f4753ac0a4 | ||
|
|
ce2161ca32 | ||
|
|
17eda7a2de | ||
|
|
7119720fc7 | ||
|
|
f4e192a428 | ||
|
|
45ad7fd13c | ||
|
|
0cb304131f | ||
|
|
8a731e17a7 | ||
|
|
7416c176a7 | ||
|
|
0f6ebaa784 | ||
|
|
f14f620e15 | ||
|
|
e94e6c5b75 | ||
|
|
f90d9943fe | ||
|
|
8991b1bba3 | ||
|
|
78c3a007ad | ||
|
|
30b31096b8 | ||
|
|
2b318a6154 | ||
|
|
41293714fd | ||
|
|
08779f2657 | ||
|
|
76a99aef86 | ||
|
|
6b213a958d | ||
|
|
9a7dfb15d2 | ||
|
|
ec9904bf52 | ||
|
|
bcc28d7063 | ||
|
|
79d55216fc | ||
|
|
7e940542f8 | ||
|
|
ec3ebcb7bb | ||
|
|
c521b4d47c | ||
|
|
66fe69a149 | ||
|
|
e13fd13529 | ||
|
|
f1eac6fb04 | ||
|
|
6440ca434d | ||
|
|
93ad31e0af | ||
|
|
a6a9550d1e | ||
|
|
6c68715554 | ||
|
|
258d55469e | ||
|
|
5096d9af4e | ||
|
|
3be797c8d8 | ||
|
|
d10e8c2ddf | ||
|
|
c2ada1af95 | ||
|
|
ea3dd9dffc | ||
|
|
d41139fea2 | ||
|
|
873d1c2945 | ||
|
|
25816a6e77 | ||
|
|
1f23f1e4d2 | ||
|
|
dec67bd535 | ||
|
|
83b336d9d1 | ||
|
|
be3c8275d4 | ||
|
|
bf4694333c | ||
|
|
9febe3159d | ||
|
|
5e98ee951c | ||
|
|
fd5b9ce1ae | ||
|
|
58c63e98bb | ||
|
|
7f392d188e | ||
|
|
6baf3a9270 | ||
|
|
1545112744 | ||
|
|
8a5216401f | ||
|
|
fffb8abb24 | ||
|
|
17e9088ac5 | ||
|
|
d19ffcc231 | ||
|
|
0b4a9edff8 | ||
|
|
e02c24d151 | ||
|
|
913ad50a76 | ||
|
|
c395c525dc | ||
|
|
12fefa4b3d | ||
|
|
88b98277bc | ||
|
|
4eded6ab61 | ||
|
|
6c766b7785 | ||
|
|
13ff1e037e | ||
|
|
a00f995c68 | ||
|
|
795a80ec66 | ||
|
|
3d1a96e020 | ||
|
|
076093c16c | ||
|
|
8d53f4d202 | ||
|
|
71631a6529 | ||
|
|
bed56a76f8 | ||
|
|
97fe2e7c95 | ||
|
|
ef3f127d27 | ||
|
|
472f61ab37 | ||
|
|
10dbf8be98 | ||
|
|
a497d0942a | ||
|
|
9a41154e3b | ||
|
|
fc3eb0fbd8 | ||
|
|
223924a7a1 |
4
.github/CONTRIBUTING.md
vendored
4
.github/CONTRIBUTING.md
vendored
@@ -17,7 +17,7 @@ git clone git@github.com:yourUserName/jasmine.git # Clone your fork
|
|||||||
cd jasmine # Change directory
|
cd jasmine # Change directory
|
||||||
git remote add upstream https://github.com/jasmine/jasmine.git # Assign original repository to a remote named 'upstream'
|
git remote add upstream https://github.com/jasmine/jasmine.git # Assign original repository to a remote named 'upstream'
|
||||||
git fetch upstream # Fetch changes not present in your local repository
|
git fetch upstream # Fetch changes not present in your local repository
|
||||||
git merge upstream/master # Sync local master with upstream repository
|
git merge upstream/main # Sync local main with upstream repository
|
||||||
git checkout -b my-new-feature # Create your feature branch
|
git checkout -b my-new-feature # Create your feature branch
|
||||||
git commit -am 'Add some feature' # Commit your changes
|
git commit -am 'Add some feature' # Commit your changes
|
||||||
git push origin my-new-feature # Push to the branch
|
git push origin my-new-feature # Push to the branch
|
||||||
@@ -121,7 +121,7 @@ The easiest way to run the tests in **Internet Explorer** is to run a VM that ha
|
|||||||
1. Build `jasmine.js` with `npm run build` and run all specs again - this ensures that your changes self-test well
|
1. Build `jasmine.js` with `npm run build` and run all specs again - this ensures that your changes self-test well
|
||||||
1. Revert your changes to `jasmine.js` and `jasmine-html.js`
|
1. Revert your changes to `jasmine.js` and `jasmine-html.js`
|
||||||
* We do this because `jasmine.js` and `jasmine-html.js` are auto-generated (as you've seen in the previous steps) and accepting multiple pull requests when this auto-generated file changes causes lots of headaches
|
* We do this because `jasmine.js` and `jasmine-html.js` are auto-generated (as you've seen in the previous steps) and accepting multiple pull requests when this auto-generated file changes causes lots of headaches
|
||||||
* When we accept your pull request, we will generate these files as a separate commit and merge the entire branch into master
|
* When we accept your pull request, we will generate these files as a separate commit and merge the entire branch into main
|
||||||
|
|
||||||
Note that we use Travis for Continuous Integration. We only accept green pull requests.
|
Note that we use Travis for Continuous Integration. We only accept green pull requests.
|
||||||
|
|
||||||
|
|||||||
62
.travis.yml
62
.travis.yml
@@ -1,8 +1,5 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js: 10
|
||||||
- "10"
|
|
||||||
- "8"
|
|
||||||
- "12"
|
|
||||||
|
|
||||||
script: $TEST_COMMAND
|
script: $TEST_COMMAND
|
||||||
|
|
||||||
@@ -12,36 +9,15 @@ env:
|
|||||||
- TEST_COMMAND="bash travis-core-script.sh"
|
- TEST_COMMAND="bash travis-core-script.sh"
|
||||||
- secure: WSPWhlnC4mWSnSPquX+m1/BCu5ch5NygkaHuM2Nea7lD8oS3XLX8QncZZAsQ4lnNfqoDDuBOizG0AESiqNvE4y6x5qvLLTS6q+ce255ZEMZ71TBdZgDEEvGMEjOPPsVXiXyTQOP1lwOPlrbZvaPgWV7e11KIBab6DfFcQpnvDgo=
|
- secure: WSPWhlnC4mWSnSPquX+m1/BCu5ch5NygkaHuM2Nea7lD8oS3XLX8QncZZAsQ4lnNfqoDDuBOizG0AESiqNvE4y6x5qvLLTS6q+ce255ZEMZ71TBdZgDEEvGMEjOPPsVXiXyTQOP1lwOPlrbZvaPgWV7e11KIBab6DfFcQpnvDgo=
|
||||||
- secure: SW7CJhZnwaNT749Gdnhvqb5rbXlAOsygUAzh9qhtyvbqXKkmJdBIEsO01YF6pbju1X2twE9JvWCOxeZju43NgQChJlPsGbjY2j3k/TdQeTAJesQe2K7ytwghunI30gjEovtRH0T3w1EmcKPH8yj5eBIcB2OYoJHx8KEC7e68q1g=
|
- secure: SW7CJhZnwaNT749Gdnhvqb5rbXlAOsygUAzh9qhtyvbqXKkmJdBIEsO01YF6pbju1X2twE9JvWCOxeZju43NgQChJlPsGbjY2j3k/TdQeTAJesQe2K7ytwghunI30gjEovtRH0T3w1EmcKPH8yj5eBIcB2OYoJHx8KEC7e68q1g=
|
||||||
matrix:
|
|
||||||
- TEST_COMMAND="npm test"
|
|
||||||
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- env: JASMINE_BROWSER="firefox" SAUCE_BROWSER_VERSION='' SAUCE_OS="Linux"
|
- node_js: "10"
|
||||||
if: type != pull_request
|
env: JASMINE_LONG_PROPERTY_TESTS="y" TEST_COMMAND="npm test"
|
||||||
addons:
|
- node_js: "12"
|
||||||
sauce_connect: true
|
env: TEST_COMMAND="npm test"
|
||||||
- env: JASMINE_BROWSER="chrome" SAUCE_BROWSER_VERSION='' SAUCE_OS="Linux"
|
- node_js: "8"
|
||||||
if: type != pull_request
|
env: TEST_COMMAND="npm test"
|
||||||
addons:
|
|
||||||
sauce_connect: true
|
|
||||||
- env: JASMINE_BROWSER="safari" SAUCE_BROWSER_VERSION="10" SAUCE_OS="OS X 10.12"
|
|
||||||
if: type != pull_request
|
|
||||||
addons:
|
|
||||||
sauce_connect: true
|
|
||||||
- env: JASMINE_BROWSER="safari" SAUCE_BROWSER_VERSION="9" SAUCE_OS="OS X 10.11"
|
|
||||||
if: type != pull_request
|
|
||||||
addons:
|
|
||||||
sauce_connect: true
|
|
||||||
- env: JASMINE_BROWSER="safari" SAUCE_BROWSER_VERSION="8" SAUCE_OS="OS X 10.10"
|
|
||||||
if: type != pull_request
|
|
||||||
addons:
|
|
||||||
sauce_connect: true
|
|
||||||
- env: JASMINE_BROWSER="MicrosoftEdge" SAUCE_BROWSER_VERSION="15" SAUCE_OS="Windows 10"
|
|
||||||
if: type != pull_request
|
|
||||||
addons:
|
|
||||||
sauce_connect: true
|
|
||||||
- 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
|
||||||
addons:
|
addons:
|
||||||
@@ -50,3 +26,27 @@ matrix:
|
|||||||
if: type != pull_request
|
if: type != pull_request
|
||||||
addons:
|
addons:
|
||||||
sauce_connect: true
|
sauce_connect: true
|
||||||
|
- env: JASMINE_BROWSER="firefox" SAUCE_BROWSER_VERSION='' SAUCE_OS="Windows 10"
|
||||||
|
if: type != pull_request
|
||||||
|
addons:
|
||||||
|
sauce_connect: true
|
||||||
|
- env: JASMINE_BROWSER="firefox" SAUCE_BROWSER_VERSION='68' SAUCE_OS="Windows 10"
|
||||||
|
if: type != pull_request
|
||||||
|
addons:
|
||||||
|
sauce_connect: true
|
||||||
|
- env: JASMINE_BROWSER="chrome" SAUCE_BROWSER_VERSION='' SAUCE_OS="Windows 10"
|
||||||
|
if: type != pull_request
|
||||||
|
addons:
|
||||||
|
sauce_connect: true
|
||||||
|
- env: JASMINE_BROWSER="safari" SAUCE_BROWSER_VERSION="13" SAUCE_OS="OS X 10.13"
|
||||||
|
if: type != pull_request
|
||||||
|
addons:
|
||||||
|
sauce_connect: true
|
||||||
|
- env: JASMINE_BROWSER="safari" SAUCE_BROWSER_VERSION="8" SAUCE_OS="OS X 10.10"
|
||||||
|
if: type != pull_request
|
||||||
|
addons:
|
||||||
|
sauce_connect: true
|
||||||
|
- env: JASMINE_BROWSER="MicrosoftEdge" SAUCE_BROWSER_VERSION="" SAUCE_OS="Windows 10"
|
||||||
|
if: type != pull_request
|
||||||
|
addons:
|
||||||
|
sauce_connect: true
|
||||||
|
|||||||
49
README.md
49
README.md
@@ -1,6 +1,6 @@
|
|||||||
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/master/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.org/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)
|
||||||
|
|
||||||
@@ -9,35 +9,35 @@
|
|||||||
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
||||||
|
|
||||||
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
|
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
|
||||||
For a quick start guide of Jasmine, see the beginning of [http://jasmine.github.io/edge/introduction.html](http://jasmine.github.io/edge/introduction.html)
|
For a quick start guide of Jasmine, see the beginning of [http://jasmine.github.io/edge/introduction.html](http://jasmine.github.io/edge/introduction.html).
|
||||||
|
|
||||||
Upgrading from Jasmine 2.x? Check out the [3.0 release notes](https://github.com/jasmine/jasmine/blob/v3.0.0/release_notes/3.0.md) for a list of what's new (including breaking changes).
|
Upgrading from Jasmine 2.x? Check out the [3.0 release notes](https://github.com/jasmine/jasmine/blob/v3.0.0/release_notes/3.0.md) for a list of what's new (including breaking changes).
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Please read the [contributors' guide](https://github.com/jasmine/jasmine/blob/master/.github/CONTRIBUTING.md)
|
Please read the [contributors' guide](https://github.com/jasmine/jasmine/blob/main/.github/CONTRIBUTING.md).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
For the Jasmine NPM module:<br>
|
For the Jasmine NPM module:<br>
|
||||||
[https://github.com/jasmine/jasmine-npm](https://github.com/jasmine/jasmine-npm)
|
[https://github.com/jasmine/jasmine-npm](https://github.com/jasmine/jasmine-npm).
|
||||||
|
|
||||||
For the Jasmine Ruby Gem:<br>
|
For the Jasmine Ruby Gem:<br>
|
||||||
[https://github.com/jasmine/jasmine-gem](https://github.com/jasmine/jasmine-gem)
|
[https://github.com/jasmine/jasmine-gem](https://github.com/jasmine/jasmine-gem).
|
||||||
|
|
||||||
For the Jasmine Python Egg:<br>
|
For the Jasmine Python Egg:<br>
|
||||||
[https://github.com/jasmine/jasmine-py](https://github.com/jasmine/jasmine-py)
|
[https://github.com/jasmine/jasmine-py](https://github.com/jasmine/jasmine-py).
|
||||||
|
|
||||||
For the Jasmine headless browser gulp plugin:<br>
|
For the Jasmine headless browser gulp plugin:<br>
|
||||||
[https://github.com/jasmine/gulp-jasmine-browser](https://github.com/jasmine/gulp-jasmine-browser)
|
[https://github.com/jasmine/gulp-jasmine-browser](https://github.com/jasmine/gulp-jasmine-browser).
|
||||||
|
|
||||||
To install Jasmine standalone on your local box (where **_{#.#.#}_** below is substituted by the release number downloaded):
|
To install Jasmine standalone on your local box (where **_{#.#.#}_** below is substituted by the release number downloaded):
|
||||||
|
|
||||||
* Download the standalone distribution for your desired release from the [releases page](https://github.com/jasmine/jasmine/releases)
|
* Download the standalone distribution for your desired release from the [releases page](https://github.com/jasmine/jasmine/releases).
|
||||||
* Create a Jasmine directory in your project - `mkdir my-project/jasmine`
|
* Create a Jasmine directory in your project. - `mkdir my-project/jasmine`
|
||||||
* Move the dist to your project directory - `mv jasmine/dist/jasmine-standalone-{#.#.#}.zip my-project/jasmine`
|
* Move the dist to your project directory. - `mv jasmine/dist/jasmine-standalone-{#.#.#}.zip my-project/jasmine`
|
||||||
* Change directory - `cd my-project/jasmine`
|
* Change directory. - `cd my-project/jasmine`
|
||||||
* Unzip the dist - `unzip jasmine-standalone-{#.#.#}.zip`
|
* Unzip the dist. - `unzip jasmine-standalone-{#.#.#}.zip`
|
||||||
|
|
||||||
Add the following to your HTML file:
|
Add the following to your HTML file:
|
||||||
|
|
||||||
@@ -52,16 +52,27 @@ Add the following to your HTML file:
|
|||||||
|
|
||||||
## Supported environments
|
## Supported environments
|
||||||
|
|
||||||
Jasmine tests itself across many browsers (Safari, Chrome, Firefox, Microsoft Edge, and new Internet Explorer) as well as nodejs. To see the exact version tests are run against look at our [.travis.yml](https://github.com/jasmine/jasmine/blob/master/.travis.yml)
|
Jasmine tests itself across many browsers (Safari, Chrome, Firefox, Microsoft Edge, and Internet Explorer) as well as nodejs.
|
||||||
|
|
||||||
[](https://saucelabs.com/u/jasmine-js)
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 8, 10, 12 |
|
||||||
|
| Safari | 8-13 |
|
||||||
|
| Chrome | Evergreen |
|
||||||
|
| Firefox | Evergreen, 68 |
|
||||||
|
| Edge | Evergreen |
|
||||||
|
| Internet Explorer | 10, 11 |
|
||||||
|
|
||||||
|
For evergreen browsers, each version of Jasmine is tested against the version of the browser that is available to us
|
||||||
|
at the time of release. Other browsers, as well as older & newer versions of some supported browsers, are likely to work.
|
||||||
|
However, Jasmine isn't tested against them and they aren't actively supported.
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
* Search past discussions: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js)
|
* Search past discussions: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js).
|
||||||
* Send an email to the list: [jasmine-js@googlegroups.com](mailto:jasmine-js@googlegroups.com)
|
* Send an email to the list: [jasmine-js@googlegroups.com](mailto:jasmine-js@googlegroups.com).
|
||||||
* View the project backlog at Pivotal Tracker: [http://www.pivotaltracker.com/projects/10606](http://www.pivotaltracker.com/projects/10606)
|
* View the project backlog at Pivotal Tracker: [http://www.pivotaltracker.com/projects/10606](http://www.pivotaltracker.com/projects/10606).
|
||||||
* Follow us on Twitter: [@JasmineBDD](http://twitter.com/JasmineBDD)
|
* Follow us on Twitter: [@JasmineBDD](http://twitter.com/JasmineBDD).
|
||||||
|
|
||||||
## Maintainers
|
## Maintainers
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Follow the instructions in `CONTRIBUTING.md` during development.
|
|||||||
|
|
||||||
### Git Rules
|
### Git Rules
|
||||||
|
|
||||||
Please attempt to keep commits to `master` small, but cohesive. If a feature is contained in a bunch of small commits (e.g., it has several wip commits or small work), please squash them when pushing to `master`.
|
Please attempt to keep commits to `main` small, but cohesive. If a feature is contained in a bunch of small commits (e.g., it has several wip commits or small work), please squash them when pushing to `main`.
|
||||||
|
|
||||||
### Version
|
### Version
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2019 Pivotal Labs
|
Copyright (c) 2008-2020 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
|
||||||
@@ -31,13 +31,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Require & Instantiate
|
* ## Require & Instantiate
|
||||||
*
|
*
|
||||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||||
*/
|
*/
|
||||||
window.jasmine = jasmineRequire.core(jasmineRequire);
|
var jasmine = jasmineRequire.core(jasmineRequire),
|
||||||
|
global = jasmine.getGlobal();
|
||||||
|
global.jasmine = jasmine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
||||||
@@ -59,7 +62,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
/**
|
/**
|
||||||
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||||
*/
|
*/
|
||||||
extend(window, jasmineInterface);
|
extend(global, jasmineInterface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Runner Parameters
|
* ## Runner Parameters
|
||||||
|
|||||||
@@ -9,13 +9,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Require & Instantiate
|
* ## Require & Instantiate
|
||||||
*
|
*
|
||||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||||
*/
|
*/
|
||||||
window.jasmine = jasmineRequire.core(jasmineRequire);
|
var jasmine = jasmineRequire.core(jasmineRequire),
|
||||||
|
global = jasmine.getGlobal();
|
||||||
|
global.jasmine = jasmine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
||||||
@@ -37,7 +40,7 @@
|
|||||||
/**
|
/**
|
||||||
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||||
*/
|
*/
|
||||||
extend(window, jasmineInterface);
|
extend(global, jasmineInterface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Runner Parameters
|
* ## Runner Parameters
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ Player.prototype.resume = function() {
|
|||||||
|
|
||||||
Player.prototype.makeFavorite = function() {
|
Player.prototype.makeFavorite = function() {
|
||||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ function Song() {
|
|||||||
Song.prototype.persistFavoriteStatus = function(value) {
|
Song.prototype.persistFavoriteStatus = function(value) {
|
||||||
// something complicated
|
// something complicated
|
||||||
throw new Error("not yet implemented");
|
throw new Error("not yet implemented");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2019 Pivotal Labs
|
Copyright (c) 2008-2020 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
|
||||||
@@ -20,6 +20,8 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
jasmineRequire.html = function(j$) {
|
jasmineRequire.html = function(j$) {
|
||||||
j$.ResultsNode = jasmineRequire.ResultsNode();
|
j$.ResultsNode = jasmineRequire.ResultsNode();
|
||||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||||
@@ -350,9 +352,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
find('.jasmine-failures-menu').onclick = function() {
|
find('.jasmine-failures-menu').onclick = function() {
|
||||||
setMenuModeTo('jasmine-failure-list');
|
setMenuModeTo('jasmine-failure-list');
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
find('.jasmine-spec-list-menu').onclick = function() {
|
find('.jasmine-spec-list-menu').onclick = function() {
|
||||||
setMenuModeTo('jasmine-spec-list');
|
setMenuModeTo('jasmine-spec-list');
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
setMenuModeTo('jasmine-failure-list');
|
setMenuModeTo('jasmine-failure-list');
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2019 Pivotal Labs
|
Copyright (c) 2008-2020 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.5.0"
|
VERSION = "3.6.0"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
30
package.json
30
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "jasmine-core",
|
"name": "jasmine-core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "3.5.0",
|
"version": "3.6.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/jasmine/jasmine.git"
|
"url": "https://github.com/jasmine/jasmine.git"
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"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",
|
||||||
@@ -28,8 +28,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "^6.0.0",
|
"acorn": "^6.0.0",
|
||||||
"ejs": "^2.5.5",
|
"ejs": "^2.5.5",
|
||||||
"eslint": "^5.16.0",
|
"eslint": "^6.8.0",
|
||||||
|
"eslint-plugin-compat": "^3.8.0",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
|
"fast-check": "^1.21.0",
|
||||||
"fast-glob": "^2.2.6",
|
"fast-glob": "^2.2.6",
|
||||||
"grunt": "^1.0.4",
|
"grunt": "^1.0.4",
|
||||||
"grunt-cli": "^1.3.2",
|
"grunt-cli": "^1.3.2",
|
||||||
@@ -38,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": "0.3.0",
|
"jasmine-browser-runner": "github:jasmine/jasmine-browser",
|
||||||
"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",
|
||||||
@@ -51,6 +53,12 @@
|
|||||||
"singleQuote": true
|
"singleQuote": true
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"plugin:compat/recommended"
|
||||||
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 5
|
||||||
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"quotes": [
|
"quotes": [
|
||||||
"error",
|
"error",
|
||||||
@@ -66,10 +74,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"block-spacing": "error",
|
"block-spacing": "error",
|
||||||
"comma-dangle": [
|
|
||||||
"error",
|
|
||||||
"never"
|
|
||||||
],
|
|
||||||
"func-call-spacing": [
|
"func-call-spacing": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
@@ -84,5 +88,13 @@
|
|||||||
],
|
],
|
||||||
"space-before-blocks": "error"
|
"space-before-blocks": "error"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"Safari >= 8",
|
||||||
|
"last 2 Chrome versions",
|
||||||
|
"last 2 Firefox versions",
|
||||||
|
"Firefox 68",
|
||||||
|
"last 2 Edge versions",
|
||||||
|
"IE >= 10"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
146
release_notes/3.6.0.md
Normal file
146
release_notes/3.6.0.md
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
# Jasmine Core 3.6 Release Notes
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This is a maintenance release of Jasmine with a number of new features and fixes.
|
||||||
|
|
||||||
|
## Highlights
|
||||||
|
|
||||||
|
* Added support for custom object formatters
|
||||||
|
* Allows customizing how an object is stringified in matcher failure messages
|
||||||
|
* [Tutorial](https://jasmine.github.io/tutorials/custom_object_formatter)
|
||||||
|
* [API reference](https://jasmine.github.io/api/3.6/jasmine.html#.addCustomObjectFormatter)
|
||||||
|
|
||||||
|
* Don't require matchers and asymmetric equality testers to pass custom object formatters back to Jasmine
|
||||||
|
- Supports custom object formatters.
|
||||||
|
- Makes it easier to write high quality matchers and asymmetric equality testers.
|
||||||
|
- The old API will still work until 4.0.
|
||||||
|
|
||||||
|
* Properly import jasmineRequire object before using
|
||||||
|
- Improves compatibility with Webpack
|
||||||
|
- Merges [#1766](https://github.com/jasmine/jasmine/pull/1766) from @amilligan
|
||||||
|
|
||||||
|
* Added a toHaveBeenCalledOnceWith matcher
|
||||||
|
- Merges [#1801](https://github.com/jasmine/jasmine/pull/1801) from @Maximaximum
|
||||||
|
- Fixes [#1717](https://github.com/jasmine/jasmine/issues/1717)
|
||||||
|
|
||||||
|
* Added a toHaveSize matcher
|
||||||
|
- Merges [#1796](https://github.com/jasmine/jasmine/pull/1796) from @wokier
|
||||||
|
|
||||||
|
* Added a toBePending async matcher
|
||||||
|
- Merges [#1808](https://github.com/jasmine/jasmine/pull/1808) from @DCtheTall
|
||||||
|
- Fixes [#1803](https://github.com/jasmine/jasmine/issues/1803)
|
||||||
|
|
||||||
|
* Added support for user-defined spec/suite properties
|
||||||
|
- Allows specs/suites to pass data to custom reporters
|
||||||
|
- Merges [#1763](https://github.com/jasmine/jasmine/pull/1763) from @johnjbarton
|
||||||
|
|
||||||
|
* Route unhandled promise rejections to onerror
|
||||||
|
- Merges [#1778](https://github.com/jasmine/jasmine/pull/1778) from @johnjbarton
|
||||||
|
- Fixes [#1777](https://github.com/jasmine/jasmine/issues/1777)
|
||||||
|
|
||||||
|
|
||||||
|
## Internal notes
|
||||||
|
|
||||||
|
* Use a version of eslint that works on Node 8
|
||||||
|
|
||||||
|
* Check for syntax and standard library objects that don't work in IE
|
||||||
|
|
||||||
|
* Run eslint against all files
|
||||||
|
|
||||||
|
* Add Additional Test for equals Matcher
|
||||||
|
- Merges [#1829](https://github.com/jasmine/jasmine/pull/1829) from @tobiasschweizer
|
||||||
|
- Fixes [#1821](https://github.com/jasmine/jasmine/issues/1821)
|
||||||
|
|
||||||
|
* Depend on head of jasmine-browser to fix IE failures in CI
|
||||||
|
|
||||||
|
* Fixed test failure in Firefox 74
|
||||||
|
|
||||||
|
* Added test for resolveTo/rejectWith with empty parameters
|
||||||
|
- Merges [#1802](https://github.com/jasmine/jasmine/pull/1802) from @chivesrs
|
||||||
|
|
||||||
|
* Removed unnecessary uses of new in tests
|
||||||
|
|
||||||
|
* Realigned the browser testing matrix to match current reality
|
||||||
|
- Use Windows instead of Linux so we can get current browsers from Sauce.
|
||||||
|
- Test against the version of Firefox that corresponds to ESR as well as
|
||||||
|
latest.
|
||||||
|
- Test the latest Edge rather than a specific older version.
|
||||||
|
- Test Safari 8 and 13 instead of 8, 9 and 10. What works in those versions
|
||||||
|
is likely to work in the ones in between.
|
||||||
|
|
||||||
|
* Don't leak global error handlers between Jasmine's own tests
|
||||||
|
|
||||||
|
* Added basic property tests for matchersUtil.equals
|
||||||
|
|
||||||
|
* Added integration tests for existing matcher interfaces
|
||||||
|
|
||||||
|
* Added integration tests for asymmetric equality testers
|
||||||
|
|
||||||
|
* Test IE before other browsers on Travis
|
||||||
|
|
||||||
|
|
||||||
|
## Other Changes
|
||||||
|
|
||||||
|
* Show diffs involving root-level asymmetric equality testers
|
||||||
|
- Fixes [#1831](https://github.com/jasmine/jasmine/issues/1831)
|
||||||
|
|
||||||
|
* Fixed references to master in docs
|
||||||
|
|
||||||
|
* Allow spy throwError to throw an Object
|
||||||
|
- Merges [#1822](https://github.com/jasmine/jasmine/pull/1822) from @terencehonles
|
||||||
|
|
||||||
|
* Added missing periods to README
|
||||||
|
- Merges [#1828](https://github.com/jasmine/jasmine/pull/1828) from @dirkpuge
|
||||||
|
|
||||||
|
|
||||||
|
* Expose setSpec/SuiteProperty on interface
|
||||||
|
- Merges [#1820](https://github.com/jasmine/jasmine/pull/1820) from @johnjbarton
|
||||||
|
|
||||||
|
* Prevent undesired reloads when karma-jasmine-html-reporter is used
|
||||||
|
- Merges [#1807](https://github.com/jasmine/jasmine/pull/1807) from @parloti
|
||||||
|
- Fixes [#1775](https://github.com/jasmine/jasmine/issues/1775)
|
||||||
|
|
||||||
|
* Correctly report spec and suite duration
|
||||||
|
- Fixes [#1676](https://github.com/jasmine/jasmine/issues/1676).
|
||||||
|
|
||||||
|
* Added jsdocs for MatchersUtil
|
||||||
|
|
||||||
|
* Allow the .callThrough spy strategy to call constructor functions without errors
|
||||||
|
- Merges [#1782](https://github.com/jasmine/jasmine/pull/1782) from @enelson
|
||||||
|
- Fixes [#1760](https://github.com/jasmine/jasmine/issues/1760)
|
||||||
|
|
||||||
|
* Inject a per-runable pretty printer into MatchersUtil
|
||||||
|
- Supports custom object formatters
|
||||||
|
|
||||||
|
* Include stack traces in unhandled promise rejection messages
|
||||||
|
|
||||||
|
* Describe the naming for the function it
|
||||||
|
- Merges [#1772](https://github.com/jasmine/jasmine/pull/1772) from @johnlinp
|
||||||
|
|
||||||
|
* Correctly extract error messages from stack traces that don't start with `Error`
|
||||||
|
- Merges [#1776](https://github.com/jasmine/jasmine/pull/1776) from @vhermannitk
|
||||||
|
- Fixes [#1771](https://github.com/jasmine/jasmine/issues/1771)
|
||||||
|
|
||||||
|
* Fixed objectContaining to not match when the expected is the empty object and the actual is a non-object
|
||||||
|
|
||||||
|
* Fixed toEqual(0, Number.MIN_VALUE) to fail instead of passing
|
||||||
|
- Merges [#1764](https://github.com/jasmine/jasmine/pull/1764) from @dubzzz
|
||||||
|
|
||||||
|
* Fixed comparison between ObjectContaining and non-objects on IE
|
||||||
|
|
||||||
|
* Provide better diffs for object graphs that include `objectContaining`
|
||||||
|
|
||||||
|
* Indent multiline failure messages in the output of `withContext`
|
||||||
|
* This makes it easier to see where each failure message begins and ends.
|
||||||
|
|
||||||
|
* Report async expectations that complete after the runable completes
|
||||||
|
- See [#1752](https://github.com/jasmine/jasmine/issues/1752).
|
||||||
|
|
||||||
|
* Treat NodeJS assertion failures as expectation failures
|
||||||
|
- Merges [#1678](https://github.com/jasmine/jasmine/pull/1678) from @apla
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
17
spec/.eslintrc.js
Normal file
17
spec/.eslintrc.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
module.exports = {
|
||||||
|
"ignorePatterns": [
|
||||||
|
"support/ci.js",
|
||||||
|
"support/jasmine-browser.js"
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
// Relax rules for now to allow for the quirks of the test suite
|
||||||
|
// TODO: We should probably remove these & fix the resulting errors
|
||||||
|
"quotes": "off",
|
||||||
|
"semi": "off",
|
||||||
|
"key-spacing": "off",
|
||||||
|
"space-before-blocks": "off",
|
||||||
|
"no-unused-vars": "off",
|
||||||
|
"no-trailing-spaces": "off",
|
||||||
|
"block-spacing": "off",
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
describe('AsyncExpectation', function() {
|
describe('AsyncExpectation', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmineUnderTest.Expectation.addAsyncCoreMatchers(
|
jasmineUnderTest.Expectation.addAsyncCoreMatchers(
|
||||||
@@ -24,8 +25,9 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.resolve(),
|
actual = Promise.resolve(),
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
util: jasmineUnderTest.matchersUtil,
|
matchersUtil: new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -47,7 +49,9 @@ describe('AsyncExpectation', function() {
|
|||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.reject(),
|
actual = Promise.reject(),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
util: jasmineUnderTest.matchersUtil,
|
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: function() {}
|
||||||
|
}),
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -91,7 +95,7 @@ describe('AsyncExpectation', function() {
|
|||||||
it('prepends the context to the generated failure message', function() {
|
it('prepends the context to the generated failure message', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var util = {
|
var matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'failure message';
|
return 'failure message';
|
||||||
}
|
}
|
||||||
@@ -100,7 +104,7 @@ describe('AsyncExpectation', function() {
|
|||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: Promise.reject('rejected'),
|
actual: Promise.reject('rejected'),
|
||||||
addExpectationResult: addExpectationResult,
|
addExpectationResult: addExpectationResult,
|
||||||
util: util
|
matchersUtil: matchersUtil
|
||||||
});
|
});
|
||||||
|
|
||||||
return expectation
|
return expectation
|
||||||
@@ -119,16 +123,17 @@ describe('AsyncExpectation', function() {
|
|||||||
it('prepends the context to a custom failure message', function() {
|
it('prepends the context to a custom failure message', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var util = {
|
var matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'failure message';
|
return 'failure message';
|
||||||
}
|
},
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: Promise.reject('b'),
|
actual: Promise.reject('b'),
|
||||||
addExpectationResult: addExpectationResult,
|
addExpectationResult: addExpectationResult,
|
||||||
util: util
|
matchersUtil: matchersUtil
|
||||||
});
|
});
|
||||||
|
|
||||||
return expectation
|
return expectation
|
||||||
@@ -149,7 +154,7 @@ describe('AsyncExpectation', function() {
|
|||||||
pending('should actually work, but no custom matchers for async yet');
|
pending('should actually work, but no custom matchers for async yet');
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var util = {
|
var matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'failure message';
|
return 'failure message';
|
||||||
}
|
}
|
||||||
@@ -159,7 +164,7 @@ describe('AsyncExpectation', function() {
|
|||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult,
|
addExpectationResult: addExpectationResult,
|
||||||
util: util
|
matchersUtil: matchersUtil
|
||||||
});
|
});
|
||||||
|
|
||||||
return expectation
|
return expectation
|
||||||
@@ -180,10 +185,11 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.resolve(),
|
actual = Promise.resolve(),
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult,
|
addExpectationResult: addExpectationResult,
|
||||||
util: jasmineUnderTest.matchersUtil
|
matchersUtil: new jasmineUnderTest.MatchersUtil({ pp: pp })
|
||||||
});
|
});
|
||||||
|
|
||||||
return expectation
|
return expectation
|
||||||
@@ -208,7 +214,9 @@ describe('AsyncExpectation', function() {
|
|||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult,
|
addExpectationResult: addExpectationResult,
|
||||||
util: jasmineUnderTest.matchersUtil
|
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
return expectation
|
return expectation
|
||||||
@@ -256,7 +264,7 @@ describe('AsyncExpectation', function() {
|
|||||||
matchers = {
|
matchers = {
|
||||||
toFoo: matcherFactory
|
toFoo: matcherFactory
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
customEqualityTesters = ['a'],
|
customEqualityTesters = ['a'],
|
||||||
@@ -264,7 +272,7 @@ describe('AsyncExpectation', function() {
|
|||||||
expectation;
|
expectation;
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
customEqualityTesters: customEqualityTesters,
|
customEqualityTesters: customEqualityTesters,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -273,7 +281,7 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
return expectation.toFoo('hello').then(function() {
|
return expectation.toFoo('hello').then(function() {
|
||||||
expect(matcherFactory).toHaveBeenCalledWith(
|
expect(matcherFactory).toHaveBeenCalledWith(
|
||||||
util,
|
matchersUtil,
|
||||||
customEqualityTesters
|
customEqualityTesters
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -292,14 +300,14 @@ describe('AsyncExpectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
expectation;
|
expectation;
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -322,7 +330,7 @@ describe('AsyncExpectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
@@ -335,7 +343,7 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -365,7 +373,7 @@ describe('AsyncExpectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -380,7 +388,7 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -536,7 +544,7 @@ describe('AsyncExpectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'default message';
|
return 'default message';
|
||||||
}
|
}
|
||||||
@@ -553,7 +561,7 @@ describe('AsyncExpectation', function() {
|
|||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
}).not;
|
}).not;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ describe('Env', function() {
|
|||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
describe('#pending', function() {
|
describe('#pending', function() {
|
||||||
it('throws the Pending Spec exception', function() {
|
it('throws the Pending Spec exception', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -281,11 +285,13 @@ describe('Env', function() {
|
|||||||
it('installs a global error handler on construction', function() {
|
it('installs a global error handler on construction', function() {
|
||||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||||
'install',
|
'install',
|
||||||
|
'uninstall',
|
||||||
'pushListener',
|
'pushListener',
|
||||||
'popListener'
|
'popListener'
|
||||||
]);
|
]);
|
||||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||||
new jasmineUnderTest.Env();
|
env.cleanup_();
|
||||||
|
env = new jasmineUnderTest.Env();
|
||||||
expect(globalErrors.install).toHaveBeenCalled();
|
expect(globalErrors.install).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -294,14 +300,90 @@ describe('Env', function() {
|
|||||||
it('does not install a global error handler until execute is called', function() {
|
it('does not install a global error handler until execute is called', function() {
|
||||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||||
'install',
|
'install',
|
||||||
|
'uninstall',
|
||||||
'pushListener',
|
'pushListener',
|
||||||
'popListener'
|
'popListener'
|
||||||
]);
|
]);
|
||||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||||
|
env.cleanup_();
|
||||||
env = new jasmineUnderTest.Env({ suppressLoadErrors: true });
|
env = new jasmineUnderTest.Env({ suppressLoadErrors: true });
|
||||||
expect(globalErrors.install).not.toHaveBeenCalled();
|
expect(globalErrors.install).not.toHaveBeenCalled();
|
||||||
env.execute();
|
env.execute();
|
||||||
expect(globalErrors.install).toHaveBeenCalled();
|
expect(globalErrors.install).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('creates an expectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
||||||
|
function customEqualityTester() {}
|
||||||
|
function customObjectFormatter() {}
|
||||||
|
function prettyPrinter() {}
|
||||||
|
var RealSpec = jasmineUnderTest.Spec,
|
||||||
|
specInstance,
|
||||||
|
expectationFactory;
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||||
|
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||||
|
expectationFactory = options.expectationFactory;
|
||||||
|
specInstance = new RealSpec(options);
|
||||||
|
return specInstance;
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it('spec', function() {
|
||||||
|
env.addCustomEqualityTester(customEqualityTester);
|
||||||
|
env.addCustomObjectFormatter(customObjectFormatter);
|
||||||
|
expectationFactory('actual', specInstance);
|
||||||
|
});
|
||||||
|
|
||||||
|
env.addReporter({
|
||||||
|
jasmineDone: function() {
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
|
customObjectFormatter
|
||||||
|
]);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
|
customTesters: [customEqualityTester],
|
||||||
|
pp: prettyPrinter
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
||||||
|
function customEqualityTester() {}
|
||||||
|
function customObjectFormatter() {}
|
||||||
|
function prettyPrinter() {}
|
||||||
|
var RealSpec = jasmineUnderTest.Spec,
|
||||||
|
specInstance,
|
||||||
|
asyncExpectationFactory;
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||||
|
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||||
|
asyncExpectationFactory = options.asyncExpectationFactory;
|
||||||
|
specInstance = new RealSpec(options);
|
||||||
|
return specInstance;
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it('spec', function() {
|
||||||
|
env.addCustomEqualityTester(customEqualityTester);
|
||||||
|
env.addCustomObjectFormatter(customObjectFormatter);
|
||||||
|
asyncExpectationFactory('actual', specInstance);
|
||||||
|
});
|
||||||
|
|
||||||
|
env.addReporter({
|
||||||
|
jasmineDone: function() {
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
|
customObjectFormatter
|
||||||
|
]);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
|
customTesters: [customEqualityTester],
|
||||||
|
pp: prettyPrinter
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ describe('Exceptions:', function() {
|
|||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle exceptions thrown, but continue', function(done) {
|
it('should handle exceptions thrown, but continue', function(done) {
|
||||||
var secondTest = jasmine.createSpy('second test');
|
var secondTest = jasmine.createSpy('second test');
|
||||||
env.describe('Suite for handles exceptions', function() {
|
env.describe('Suite for handles exceptions', function() {
|
||||||
|
|||||||
@@ -72,21 +72,21 @@ describe('ExpectationFilterChain', function() {
|
|||||||
matcherResult = { pass: false },
|
matcherResult = { pass: false },
|
||||||
matcherName = 'foo',
|
matcherName = 'foo',
|
||||||
args = [],
|
args = [],
|
||||||
util = {},
|
matchersUtil = {},
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = chain.buildFailureMessage(
|
result = chain.buildFailureMessage(
|
||||||
matcherResult,
|
matcherResult,
|
||||||
matcherName,
|
matcherName,
|
||||||
args,
|
args,
|
||||||
util
|
matchersUtil
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(first).toHaveBeenCalledWith(
|
expect(first).toHaveBeenCalledWith(
|
||||||
matcherResult,
|
matcherResult,
|
||||||
matcherName,
|
matcherName,
|
||||||
args,
|
args,
|
||||||
util
|
matchersUtil
|
||||||
);
|
);
|
||||||
expect(second).not.toHaveBeenCalled();
|
expect(second).not.toHaveBeenCalled();
|
||||||
expect(result).toEqual('first');
|
expect(result).toEqual('first');
|
||||||
|
|||||||
@@ -90,4 +90,37 @@ describe('buildExpectationResult', function() {
|
|||||||
});
|
});
|
||||||
expect(result.actual).toBe('some-value');
|
expect(result.actual).toBe('some-value');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles nodejs assertions', function() {
|
||||||
|
if (typeof require === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var assert = require('assert');
|
||||||
|
var error;
|
||||||
|
var value = 8421;
|
||||||
|
var expectedValue = 'JasmineExpectationTestValue';
|
||||||
|
try {
|
||||||
|
assert.equal(value, expectedValue);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.code).toEqual('ERR_ASSERTION');
|
||||||
|
expect(error.actual).toEqual(value);
|
||||||
|
expect(error.expected).toEqual(expectedValue);
|
||||||
|
expect(error.operator).toEqual('==');
|
||||||
|
|
||||||
|
var result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: false,
|
||||||
|
matcherName: '',
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: error
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.code).toEqual('ERR_ASSERTION');
|
||||||
|
expect(result.actual).toEqual(value);
|
||||||
|
expect(result.expected).toEqual(expectedValue);
|
||||||
|
expect(result.matcherName).toEqual('assert ==');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ describe('Expectation', function() {
|
|||||||
matchers = {
|
matchers = {
|
||||||
toFoo: matcherFactory
|
toFoo: matcherFactory
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
customEqualityTesters = ['a'],
|
customEqualityTesters = ['a'],
|
||||||
@@ -45,7 +45,7 @@ describe('Expectation', function() {
|
|||||||
expectation;
|
expectation;
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
customEqualityTesters: customEqualityTesters,
|
customEqualityTesters: customEqualityTesters,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -54,7 +54,10 @@ describe('Expectation', function() {
|
|||||||
|
|
||||||
expectation.toFoo('hello');
|
expectation.toFoo('hello');
|
||||||
|
|
||||||
expect(matcherFactory).toHaveBeenCalledWith(util, customEqualityTesters);
|
expect(matcherFactory).toHaveBeenCalledWith(
|
||||||
|
matchersUtil,
|
||||||
|
customEqualityTesters
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
||||||
@@ -68,14 +71,14 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
expectation;
|
expectation;
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -96,7 +99,7 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
@@ -104,7 +107,7 @@ describe('Expectation', function() {
|
|||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -132,7 +135,7 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -142,7 +145,7 @@ describe('Expectation', function() {
|
|||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -275,7 +278,7 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'default message';
|
return 'default message';
|
||||||
}
|
}
|
||||||
@@ -287,7 +290,7 @@ describe('Expectation', function() {
|
|||||||
expectation = jasmineUnderTest.Expectation.factory({
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
}).not;
|
}).not;
|
||||||
|
|
||||||
@@ -539,7 +542,7 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
util = {
|
matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'failure message';
|
return 'failure message';
|
||||||
}
|
}
|
||||||
@@ -547,7 +550,7 @@ describe('Expectation', function() {
|
|||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
util: util,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -589,6 +592,32 @@ describe('Expectation', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('indents a multiline failure message', function() {
|
||||||
|
var matchers = {
|
||||||
|
toFoo: function() {
|
||||||
|
return {
|
||||||
|
compare: function() {
|
||||||
|
return { pass: false, message: 'a\nmultiline\nmessage' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
|
customMatchers: matchers,
|
||||||
|
actual: 'an actual',
|
||||||
|
addExpectationResult: addExpectationResult
|
||||||
|
}),
|
||||||
|
actualMessage;
|
||||||
|
|
||||||
|
expectation.withContext('Some context').toFoo('hello');
|
||||||
|
|
||||||
|
actualMessage = addExpectationResult.calls.argsFor(0)[1].message;
|
||||||
|
expect(actualMessage).toEqual(
|
||||||
|
'Some context:\n a\n multiline\n message'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('prepends the context to a custom failure message from a function', function() {
|
it('prepends the context to a custom failure message from a function', function() {
|
||||||
var matchers = {
|
var matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
@@ -632,9 +661,10 @@ describe('Expectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
util: jasmineUnderTest.matchersUtil,
|
matchersUtil: new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -193,4 +193,80 @@ describe('GlobalErrors', function() {
|
|||||||
'foo'
|
'foo'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Reporting unhandled promise rejections in the browser', function() {
|
||||||
|
it('subscribes and unsubscribes from the unhandledrejection event', function() {
|
||||||
|
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'addEventListener',
|
||||||
|
'removeEventListener',
|
||||||
|
'onerror'
|
||||||
|
]),
|
||||||
|
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
expect(fakeGlobal.addEventListener).toHaveBeenCalledWith(
|
||||||
|
'unhandledrejection',
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
|
||||||
|
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||||
|
errors.uninstall();
|
||||||
|
|
||||||
|
expect(fakeGlobal.removeEventListener).toHaveBeenCalledWith(
|
||||||
|
'unhandledrejection',
|
||||||
|
addedListener
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reports rejections whose reason is a string', function() {
|
||||||
|
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'addEventListener',
|
||||||
|
'removeEventListener',
|
||||||
|
'onerror'
|
||||||
|
]),
|
||||||
|
handler = jasmine.createSpy('errorHandler'),
|
||||||
|
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
|
||||||
|
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||||
|
addedListener({ reason: 'nope' });
|
||||||
|
|
||||||
|
expect(handler).toHaveBeenCalledWith('Unhandled promise rejection: nope');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reports rejections whose reason is an Error', function() {
|
||||||
|
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'addEventListener',
|
||||||
|
'removeEventListener',
|
||||||
|
'onerror'
|
||||||
|
]),
|
||||||
|
handler = jasmine.createSpy('errorHandler'),
|
||||||
|
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
|
||||||
|
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(handler).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||||
|
message: reason.message,
|
||||||
|
stack: reason.stack
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,26 +1,29 @@
|
|||||||
describe('jasmineUnderTest.pp', function() {
|
describe('PrettyPrinter', function() {
|
||||||
it('should wrap strings in single quotes', function() {
|
it('should wrap strings in single quotes', function() {
|
||||||
expect(jasmineUnderTest.pp('some string')).toEqual("'some string'");
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(jasmineUnderTest.pp("som' string")).toEqual("'som' string'");
|
expect(pp('some string')).toEqual("'some string'");
|
||||||
|
expect(pp("som' string")).toEqual("'som' string'");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify primitives properly', function() {
|
it('should stringify primitives properly', function() {
|
||||||
expect(jasmineUnderTest.pp(true)).toEqual('true');
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(jasmineUnderTest.pp(false)).toEqual('false');
|
expect(pp(true)).toEqual('true');
|
||||||
expect(jasmineUnderTest.pp(null)).toEqual('null');
|
expect(pp(false)).toEqual('false');
|
||||||
expect(jasmineUnderTest.pp(jasmine.undefined)).toEqual('undefined');
|
expect(pp(null)).toEqual('null');
|
||||||
expect(jasmineUnderTest.pp(3)).toEqual('3');
|
expect(pp(jasmine.undefined)).toEqual('undefined');
|
||||||
expect(jasmineUnderTest.pp(-3.14)).toEqual('-3.14');
|
expect(pp(3)).toEqual('3');
|
||||||
expect(jasmineUnderTest.pp(-0)).toEqual('-0');
|
expect(pp(-3.14)).toEqual('-3.14');
|
||||||
|
expect(pp(-0)).toEqual('-0');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('stringify sets', function() {
|
describe('stringify sets', function() {
|
||||||
it('should stringify sets properly', function() {
|
it('should stringify sets properly', function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
var set = new Set();
|
var set = new Set(); // eslint-disable-line compat/compat
|
||||||
set.add(1);
|
set.add(1);
|
||||||
set.add(2);
|
set.add(2);
|
||||||
expect(jasmineUnderTest.pp(set)).toEqual('Set( 1, 2 )');
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp(set)).toEqual('Set( 1, 2 )');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should truncate sets with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
it('should truncate sets with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||||
@@ -29,11 +32,12 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
var set = new Set();
|
var set = new Set(); // eslint-disable-line compat/compat
|
||||||
set.add('a');
|
set.add('a');
|
||||||
set.add('b');
|
set.add('b');
|
||||||
set.add('c');
|
set.add('c');
|
||||||
expect(jasmineUnderTest.pp(set)).toEqual("Set( 'a', 'b', ... )");
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||||
}
|
}
|
||||||
@@ -43,9 +47,10 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
describe('stringify maps', function() {
|
describe('stringify maps', function() {
|
||||||
it('should stringify maps properly', function() {
|
it('should stringify maps properly', function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var map = new Map();
|
var map = new Map(); // eslint-disable-line compat/compat
|
||||||
map.set(1, 2);
|
map.set(1, 2);
|
||||||
expect(jasmineUnderTest.pp(map)).toEqual('Map( [ 1, 2 ] )');
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp(map)).toEqual('Map( [ 1, 2 ] )');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should truncate maps with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
it('should truncate maps with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||||
@@ -54,13 +59,12 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
var map = new Map();
|
var map = new Map(); // eslint-disable-line compat/compat
|
||||||
map.set('a', 1);
|
map.set('a', 1);
|
||||||
map.set('b', 2);
|
map.set('b', 2);
|
||||||
map.set('c', 3);
|
map.set('c', 3);
|
||||||
expect(jasmineUnderTest.pp(map)).toEqual(
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
"Map( [ 'a', 1 ], [ 'b', 2 ], ... )"
|
expect(pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||||
);
|
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||||
}
|
}
|
||||||
@@ -69,43 +73,44 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
|
|
||||||
describe('stringify arrays', function() {
|
describe('stringify arrays', function() {
|
||||||
it('should stringify arrays properly', function() {
|
it('should stringify arrays properly', function() {
|
||||||
expect(jasmineUnderTest.pp([1, 2])).toEqual('[ 1, 2 ]');
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(
|
expect(pp([1, 2])).toEqual('[ 1, 2 ]');
|
||||||
jasmineUnderTest.pp([1, 'foo', {}, jasmine.undefined, null])
|
expect(pp([1, 'foo', {}, jasmine.undefined, null])).toEqual(
|
||||||
).toEqual("[ 1, 'foo', Object({ }), undefined, null ]");
|
"[ 1, 'foo', Object({ }), undefined, null ]"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
it('should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
var array = [1, 2, 3];
|
var array = [1, 2, 3];
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
expect(jasmineUnderTest.pp(array)).toEqual('[ 1, 2, ... ]');
|
expect(pp(array)).toEqual('[ 1, 2, ... ]');
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify arrays with properties properly', function() {
|
it('should stringify arrays with properties properly', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var arr = [1, 2];
|
var arr = [1, 2];
|
||||||
arr.foo = 'bar';
|
arr.foo = 'bar';
|
||||||
arr.baz = {};
|
arr.baz = {};
|
||||||
expect(jasmineUnderTest.pp(arr)).toEqual(
|
expect(pp(arr)).toEqual("[ 1, 2, foo: 'bar', baz: Object({ }) ]");
|
||||||
"[ 1, 2, foo: 'bar', baz: Object({ }) ]"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify empty arrays with properties properly', function() {
|
it('should stringify empty arrays with properties properly', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var empty = [];
|
var empty = [];
|
||||||
empty.foo = 'bar';
|
empty.foo = 'bar';
|
||||||
empty.baz = {};
|
empty.baz = {};
|
||||||
expect(jasmineUnderTest.pp(empty)).toEqual(
|
expect(pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
|
||||||
"[ foo: 'bar', baz: Object({ }) ]"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify long arrays with properties properly', function() {
|
it('should stringify long arrays with properties properly', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
var long = [1, 2, 3];
|
var long = [1, 2, 3];
|
||||||
long.foo = 'bar';
|
long.foo = 'bar';
|
||||||
@@ -113,7 +118,7 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
expect(jasmineUnderTest.pp(long)).toEqual(
|
expect(pp(long)).toEqual(
|
||||||
"[ 1, 2, ..., foo: 'bar', baz: Object({ }) ]"
|
"[ 1, 2, ..., foo: 'bar', baz: Object({ }) ]"
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -122,26 +127,25 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should indicate circular array references', function() {
|
it('should indicate circular array references', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var array1 = [1, 2];
|
var array1 = [1, 2];
|
||||||
var array2 = [array1];
|
var array2 = [array1];
|
||||||
array1.push(array2);
|
array1.push(array2);
|
||||||
expect(jasmineUnderTest.pp(array1)).toEqual(
|
expect(pp(array1)).toEqual('[ 1, 2, [ <circular reference: Array> ] ]');
|
||||||
'[ 1, 2, [ <circular reference: Array> ] ]'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not indicate circular references incorrectly', function() {
|
it('should not indicate circular references incorrectly', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var array = [[1]];
|
var array = [[1]];
|
||||||
expect(jasmineUnderTest.pp(array)).toEqual('[ [ 1 ] ]');
|
expect(pp(array)).toEqual('[ [ 1 ] ]');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects properly', function() {
|
it('should stringify objects properly', function() {
|
||||||
expect(jasmineUnderTest.pp({ foo: 'bar' })).toEqual(
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
"Object({ foo: 'bar' })"
|
expect(pp({ foo: 'bar' })).toEqual("Object({ foo: 'bar' })");
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
jasmineUnderTest.pp({
|
pp({
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
baz: 3,
|
baz: 3,
|
||||||
nullValue: null,
|
nullValue: null,
|
||||||
@@ -150,24 +154,24 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
).toEqual(
|
).toEqual(
|
||||||
"Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })"
|
"Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })"
|
||||||
);
|
);
|
||||||
expect(jasmineUnderTest.pp({ foo: function() {}, bar: [1, 2, 3] })).toEqual(
|
expect(pp({ foo: function() {}, bar: [1, 2, 3] })).toEqual(
|
||||||
'Object({ foo: Function, bar: [ 1, 2, 3 ] })'
|
'Object({ foo: Function, bar: [ 1, 2, 3 ] })'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects that almost look like DOM nodes', function() {
|
it('should stringify objects that almost look like DOM nodes', function() {
|
||||||
expect(jasmineUnderTest.pp({ nodeType: 1 })).toEqual(
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
'Object({ nodeType: 1 })'
|
expect(pp({ nodeType: 1 })).toEqual('Object({ nodeType: 1 })');
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should truncate objects with too many keys', function() {
|
it('should truncate objects with too many keys', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
var long = { a: 1, b: 2, c: 3 };
|
var long = { a: 1, b: 2, c: 3 };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
expect(jasmineUnderTest.pp(long)).toEqual('Object({ a: 1, b: 2, ... })');
|
expect(pp(long)).toEqual('Object({ a: 1, b: 2, ... })');
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||||
}
|
}
|
||||||
@@ -185,12 +189,11 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should truncate outputs that are too long', function() {
|
it('should truncate outputs that are too long', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var big = [{ a: 1, b: 'a long string' }, {}];
|
var big = [{ a: 1, b: 'a long string' }, {}];
|
||||||
|
|
||||||
withMaxChars(34, function() {
|
withMaxChars(34, function() {
|
||||||
expect(jasmineUnderTest.pp(big)).toEqual(
|
expect(pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
||||||
"[ Object({ a: 1, b: 'a long st ..."
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -214,59 +217,55 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
jasmineToString: jasmine
|
jasmineToString: jasmine
|
||||||
.createSpy('d jasmineToString')
|
.createSpy('d jasmineToString')
|
||||||
.and.returnValue('')
|
.and.returnValue('')
|
||||||
};
|
},
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
|
||||||
withMaxChars(30, function() {
|
withMaxChars(30, function() {
|
||||||
jasmineUnderTest.pp([{ a: a, b: b, c: c }, d]);
|
pp([{ a: a, b: b, c: c }, d]);
|
||||||
expect(c.jasmineToString).not.toHaveBeenCalled();
|
expect(c.jasmineToString).not.toHaveBeenCalled();
|
||||||
expect(d.jasmineToString).not.toHaveBeenCalled();
|
expect(d.jasmineToString).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
||||||
expect(jasmineUnderTest.pp({ constructor: function() {} })).toContain(
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
'null({'
|
expect(pp({ constructor: function() {} })).toContain('null({');
|
||||||
);
|
expect(pp({ constructor: 'foo' })).toContain('null({');
|
||||||
expect(jasmineUnderTest.pp({ constructor: 'foo' })).toContain('null({');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not include inherited properties when stringifying an object', function() {
|
it('should not include inherited properties when stringifying an object', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var SomeClass = function SomeClass() {};
|
var SomeClass = function SomeClass() {};
|
||||||
SomeClass.prototype.foo = 'inherited foo';
|
SomeClass.prototype.foo = 'inherited foo';
|
||||||
var instance = new SomeClass();
|
var instance = new SomeClass();
|
||||||
instance.bar = 'my own bar';
|
instance.bar = 'my own bar';
|
||||||
expect(jasmineUnderTest.pp(instance)).toEqual(
|
expect(pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
|
||||||
"SomeClass({ bar: 'my own bar' })"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not recurse objects and arrays more deeply than jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH', function() {
|
it('should not recurse objects and arrays more deeply than jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
|
var originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
|
||||||
var nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
var nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
||||||
var nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
var nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
|
||||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
expect(pp(nestedObject)).toEqual(
|
||||||
'Object({ level1: Object({ level2: Object }) })'
|
'Object({ level1: Object({ level2: Object }) })'
|
||||||
);
|
);
|
||||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual('[ 1, [ 2, Array ] ]');
|
expect(pp(nestedArray)).toEqual('[ 1, [ 2, Array ] ]');
|
||||||
|
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 3;
|
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 3;
|
||||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
expect(pp(nestedObject)).toEqual(
|
||||||
'Object({ level1: Object({ level2: Object({ level3: Object }) }) })'
|
'Object({ level1: Object({ level2: Object({ level3: Object }) }) })'
|
||||||
);
|
);
|
||||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual(
|
expect(pp(nestedArray)).toEqual('[ 1, [ 2, [ 3, Array ] ] ]');
|
||||||
'[ 1, [ 2, [ 3, Array ] ] ]'
|
|
||||||
);
|
|
||||||
|
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 4;
|
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 4;
|
||||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
expect(pp(nestedObject)).toEqual(
|
||||||
"Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })"
|
"Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })"
|
||||||
);
|
);
|
||||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual(
|
expect(pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
|
||||||
"[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]"
|
|
||||||
);
|
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
|
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
|
||||||
}
|
}
|
||||||
@@ -274,28 +273,32 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
|
|
||||||
it('should stringify immutable circular objects', function() {
|
it('should stringify immutable circular objects', function() {
|
||||||
if (Object.freeze) {
|
if (Object.freeze) {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var frozenObject = { foo: { bar: 'baz' } };
|
var frozenObject = { foo: { bar: 'baz' } };
|
||||||
frozenObject.circular = frozenObject;
|
frozenObject.circular = frozenObject;
|
||||||
frozenObject = Object.freeze(frozenObject);
|
frozenObject = Object.freeze(frozenObject);
|
||||||
expect(jasmineUnderTest.pp(frozenObject)).toEqual(
|
expect(pp(frozenObject)).toEqual(
|
||||||
"Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })"
|
"Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify RegExp objects properly', function() {
|
it('should stringify RegExp objects properly', function() {
|
||||||
expect(jasmineUnderTest.pp(/x|y|z/)).toEqual('/x|y|z/');
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp(/x|y|z/)).toEqual('/x|y|z/');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should indicate circular object references', function() {
|
it('should indicate circular object references', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var sampleValue = { foo: 'hello' };
|
var sampleValue = { foo: 'hello' };
|
||||||
sampleValue.nested = sampleValue;
|
sampleValue.nested = sampleValue;
|
||||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual(
|
expect(pp(sampleValue)).toEqual(
|
||||||
"Object({ foo: 'hello', nested: <circular reference: Object> })"
|
"Object({ foo: 'hello', nested: <circular reference: Object> })"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should indicate getters on objects as such', function() {
|
it('should indicate getters on objects as such', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var sampleValue = { id: 1 };
|
var sampleValue = { id: 1 };
|
||||||
if (sampleValue.__defineGetter__) {
|
if (sampleValue.__defineGetter__) {
|
||||||
//not supported in IE!
|
//not supported in IE!
|
||||||
@@ -304,95 +307,117 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (sampleValue.__defineGetter__) {
|
if (sampleValue.__defineGetter__) {
|
||||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual(
|
expect(pp(sampleValue)).toEqual(
|
||||||
'Object({ id: 1, calculatedValue: <getter> })'
|
'Object({ id: 1, calculatedValue: <getter> })'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual('Object({ id: 1 })');
|
expect(pp(sampleValue)).toEqual('Object({ id: 1 })');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not do HTML escaping of strings', function() {
|
it('should not do HTML escaping of strings', function() {
|
||||||
expect(jasmineUnderTest.pp('some <b>html string</b> &', false)).toEqual(
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp('some <b>html string</b> &', false)).toEqual(
|
||||||
"'some <b>html string</b> &'"
|
"'some <b>html string</b> &'"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should abbreviate the global (usually window) object', function() {
|
it('should abbreviate the global (usually window) object', function() {
|
||||||
expect(jasmineUnderTest.pp(jasmine.getGlobal())).toEqual('<global>');
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp(jasmine.getGlobal())).toEqual('<global>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify Date objects properly', function() {
|
it('should stringify Date objects properly', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
expect(jasmineUnderTest.pp(now)).toEqual('Date(' + now.toString() + ')');
|
expect(pp(now)).toEqual('Date(' + now.toString() + ')');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify spy objects properly', function() {
|
describe('with a spy object', function() {
|
||||||
var TestObject = {
|
var env, pp;
|
||||||
someFunction: function() {}
|
|
||||||
},
|
|
||||||
env = new jasmineUnderTest.Env();
|
|
||||||
|
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
beforeEach(function() {
|
||||||
currentSpies: function() {
|
env = new jasmineUnderTest.Env();
|
||||||
return [];
|
pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
},
|
|
||||||
createSpy: function(name, originalFn) {
|
|
||||||
return jasmineUnderTest.Spy(name, originalFn);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spyRegistry.spyOn(TestObject, 'someFunction');
|
afterEach(function() {
|
||||||
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual(
|
env.cleanup_();
|
||||||
'spy on someFunction'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(env.createSpy('something'))).toEqual(
|
|
||||||
'spy on something'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should stringify spyOn toString properly', function() {
|
|
||||||
var TestObject = {
|
|
||||||
someFunction: function() {}
|
|
||||||
},
|
|
||||||
env = new jasmineUnderTest.Env();
|
|
||||||
|
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
|
||||||
currentSpies: function() {
|
|
||||||
return [];
|
|
||||||
},
|
|
||||||
createSpy: function(name, originalFn) {
|
|
||||||
return jasmineUnderTest.Spy(name, originalFn);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spyRegistry.spyOn(TestObject, 'toString');
|
it('should stringify spy objects properly', function() {
|
||||||
var testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
var TestObject = {
|
||||||
|
someFunction: function() {}
|
||||||
|
};
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(testSpyObj)).toEqual(
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
'spy on TheClassName.toString'
|
currentSpies: function() {
|
||||||
);
|
return [];
|
||||||
|
},
|
||||||
|
createSpy: function(name, originalFn) {
|
||||||
|
return jasmineUnderTest.Spy(name, originalFn);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
spyRegistry.spyOn(TestObject, 'someFunction');
|
||||||
|
expect(pp(TestObject.someFunction)).toEqual('spy on someFunction');
|
||||||
|
|
||||||
|
expect(pp(env.createSpy('something'))).toEqual('spy on something');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should stringify spyOn toString properly', function() {
|
||||||
|
var TestObject = {
|
||||||
|
someFunction: function() {}
|
||||||
|
},
|
||||||
|
env = new jasmineUnderTest.Env(),
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
|
||||||
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() {
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
createSpy: function(name, originalFn) {
|
||||||
|
return jasmineUnderTest.Spy(name, originalFn);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
spyRegistry.spyOn(TestObject, 'toString');
|
||||||
|
var testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
||||||
|
|
||||||
|
expect(pp(testSpyObj)).toEqual('spy on TheClassName.toString');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects that implement jasmineToString', function() {
|
it('should stringify objects that implement jasmineToString', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
var obj = {
|
||||||
jasmineToString: function() {
|
jasmineToString: function() {
|
||||||
return 'strung';
|
return 'strung';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(obj)).toEqual('strung');
|
expect(pp(obj)).toEqual('strung');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass itself to jasmineToString', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter([]);
|
||||||
|
var obj = {
|
||||||
|
jasmineToString: jasmine.createSpy('jasmineToString').and.returnValue('')
|
||||||
|
};
|
||||||
|
|
||||||
|
pp(obj);
|
||||||
|
expect(obj.jasmineToString).toHaveBeenCalledWith(pp);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects that implement custom toString', function() {
|
it('should stringify objects that implement custom toString', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
var obj = {
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return 'my toString';
|
return 'my toString';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(obj)).toEqual('my toString');
|
expect(pp(obj)).toEqual('my toString');
|
||||||
|
|
||||||
// Simulate object from another global context (e.g. an iframe or Web Worker) that does not actually have a custom
|
// Simulate object from another global context (e.g. an iframe or Web Worker) that does not actually have a custom
|
||||||
// toString despite obj.toString !== Object.prototype.toString
|
// toString despite obj.toString !== Object.prototype.toString
|
||||||
@@ -403,20 +428,22 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(objFromOtherContext)).toEqual(
|
expect(pp(objFromOtherContext)).toEqual(
|
||||||
"Object({ foo: 'bar', toString: Function })"
|
"Object({ foo: 'bar', toString: Function })"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should stringify objects have have a toString that isn't a function", function() {
|
it("should stringify objects have have a toString that isn't a function", function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
var obj = {
|
||||||
toString: 'foo'
|
toString: 'foo'
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(obj)).toEqual("Object({ toString: 'foo' })");
|
expect(pp(obj)).toEqual("Object({ toString: 'foo' })");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects from anonymous constructors with custom toString', function() {
|
it('should stringify objects from anonymous constructors with custom toString', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var MyAnonymousConstructor = (function() {
|
var MyAnonymousConstructor = (function() {
|
||||||
return function() {};
|
return function() {};
|
||||||
})();
|
})();
|
||||||
@@ -426,17 +453,19 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
|
|
||||||
var a = new MyAnonymousConstructor();
|
var a = new MyAnonymousConstructor();
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(a)).toEqual('<anonymous>({ })');
|
expect(pp(a)).toEqual('<anonymous>({ })');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle objects with null prototype', function() {
|
it('should handle objects with null prototype', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = Object.create(null);
|
var obj = Object.create(null);
|
||||||
obj.foo = 'bar';
|
obj.foo = 'bar';
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(obj)).toEqual("null({ foo: 'bar' })");
|
expect(pp(obj)).toEqual("null({ foo: 'bar' })");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should gracefully handle objects with invalid toString implementations', function() {
|
it('should gracefully handle objects with invalid toString implementations', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
var obj = {
|
||||||
foo: {
|
foo: {
|
||||||
toString: function() {
|
toString: function() {
|
||||||
@@ -466,8 +495,72 @@ describe('jasmineUnderTest.pp', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(obj)).toEqual(
|
expect(pp(obj)).toEqual(
|
||||||
'Object({ foo: [object Number], bar: [object Object], baz: 3, qux: Error: bar, baddy: has-invalid-toString-method })'
|
'Object({ foo: [object Number], bar: [object Object], baz: 3, qux: Error: bar, baddy: has-invalid-toString-method })'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Custom object formatters', function() {
|
||||||
|
it('should use the first custom object formatter that does not return undefined', function() {
|
||||||
|
var customObjectFormatters = [
|
||||||
|
function(obj) {
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
function(obj) {
|
||||||
|
return '2nd: ' + obj.foo;
|
||||||
|
},
|
||||||
|
function(obj) {
|
||||||
|
return '3rd: ' + obj.foo;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(customObjectFormatters),
|
||||||
|
obj = { foo: 'bar' };
|
||||||
|
|
||||||
|
expect(pp(obj)).toEqual('2nd: bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fall back to built in logic if all custom object formatters return undefined', function() {
|
||||||
|
var customObjectFormatters = [
|
||||||
|
function(obj) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(customObjectFormatters),
|
||||||
|
obj = { foo: 'bar' };
|
||||||
|
|
||||||
|
expect(pp(obj)).toEqual("Object({ foo: 'bar' })");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customFormat_', function() {
|
||||||
|
it('should use the first custom object formatter that does not return undefined', function() {
|
||||||
|
var customObjectFormatters = [
|
||||||
|
function(obj) {
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
function(obj) {
|
||||||
|
return '2nd: ' + obj.foo;
|
||||||
|
},
|
||||||
|
function(obj) {
|
||||||
|
return '3rd: ' + obj.foo;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(customObjectFormatters),
|
||||||
|
obj = { foo: 'bar' };
|
||||||
|
|
||||||
|
expect(pp.customFormat_(obj)).toEqual('2nd: bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return undefined if all custom object formatters return undefined', function() {
|
||||||
|
var customObjectFormatters = [
|
||||||
|
function(obj) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(customObjectFormatters),
|
||||||
|
obj = { foo: 'bar' };
|
||||||
|
|
||||||
|
expect(pp.customFormat_(obj)).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -227,7 +227,8 @@ describe('Spec', function() {
|
|||||||
passedExpectations: [],
|
passedExpectations: [],
|
||||||
deprecationWarnings: [],
|
deprecationWarnings: [],
|
||||||
pendingReason: '',
|
pendingReason: '',
|
||||||
duration: null
|
duration: jasmine.any(Number),
|
||||||
|
properties: null
|
||||||
},
|
},
|
||||||
'things'
|
'things'
|
||||||
);
|
);
|
||||||
@@ -273,8 +274,34 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should report the duration of the test', function() {
|
it('should report the duration of the test', function() {
|
||||||
|
var timer = jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }),
|
||||||
|
spec = new jasmineUnderTest.Spec({
|
||||||
|
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||||
|
catchExceptions: function() {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
resultCallback: function(result) {
|
||||||
|
duration = result.duration;
|
||||||
|
},
|
||||||
|
queueRunnerFactory: function(config) {
|
||||||
|
config.queueableFns.forEach(function(qf) {
|
||||||
|
qf.fn();
|
||||||
|
});
|
||||||
|
config.cleanupFns.forEach(function(qf) {
|
||||||
|
qf.fn();
|
||||||
|
});
|
||||||
|
config.onComplete();
|
||||||
|
},
|
||||||
|
timer: timer
|
||||||
|
}),
|
||||||
|
duration = undefined;
|
||||||
|
|
||||||
|
spec.execute(function() {});
|
||||||
|
expect(duration).toBe(77000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should report properties set during the test', function() {
|
||||||
var done = jasmine.createSpy('done callback'),
|
var done = jasmine.createSpy('done callback'),
|
||||||
timer = jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }),
|
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||||
catchExceptions: function() {
|
catchExceptions: function() {
|
||||||
@@ -283,11 +310,11 @@ describe('Spec', function() {
|
|||||||
resultCallback: function() {},
|
resultCallback: function() {},
|
||||||
queueRunnerFactory: function(attrs) {
|
queueRunnerFactory: function(attrs) {
|
||||||
attrs.onComplete();
|
attrs.onComplete();
|
||||||
},
|
}
|
||||||
timer: timer
|
|
||||||
});
|
});
|
||||||
|
spec.setSpecProperty('a', 4);
|
||||||
spec.execute(done);
|
spec.execute(done);
|
||||||
expect(spec.result.duration).toBe(77000);
|
expect(spec.result.properties).toEqual({ a: 4 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#status returns passing by default', function() {
|
it('#status returns passing by default', function() {
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ describe('Spies', function() {
|
|||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
describe('createSpy', function() {
|
describe('createSpy', function() {
|
||||||
var TestClass;
|
var TestClass;
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ describe('SpyStrategy', function() {
|
|||||||
expect(originalFn).not.toHaveBeenCalled();
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows a non-Error to be thrown, wrapping it into an exception when executed', function() {
|
it('allows a string to be thrown, wrapping it into an exception when executed', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
var originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
@@ -82,6 +82,18 @@ describe('SpyStrategy', function() {
|
|||||||
expect(originalFn).not.toHaveBeenCalled();
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows a non-Error to be thrown when executed', function() {
|
||||||
|
var originalFn = jasmine.createSpy('original'),
|
||||||
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
|
spyStrategy.throwError({ code: 'ESRCH' });
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
spyStrategy.exec();
|
||||||
|
}).toThrow({ code: 'ESRCH' });
|
||||||
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('allows a fake function to be called instead', function() {
|
it('allows a fake function to be called instead', 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),
|
||||||
@@ -140,6 +152,28 @@ describe('SpyStrategy', function() {
|
|||||||
.catch(done.fail);
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows an empty resolved promise to be returned', function(done) {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var originalFn = jasmine.createSpy('original'),
|
||||||
|
getPromise = function() {
|
||||||
|
return Promise;
|
||||||
|
},
|
||||||
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
|
fn: originalFn,
|
||||||
|
getPromise: getPromise
|
||||||
|
});
|
||||||
|
|
||||||
|
spyStrategy.resolveTo();
|
||||||
|
spyStrategy
|
||||||
|
.exec()
|
||||||
|
.then(function(returnValue) {
|
||||||
|
expect(returnValue).toBe();
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
it('fails if promises are not available', function() {
|
it('fails if promises are not available', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
var originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
@@ -176,6 +210,29 @@ describe('SpyStrategy', function() {
|
|||||||
.catch(done.fail);
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows an empty rejected promise to be returned', function(done) {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var originalFn = jasmine.createSpy('original'),
|
||||||
|
getPromise = function() {
|
||||||
|
return Promise;
|
||||||
|
},
|
||||||
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
|
fn: originalFn,
|
||||||
|
getPromise: getPromise
|
||||||
|
});
|
||||||
|
|
||||||
|
spyStrategy.rejectWith();
|
||||||
|
spyStrategy
|
||||||
|
.exec()
|
||||||
|
.then(done.fail)
|
||||||
|
.catch(function(error) {
|
||||||
|
expect(error).toBe();
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
it('allows a non-Error to be rejected', function(done) {
|
it('allows a non-Error to be rejected', function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
|||||||
@@ -213,4 +213,46 @@ describe('StackTrace', function() {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('consideres different types of errors', function() {
|
||||||
|
var error = {
|
||||||
|
message: 'nope',
|
||||||
|
stack:
|
||||||
|
'TypeError: nope\n' +
|
||||||
|
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||||
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
|
expect(result.message).toEqual('TypeError: nope');
|
||||||
|
expect(result.frames).toEqual([
|
||||||
|
{
|
||||||
|
raw:
|
||||||
|
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||||
|
func: 'UserContext.<anonymous>',
|
||||||
|
file: 'http://localhost:8888/__spec__/core/UtilSpec.js',
|
||||||
|
line: 115
|
||||||
|
},
|
||||||
|
{
|
||||||
|
raw:
|
||||||
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)',
|
||||||
|
func: 'QueueRunner.run',
|
||||||
|
file: 'http://localhost:8888/__jasmine__/jasmine.js',
|
||||||
|
line: 4320
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
var no_error = {
|
||||||
|
message: 'nope',
|
||||||
|
stack:
|
||||||
|
'Type Error: nope\n' +
|
||||||
|
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||||
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
|
};
|
||||||
|
|
||||||
|
var result_no_error = new jasmineUnderTest.StackTrace(no_error);
|
||||||
|
|
||||||
|
expect(result_no_error.message).not.toEqual(jasmine.anything());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,28 +1,35 @@
|
|||||||
describe('Suite', function() {
|
describe('Suite', function() {
|
||||||
|
var env;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
env = new jasmineUnderTest.Env();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
it('keeps its id', function() {
|
it('keeps its id', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var suite = new jasmineUnderTest.Suite({
|
||||||
suite = new jasmineUnderTest.Suite({
|
env: env,
|
||||||
env: env,
|
id: 456,
|
||||||
id: 456,
|
description: 'I am a suite'
|
||||||
description: 'I am a suite'
|
});
|
||||||
});
|
|
||||||
|
|
||||||
expect(suite.id).toEqual(456);
|
expect(suite.id).toEqual(456);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns blank full name for top level suite', function() {
|
it('returns blank full name for top level suite', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var suite = new jasmineUnderTest.Suite({
|
||||||
suite = new jasmineUnderTest.Suite({
|
env: env,
|
||||||
env: env,
|
description: 'I am a suite'
|
||||||
description: 'I am a suite'
|
});
|
||||||
});
|
|
||||||
|
|
||||||
expect(suite.getFullName()).toEqual('');
|
expect(suite.getFullName()).toEqual('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns its full name when it has parent suites', function() {
|
it('returns its full name when it has parent suites', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var parentSuite = new jasmineUnderTest.Suite({
|
||||||
parentSuite = new jasmineUnderTest.Suite({
|
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a parent suite',
|
description: 'I am a parent suite',
|
||||||
parentSuite: jasmine.createSpy('pretend top level suite')
|
parentSuite: jasmine.createSpy('pretend top level suite')
|
||||||
@@ -37,8 +44,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds before functions in order of needed execution', function() {
|
it('adds before functions in order of needed execution', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var suite = new jasmineUnderTest.Suite({
|
||||||
suite = new jasmineUnderTest.Suite({
|
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a suite'
|
description: 'I am a suite'
|
||||||
}),
|
}),
|
||||||
@@ -52,8 +58,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds after functions in order of needed execution', function() {
|
it('adds after functions in order of needed execution', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var suite = new jasmineUnderTest.Suite({
|
||||||
suite = new jasmineUnderTest.Suite({
|
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a suite'
|
description: 'I am a suite'
|
||||||
}),
|
}),
|
||||||
@@ -115,13 +120,12 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls timer to compute duration', function() {
|
it('calls timer to compute duration', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var suite = new jasmineUnderTest.Suite({
|
||||||
suite = new jasmineUnderTest.Suite({
|
env: env,
|
||||||
env: env,
|
id: 456,
|
||||||
id: 456,
|
description: 'I am a suite',
|
||||||
description: 'I am a suite',
|
timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 })
|
||||||
timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 })
|
});
|
||||||
});
|
|
||||||
suite.startTimer();
|
suite.startTimer();
|
||||||
suite.endTimer();
|
suite.endTimer();
|
||||||
expect(suite.getResult().duration).toEqual(77000);
|
expect(suite.getResult().duration).toEqual(77000);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ describe('jasmineUnderTest.util', function() {
|
|||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
mockNativePromise = new Promise(function(res, rej) {});
|
mockNativePromise = new Promise(function(res, rej) {}); // eslint-disable-line compat/compat
|
||||||
mockPromiseLikeObject = new mockPromiseLike();
|
mockPromiseLikeObject = new mockPromiseLike();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
101
spec/core/asymmetricEqualityTesterArgCompatShimSpec.js
Normal file
101
spec/core/asymmetricEqualityTesterArgCompatShimSpec.js
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
describe('asymmetricEqualityTesterArgCompatShim', function() {
|
||||||
|
it('provides all the properties of the MatchersUtil', function() {
|
||||||
|
var matchersUtil = {
|
||||||
|
foo: function() {},
|
||||||
|
bar: function() {}
|
||||||
|
},
|
||||||
|
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||||
|
matchersUtil,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(shim.foo).toBe(matchersUtil.foo);
|
||||||
|
expect(shim.bar).toBe(matchersUtil.bar);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('provides all the properties of the customEqualityTesters', function() {
|
||||||
|
var customEqualityTesters = [function() {}, function() {}],
|
||||||
|
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||||
|
{},
|
||||||
|
customEqualityTesters
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(shim.length).toBe(2);
|
||||||
|
expect(shim[0]).toBe(customEqualityTesters[0]);
|
||||||
|
expect(shim[1]).toBe(customEqualityTesters[1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('provides all the properties of Array.prototype', function() {
|
||||||
|
var shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []);
|
||||||
|
|
||||||
|
expect(shim.filter).toBe(Array.prototype.filter);
|
||||||
|
expect(shim.forEach).toBe(Array.prototype.forEach);
|
||||||
|
expect(shim.map).toBe(Array.prototype.map);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('provides properties of Array.prototype', function() {
|
||||||
|
var keys = [
|
||||||
|
'concat',
|
||||||
|
'constructor',
|
||||||
|
'every',
|
||||||
|
'filter',
|
||||||
|
'forEach',
|
||||||
|
'indexOf',
|
||||||
|
'join',
|
||||||
|
'lastIndexOf',
|
||||||
|
'length',
|
||||||
|
'map',
|
||||||
|
'pop',
|
||||||
|
'push',
|
||||||
|
'reduce',
|
||||||
|
'reduceRight',
|
||||||
|
'reverse',
|
||||||
|
'shift',
|
||||||
|
'slice',
|
||||||
|
'some',
|
||||||
|
'sort',
|
||||||
|
'splice',
|
||||||
|
'toLocaleString',
|
||||||
|
'toString',
|
||||||
|
'unshift'
|
||||||
|
],
|
||||||
|
optionalKeys = [
|
||||||
|
'copyWithin',
|
||||||
|
'entries',
|
||||||
|
'fill',
|
||||||
|
'find',
|
||||||
|
'findIndex',
|
||||||
|
'flat',
|
||||||
|
'flatMap',
|
||||||
|
'includes',
|
||||||
|
'keys',
|
||||||
|
'toSource',
|
||||||
|
'values'
|
||||||
|
],
|
||||||
|
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []),
|
||||||
|
i,
|
||||||
|
k;
|
||||||
|
|
||||||
|
// Properties that are present on all supported runtimes
|
||||||
|
for (i = 0; i < keys.length; i++) {
|
||||||
|
k = keys[i];
|
||||||
|
expect(shim[k])
|
||||||
|
.withContext(k)
|
||||||
|
.not.toBeUndefined();
|
||||||
|
expect(shim[k])
|
||||||
|
.withContext(k)
|
||||||
|
.toBe(Array.prototype[k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Properties that are present on only some supported runtimes
|
||||||
|
for (i = 0; i < optionalKeys.length; i++) {
|
||||||
|
k = optionalKeys[i];
|
||||||
|
|
||||||
|
if (shim[k] !== undefined) {
|
||||||
|
expect(shim[k])
|
||||||
|
.withContext(k)
|
||||||
|
.toBe(Array.prototype[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -34,7 +34,7 @@ describe("Any", function() {
|
|||||||
|
|
||||||
var any = new jasmineUnderTest.Any(Map);
|
var any = new jasmineUnderTest.Any(Map);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Map())).toBe(true);
|
expect(any.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Set", function() {
|
it("matches a Set", function() {
|
||||||
@@ -42,23 +42,23 @@ describe("Any", function() {
|
|||||||
|
|
||||||
var any = new jasmineUnderTest.Any(Set);
|
var any = new jasmineUnderTest.Any(Set);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Set())).toBe(true);
|
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);
|
var any = new jasmineUnderTest.Any(Uint32Array); // eslint-disable-line compat/compat
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
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);
|
var any = new jasmineUnderTest.Any(Symbol); // eslint-disable-line compat/compat
|
||||||
|
|
||||||
expect(any.asymmetricMatch(Symbol())).toBe(true);
|
expect(any.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches another constructed object", function() {
|
it("matches another constructed object", function() {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ describe("Anything", function() {
|
|||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(new Map())).toBe(true);
|
expect(anything.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Set", function() {
|
it("matches a Set", function() {
|
||||||
@@ -36,7 +36,7 @@ describe("Anything", function() {
|
|||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(new Set())).toBe(true);
|
expect(anything.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a TypedArray", function() {
|
it("matches a TypedArray", function() {
|
||||||
@@ -44,7 +44,7 @@ describe("Anything", function() {
|
|||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a Symbol", function() {
|
it("matches a Symbol", function() {
|
||||||
@@ -52,7 +52,7 @@ describe("Anything", function() {
|
|||||||
|
|
||||||
var anything = new jasmineUnderTest.Anything();
|
var anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(Symbol())).toBe(true);
|
expect(anything.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't match undefined", function() {
|
it("doesn't match undefined", function() {
|
||||||
|
|||||||
@@ -15,32 +15,41 @@ describe("ArrayContaining", function() {
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["foo"])).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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["foo", "bar"])).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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["bar"])).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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch("foo")).toBe(false);
|
expect(containing.asymmetricMatch("foo", matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToStrings itself", function() {
|
it("jasmineToStrings itself", function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining([]);
|
var sample = [],
|
||||||
|
matcher = new jasmineUnderTest.ArrayContaining(sample),
|
||||||
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
|
expect(matcher.jasmineToString(pp)).toEqual(
|
||||||
|
'<jasmine.arrayContaining(sample)>'
|
||||||
|
);
|
||||||
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom equality testers", function() {
|
it("uses custom equality testers", function() {
|
||||||
@@ -52,7 +61,8 @@ describe("ArrayContaining", function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
|
var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(["fooBar"], [tester])).toBe(true);
|
expect(containing.asymmetricMatch(["fooBar"], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
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();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch([2, 'a', /a/])).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() {
|
||||||
@@ -15,21 +16,28 @@ describe("ArrayWithExactContents", function() {
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||||
expect(matcher.asymmetricMatch(['a', 2, undefined])).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();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToStrings itself", function() {
|
it("jasmineToStrings itself", function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents([]);
|
var sample = [],
|
||||||
|
matcher = new jasmineUnderTest.ArrayWithExactContents(sample),
|
||||||
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
expect(matcher.jasmineToString()).toMatch("<jasmine.arrayWithExactContents");
|
expect(matcher.jasmineToString(pp)).toEqual(
|
||||||
|
'<jasmine.arrayWithExactContents(sample)>'
|
||||||
|
);
|
||||||
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom equality testers", function() {
|
it("uses custom equality testers", function() {
|
||||||
@@ -41,7 +49,8 @@ describe("ArrayWithExactContents", function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(["fooVal"]);
|
var matcher = new jasmineUnderTest.ArrayWithExactContents(["fooVal"]);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(["fooBar"], [tester])).toBe(true);
|
expect(matcher.asymmetricMatch(["fooBar"], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,20 +24,20 @@ describe("Empty", function () {
|
|||||||
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();
|
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||||
fullMap.set('thing', 2);
|
fullMap.set('thing', 2);
|
||||||
|
|
||||||
expect(empty.asymmetricMatch(new Map())).toBe(true);
|
expect(empty.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||||
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();
|
var fullSet = new Set(); // eslint-disable-line compat/compat
|
||||||
fullSet.add(3);
|
fullSet.add(3);
|
||||||
|
|
||||||
expect(empty.asymmetricMatch(new Set())).toBe(true);
|
expect(empty.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||||
expect(empty.asymmetricMatch(fullSet)).toBe(false);
|
expect(empty.asymmetricMatch(fullSet)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ describe("Empty", function () {
|
|||||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||||
var empty = new jasmineUnderTest.Empty();
|
var empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
|
expect(empty.asymmetricMatch(new Int16Array())).toBe(true); // eslint-disable-line compat/compat
|
||||||
expect(empty.asymmetricMatch(new Int16Array([1,2]))).toBe(false);
|
expect(empty.asymmetricMatch(new Int16Array([1,2]))).toBe(false); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* 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();
|
||||||
@@ -31,8 +32,9 @@ describe('MapContaining', function() {
|
|||||||
['foo', [1, 2, 3]],
|
['foo', [1, 2, 3]],
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a key is not in actual', function() {
|
it('does not match when a key is not in actual', function() {
|
||||||
@@ -46,8 +48,9 @@ describe('MapContaining', function() {
|
|||||||
['foo', [1, 2, 3]],
|
['foo', [1, 2, 3]],
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value is not in actual', function() {
|
it('does not match when a value is not in actual', function() {
|
||||||
@@ -61,8 +64,9 @@ describe('MapContaining', function() {
|
|||||||
['foo', [1, 2]],
|
['foo', [1, 2]],
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches when all the key/value pairs in sample have asymmetric matches in actual', function() {
|
it('matches when all the key/value pairs in sample have asymmetric matches in actual', function() {
|
||||||
@@ -74,17 +78,18 @@ describe('MapContaining', function() {
|
|||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([
|
||||||
[
|
[
|
||||||
jasmine.stringMatching(/^foo\d/),
|
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||||
'bar'
|
'bar'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'baz',
|
'baz',
|
||||||
jasmine.arrayContaining([2, 3])
|
jasmineUnderTest.arrayContaining([2, 3])
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
||||||
@@ -95,17 +100,18 @@ describe('MapContaining', function() {
|
|||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([
|
||||||
[
|
[
|
||||||
jasmine.stringMatching(/^foo\d/),
|
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||||
'bar'
|
'bar'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'baz',
|
'baz',
|
||||||
jasmine.arrayContaining([2, 3])
|
jasmineUnderTest.arrayContaining([2, 3])
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
||||||
@@ -116,17 +122,18 @@ describe('MapContaining', function() {
|
|||||||
|
|
||||||
var containingMap = new MapI([
|
var containingMap = new MapI([
|
||||||
[
|
[
|
||||||
jasmine.stringMatching(/^foo\d/),
|
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||||
'bar'
|
'bar'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'baz',
|
'baz',
|
||||||
jasmine.arrayContaining([4, 5])
|
jasmineUnderTest.arrayContaining([4, 5])
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches recursively', function() {
|
it('matches recursively', function() {
|
||||||
@@ -147,8 +154,9 @@ describe('MapContaining', function() {
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses custom equality testers', function() {
|
it('uses custom equality testers', function() {
|
||||||
@@ -158,8 +166,9 @@ describe('MapContaining', function() {
|
|||||||
}
|
}
|
||||||
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(new MapI([['foo', -2]]));
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, [tester])).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() {
|
||||||
@@ -176,8 +185,13 @@ describe('MapContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('defines a `jasmineToString` method', function() {
|
it('defines a `jasmineToString` method', function() {
|
||||||
var containing = new jasmineUnderTest.MapContaining(new Map());
|
var sample = new Map(),
|
||||||
|
containing = new jasmineUnderTest.MapContaining(sample),
|
||||||
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
expect(containing.jasmineToString()).toMatch(/^<jasmine\.mapContaining/);
|
expect(containing.jasmineToString(pp)).toEqual(
|
||||||
|
'<jasmine.mapContaining(sample)>'
|
||||||
|
);
|
||||||
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ describe("NotEmpty", function () {
|
|||||||
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();
|
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||||
fullMap.set('one', 1);
|
fullMap.set('one', 1);
|
||||||
var emptyMap = new Map();
|
var emptyMap = new Map(); // eslint-disable-line compat/compat
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
|
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
||||||
@@ -35,9 +35,9 @@ describe("NotEmpty", function () {
|
|||||||
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();
|
var filledSet = new Set(); // eslint-disable-line compat/compat
|
||||||
filledSet.add(1);
|
filledSet.add(1);
|
||||||
var emptySet = new Set();
|
var emptySet = new Set(); // eslint-disable-line compat/compat
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
|
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
|
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
|
||||||
@@ -47,7 +47,7 @@ describe("NotEmpty", 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);
|
expect(notEmpty.asymmetricMatch(new Int16Array([1,2,3]))).toBe(true); // eslint-disable-line compat/compat
|
||||||
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false);
|
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,18 @@
|
|||||||
describe("ObjectContaining", function() {
|
describe("ObjectContaining", function() {
|
||||||
|
|
||||||
it("matches any actual to an empty object", function() {
|
it("matches any object actual to an empty object", function() {
|
||||||
|
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
|
expect(containing.asymmetricMatch({foo: 1}, matchersUtil)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not match when the actual is not an object", function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch("foo")).toBe(true);
|
[1, true, undefined, "a string"].forEach(function(actual) {
|
||||||
|
expect(containing.asymmetricMatch(actual)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not match an empty object actual", function() {
|
it("does not match an empty object actual", function() {
|
||||||
@@ -16,58 +25,72 @@ describe("ObjectContaining", function() {
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"})).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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(false);
|
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"}, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
var sample = {},
|
||||||
|
matcher = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
|
expect(matcher.jasmineToString(pp)).toEqual(
|
||||||
|
'<jasmine.objectContaining(sample)>'
|
||||||
|
);
|
||||||
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
|
|
||||||
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({one: {two: {}}})).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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({ one: undefined })).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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({})).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 definedPropertyObject = {};
|
var definedPropertyObject = {};
|
||||||
Object.defineProperty(definedPropertyObject, "foo", {
|
Object.defineProperty(definedPropertyObject, "foo", {
|
||||||
get: function() { return "fooVal" }
|
get: function() { return "fooVal" }
|
||||||
});
|
});
|
||||||
expect(containing.asymmetricMatch(definedPropertyObject)).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 prototypeObject = {foo: "fooVal"};
|
var prototypeObject = {foo: "fooVal"};
|
||||||
var obj;
|
var obj;
|
||||||
@@ -81,7 +104,7 @@ describe("ObjectContaining", function() {
|
|||||||
obj = new Foo();
|
obj = new Foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(obj)).toBe(true);
|
expect(containing.asymmetricMatch(obj, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom equality testers", function() {
|
it("uses custom equality testers", function() {
|
||||||
@@ -93,7 +116,70 @@ describe("ObjectContaining", function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({foo: "fooBar"}, [tester])).toBe(true);
|
expect(containing.asymmetricMatch({foo: "fooBar"}, matchersUtil)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("valuesForDiff_", function() {
|
||||||
|
describe("when other is not an object", function() {
|
||||||
|
it("sets self to jasmineToString()", function () {
|
||||||
|
var containing = new jasmineUnderTest.ObjectContaining({}),
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
|
result = containing.valuesForDiff_('a', pp);
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
self: '<jasmine.objectContaining(Object({ }))>',
|
||||||
|
other: 'a'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when other is an object", function() {
|
||||||
|
it("includes keys that are present in both other and sample", function() {
|
||||||
|
var sample = {a: 1, b: 2},
|
||||||
|
other = {a: 3, b: 4},
|
||||||
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
|
result = containing.valuesForDiff_(other);
|
||||||
|
|
||||||
|
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
||||||
|
expect(result).toEqual({
|
||||||
|
self: sample,
|
||||||
|
other: other
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("includes keys that are present only in sample", function() {
|
||||||
|
var sample = {a: 1, b: 2},
|
||||||
|
other = {a: 3},
|
||||||
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
|
result = containing.valuesForDiff_(other);
|
||||||
|
|
||||||
|
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
||||||
|
expect(containing.valuesForDiff_(other)).toEqual({
|
||||||
|
self: sample,
|
||||||
|
other: {
|
||||||
|
a: 3,
|
||||||
|
b: undefined
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("omits keys that are present only in other", function() {
|
||||||
|
var sample = {a: 1, b: 2},
|
||||||
|
other = {a: 3, b: 4, c: 5},
|
||||||
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
|
result = containing.valuesForDiff_(other);
|
||||||
|
|
||||||
|
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
||||||
|
expect(result).toEqual({
|
||||||
|
self: sample,
|
||||||
|
other: {
|
||||||
|
a: 3,
|
||||||
|
b: 4
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* 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();
|
||||||
@@ -28,8 +29,9 @@ describe('SetContaining', function() {
|
|||||||
[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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value is not in actual', function() {
|
it('does not match when a value is not in actual', function() {
|
||||||
@@ -41,8 +43,9 @@ describe('SetContaining', function() {
|
|||||||
[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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet)).toBe(false);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
||||||
@@ -51,12 +54,13 @@ describe('SetContaining', function() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
var containingSet = new SetI([
|
var containingSet = new SetI([
|
||||||
jasmine.stringMatching(/^foo\d/),
|
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||||
jasmine.arrayContaining([2, 3]),
|
jasmineUnderTest.arrayContaining([2, 3]),
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
||||||
@@ -69,8 +73,9 @@ describe('SetContaining', function() {
|
|||||||
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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet)).toBe(false);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches recursively', function() {
|
it('matches recursively', function() {
|
||||||
@@ -82,8 +87,9 @@ describe('SetContaining', function() {
|
|||||||
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();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses custom equality testers', function() {
|
it('uses custom equality testers', function() {
|
||||||
@@ -93,8 +99,9 @@ describe('SetContaining', function() {
|
|||||||
}
|
}
|
||||||
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]});
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet, [tester])).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() {
|
||||||
@@ -111,8 +118,13 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('defines a `jasmineToString` method', function() {
|
it('defines a `jasmineToString` method', function() {
|
||||||
var containing = new jasmineUnderTest.SetContaining(new Set());
|
var sample = new Set(),
|
||||||
|
containing = new jasmineUnderTest.SetContaining(sample),
|
||||||
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
expect(containing.jasmineToString()).toMatch(/^<jasmine\.setContaining/);
|
expect(containing.jasmineToString(pp)).toEqual(
|
||||||
|
'<jasmine.setContaining(sample)>'
|
||||||
|
);
|
||||||
|
expect(pp).toHaveBeenCalledWith(sample);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,4 +30,36 @@ describe('base helpers', function() {
|
|||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isAsymmetricEqualityTester_', function() {
|
||||||
|
it('returns false when the argument is falsy', function() {
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(null)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when the argument does not have a asymmetricMatch property', function() {
|
||||||
|
var obj = {};
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns false when the argument's asymmetricMatch is not a function", function() {
|
||||||
|
var obj = { asymmetricMatch: 'yes' };
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns true when the argument's asymmetricMatch is a function", function() {
|
||||||
|
var obj = { asymmetricMatch: function() {} };
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isSet', function() {
|
||||||
|
it('returns true when the object is a Set', function() {
|
||||||
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
expect(jasmineUnderTest.isSet(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when the object is not a Set', function() {
|
||||||
|
expect(jasmineUnderTest.isSet({})).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
222
spec/core/integration/AsymmetricEqualityTestersSpec.js
Normal file
222
spec/core/integration/AsymmetricEqualityTestersSpec.js
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
describe('Asymmetric equality testers (Integration)', function () {
|
||||||
|
function verifyPasses(expectations, setup) {
|
||||||
|
it('passes', function (done) {
|
||||||
|
var env = new jasmineUnderTest.Env();
|
||||||
|
env.it('a spec', function () {
|
||||||
|
expectations(env);
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function (result) {
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
|
expect(result.passedExpectations.length)
|
||||||
|
.withContext('Number of passed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(0);
|
||||||
|
expect(result.failedExpectations[0] && result.failedExpectations[0].message)
|
||||||
|
.withContext('Failure message')
|
||||||
|
.toBeUndefined();
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function verifyFails(expectations) {
|
||||||
|
it('fails', function (done) {
|
||||||
|
var env = new jasmineUnderTest.Env();
|
||||||
|
env.it('a spec', function () {
|
||||||
|
expectations(env);
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function (result) {
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message)
|
||||||
|
.withContext('Failed with a thrown error rather than a matcher failure')
|
||||||
|
.not.toMatch(/^Error: /);
|
||||||
|
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
||||||
|
.not.toEqual('');
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('any', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.expect(5).toEqual(jasmineUnderTest.any(Number));
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect("five").toEqual(jasmineUnderTest.any(Number));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('anything', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.expect('').toEqual(jasmineUnderTest.anything());
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect(null).toEqual(jasmineUnderTest.anything());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('arrayContaining', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.addCustomEqualityTester(function (a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
env.expect([1, 2, 3]).toEqual(jasmineUnderTest.arrayContaining(["2"]));
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect(null).toEqual(jasmineUnderTest.arrayContaining([2]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('arrayWithExactContents', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.addCustomEqualityTester(function (a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
env.expect([1, 2]).toEqual(jasmineUnderTest.arrayWithExactContents(["2", "1"]));
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect([]).toEqual(jasmineUnderTest.arrayWithExactContents([2]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('empty', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.expect([]).toEqual(jasmineUnderTest.empty());
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect([1]).toEqual(jasmineUnderTest.empty());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('falsy', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.expect(false).toEqual(jasmineUnderTest.falsy());
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect(true).toEqual(jasmineUnderTest.falsy());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('mapContaining', function () {
|
||||||
|
if (jasmine.getEnv().hasFunctioningMaps()) {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
var actual = new Map();
|
||||||
|
actual.set('a', "2");
|
||||||
|
var expected = new Map();
|
||||||
|
expected.set('a', 2);
|
||||||
|
|
||||||
|
env.addCustomEqualityTester(function (a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.expect(actual).toEqual(jasmineUnderTest.mapContaining(expected));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
it('passes', function() {
|
||||||
|
jasmine.getEnv().pending('Browser has incomplete or missing support for Maps');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jasmine.getEnv().hasFunctioningMaps()) {
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect('something').toEqual(jasmineUnderTest.mapContaining(new Map()));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
it('fails', function() {
|
||||||
|
jasmine.getEnv().pending('Browser has incomplete or missing support for Maps');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('notEmpty', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.expect([1]).toEqual(jasmineUnderTest.notEmpty());
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect([]).toEqual(jasmineUnderTest.notEmpty());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('objectContaining', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.addCustomEqualityTester(function (a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.expect({a: 1, b: 2}).toEqual(jasmineUnderTest.objectContaining({a: "1"}));
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect({}).toEqual(jasmineUnderTest.objectContaining({a: "1"}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setContaining', function () {
|
||||||
|
if (jasmine.getEnv().hasFunctioningSets()) {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
var actual = new Set();
|
||||||
|
actual.add("1");
|
||||||
|
var expected = new Set();
|
||||||
|
actual.add(1);
|
||||||
|
|
||||||
|
env.addCustomEqualityTester(function (a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.expect(actual).toEqual(jasmineUnderTest.setContaining(expected));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
it('pases', function() {
|
||||||
|
jasmine.getEnv().pending('Browser has incomplete or missing support for Sets');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jasmine.getEnv().hasFunctioningSets()) {
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect('something').toEqual(jasmineUnderTest.setContaining(new Set()));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
it('fails', function() {
|
||||||
|
jasmine.getEnv().pending('Browser has incomplete or missing support for Sets');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('stringMatching', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.expect('foo').toEqual(jasmineUnderTest.stringMatching(/o/));
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect('bar').toEqual(jasmineUnderTest.stringMatching(/o/));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('truthy', function () {
|
||||||
|
verifyPasses(function (env) {
|
||||||
|
env.expect(true).toEqual(jasmineUnderTest.truthy());
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function (env) {
|
||||||
|
env.expect(false).toEqual(jasmineUnderTest.truthy());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
describe('Custom Async Matchers (Integration)', function() {
|
describe('Custom Async Matchers (Integration)', function() {
|
||||||
var env;
|
var env;
|
||||||
|
|
||||||
@@ -6,6 +7,10 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
env.configure({random: false});
|
env.configure({random: false});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
it('passes the spec if the custom async matcher passes', function(done) {
|
it('passes the spec if the custom async matcher passes', function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
@@ -75,4 +80,72 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: remove this in the next major release.
|
||||||
|
it("passes the jasmine utility and current equality testers to the matcher factory", function(done) {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var matcherFactory = function () {
|
||||||
|
return {
|
||||||
|
compare: function () {
|
||||||
|
return Promise.resolve({pass: true});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy").and.callFake(matcherFactory),
|
||||||
|
customEqualityFn = function () {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
env.it("spec with expectation", function() {
|
||||||
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
|
env.addAsyncMatchers({
|
||||||
|
toBeReal: matcherFactorySpy
|
||||||
|
});
|
||||||
|
|
||||||
|
return env.expectAsync(true).toBeReal();
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function() {
|
||||||
|
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||||
|
jasmine.any(jasmineUnderTest.MatchersUtil),
|
||||||
|
[customEqualityFn]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides custom equality testers to the matcher factory via matchersUtil", function(done) {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var matcherFactory = function (matchersUtil) {
|
||||||
|
return {
|
||||||
|
compare: function (actual, expected) {
|
||||||
|
return Promise.resolve({pass: matchersUtil.equals(actual[0], expected)});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
customEqualityFn = jasmine.createSpy("customEqualityFn").and.callFake(function (a, b) {
|
||||||
|
return a.toString() === b;
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it("spec with expectation", function() {
|
||||||
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
|
env.addAsyncMatchers({
|
||||||
|
toBeArrayWithFirstElement: matcherFactory
|
||||||
|
});
|
||||||
|
|
||||||
|
return env.expectAsync([1, 2]).toBeArrayWithFirstElement("1");
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function(result) {
|
||||||
|
expect(customEqualityFn).toHaveBeenCalledWith(1, "1");
|
||||||
|
expect(result.failedExpectations).toEqual([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
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});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows adding more matchers local to a spec", function(done) {
|
afterEach(function() {
|
||||||
env.it('spec defining a custom matcher', function() {
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows adding more matchers local to a spec", function (done) {
|
||||||
|
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};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +85,36 @@ describe("Custom Matchers (Integration)", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("supports asymmetric equality testers that take a list of custom equality testers", function(done) {
|
||||||
|
// TODO: remove this in the next major release.
|
||||||
|
spyOn(jasmineUnderTest, 'getEnv').and.returnValue(env);
|
||||||
|
|
||||||
|
env.it("spec using custom asymmetric equality tester", function() {
|
||||||
|
var customEqualityFn = function(a, b) {
|
||||||
|
if (a === 2 && b === "two") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var arrayWithFirstElement = function(sample) {
|
||||||
|
return {
|
||||||
|
asymmetricMatch: function (actual, customEqualityTesters) {
|
||||||
|
return jasmineUnderTest.matchersUtil.equals(sample, actual[0], customEqualityTesters);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
|
env.expect(["two"]).toEqual(arrayWithFirstElement(2));
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function(result) {
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
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) {
|
||||||
@@ -175,26 +209,60 @@ describe("Custom Matchers (Integration)", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) {
|
// TODO: remove this in the next major release.
|
||||||
|
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() { return { compare: function() { return {pass: true}; }}; },
|
||||||
argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
|
matcherFactorySpy = jasmine.createSpy("matcherFactorySpy").and.callFake(matcherFactory),
|
||||||
customEqualityFn = function() { return true; };
|
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: argumentSpy
|
toBeReal: matcherFactorySpy
|
||||||
});
|
});
|
||||||
|
|
||||||
env.expect(true).toBeReal();
|
env.expect(true).toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function() {
|
var specExpectations = function() {
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(jasmineUnderTest.matchersUtil, [customEqualityFn]);
|
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||||
|
jasmine.any(jasmineUnderTest.MatchersUtil),
|
||||||
|
[customEqualityFn]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("provides custom equality testers to the matcher factory via matchersUtil", function (done) {
|
||||||
|
var matcherFactory = function (matchersUtil) {
|
||||||
|
return {
|
||||||
|
compare: function (actual, expected) {
|
||||||
|
return {pass: matchersUtil.equals(actual[0], expected)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
customEqualityFn = jasmine.createSpy("customEqualityFn").and.callFake(function (a, b) {
|
||||||
|
return a.toString() === b;
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it("spec with expectation", function () {
|
||||||
|
env.addCustomEqualityTester(customEqualityFn);
|
||||||
|
env.addMatchers({
|
||||||
|
toBeArrayWithFirstElement: matcherFactory
|
||||||
|
});
|
||||||
|
|
||||||
|
env.expect([1, 2]).toBeArrayWithFirstElement("1");
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function (result) {
|
||||||
|
expect(customEqualityFn).toHaveBeenCalledWith(1, "1");
|
||||||
|
expect(result.failedExpectations).toEqual([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
67
spec/core/integration/CustomObjectFormatterSpec.js
Normal file
67
spec/core/integration/CustomObjectFormatterSpec.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
describe("Custom object formatters", function() {
|
||||||
|
var env;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
env = new jasmineUnderTest.Env();
|
||||||
|
env.configure({random: false});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("scopes custom object formatters to a spec", function(done) {
|
||||||
|
env.it('a spec with custom pretty-printer', function() {
|
||||||
|
env.addCustomObjectFormatter(function(obj) { return 'custom(' + obj + ')'; });
|
||||||
|
env.expect(42).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it('a spec without custom pretty-printer', function() {
|
||||||
|
env.expect(42).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
var specResults = [];
|
||||||
|
var specDone = function(result) {
|
||||||
|
specResults.push(result);
|
||||||
|
};
|
||||||
|
var expectations = function() {
|
||||||
|
expect(specResults[0].failedExpectations[0].message).toEqual("Expected custom(42) to be undefined.");
|
||||||
|
expect(specResults[1].failedExpectations[0].message).toEqual("Expected 42 to be undefined.");
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
env.addReporter({ specDone:specDone, jasmineDone: expectations});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("scopes custom object formatters to a suite", function(done) {
|
||||||
|
env.it('a spec without custom pretty-printer', function() {
|
||||||
|
env.expect(42).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.describe('with custom pretty-printer', function() {
|
||||||
|
env.beforeEach(function() {
|
||||||
|
env.addCustomObjectFormatter(function(obj) { return 'custom(' + obj + ')'; });
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it('a spec', function() {
|
||||||
|
env.expect(42).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var specResults = [];
|
||||||
|
var specDone = function(result) {
|
||||||
|
specResults.push(result);
|
||||||
|
};
|
||||||
|
var expectations = function() {
|
||||||
|
expect(specResults[0].failedExpectations[0].message).toEqual("Expected 42 to be undefined.");
|
||||||
|
expect(specResults[1].failedExpectations[0].message).toEqual("Expected custom(42) to be undefined.");
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
env.addReporter({ specDone:specDone, jasmineDone: expectations});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws an exception if you try to add a custom object formatter outside a runable", function() {
|
||||||
|
expect(function() {
|
||||||
|
env.addCustomObjectFormatter(function() {});
|
||||||
|
}).toThrowError('Custom object formatters must be added in a before function or a spec')
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -6,6 +6,10 @@ describe('Custom Spy Strategies (Integration)', function() {
|
|||||||
env.configure({random: false});
|
env.configure({random: false});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ describe('Default Spy Strategy (Integration)', function() {
|
|||||||
env.configure({random: false});
|
env.configure({random: false});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
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() {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,16 @@
|
|||||||
describe('Matchers (Integration)', function() {
|
describe('Matchers (Integration)', function() {
|
||||||
|
var env;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
env = new jasmineUnderTest.Env();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
function verifyPasses(expectations) {
|
function verifyPasses(expectations) {
|
||||||
it('passes', function(done) {
|
it('passes', function(done) {
|
||||||
var env = new jasmineUnderTest.Env();
|
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
@@ -26,7 +35,6 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
function verifyFails(expectations) {
|
function verifyFails(expectations) {
|
||||||
it('fails', function(done) {
|
it('fails', function(done) {
|
||||||
var env = new jasmineUnderTest.Env();
|
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
@@ -39,6 +47,9 @@ describe('Matchers (Integration)', function() {
|
|||||||
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)
|
||||||
|
.withContext('Failed with a thrown type error rather than a matcher failure')
|
||||||
|
.not.toMatch(/^TypeError: /);
|
||||||
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
||||||
.not.toEqual('');
|
.not.toEqual('');
|
||||||
};
|
};
|
||||||
@@ -48,10 +59,30 @@ describe('Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function verifyFailsWithCustomObjectFormatters(config) {
|
||||||
|
it('uses custom object formatters', function(done) {
|
||||||
|
env.it('a spec', function () {
|
||||||
|
env.addCustomObjectFormatter(config.formatter);
|
||||||
|
config.expectations(env);
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function (result) {
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message)
|
||||||
|
.toEqual(config.expectedMessage);
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function verifyPassesAsync(expectations) {
|
function verifyPassesAsync(expectations) {
|
||||||
it('passes', function(done) {
|
it('passes', function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
var env = new jasmineUnderTest.Env();
|
|
||||||
|
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
return expectations(env);
|
return expectations(env);
|
||||||
@@ -77,7 +108,6 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
function verifyFailsAsync(expectations) {
|
function verifyFailsAsync(expectations) {
|
||||||
it('fails', function(done) {
|
it('fails', function(done) {
|
||||||
var env = new jasmineUnderTest.Env();
|
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
@@ -101,6 +131,30 @@ describe('Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function verifyFailsWithCustomObjectFormattersAsync(config) {
|
||||||
|
it('uses custom object formatters', function(done) {
|
||||||
|
var env = new jasmineUnderTest.Env();
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
env.it('a spec', function () {
|
||||||
|
env.addCustomObjectFormatter(config.formatter);
|
||||||
|
return config.expectations(env);
|
||||||
|
});
|
||||||
|
|
||||||
|
var specExpectations = function (result) {
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations.length)
|
||||||
|
.withContext('Number of failed expectations')
|
||||||
|
.toEqual(1);
|
||||||
|
expect(result.failedExpectations[0].message)
|
||||||
|
.toEqual(config.expectedMessage);
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({specDone: specExpectations, jasmineDone: done});
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
describe('nothing', function() {
|
describe('nothing', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect().nothing();
|
env.expect().nothing();
|
||||||
@@ -217,6 +271,16 @@ describe('Matchers (Integration)', function() {
|
|||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(2).toBeNaN();
|
env.expect(2).toBeNaN();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
env.expect(1).toBeNaN();
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected |1| to be NaN.'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeNegativeInfinity', function() {
|
describe('toBeNegativeInfinity', function() {
|
||||||
@@ -227,6 +291,16 @@ describe('Matchers (Integration)', function() {
|
|||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(2).toBeNegativeInfinity();
|
env.expect(2).toBeNegativeInfinity();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
env.expect(1).toBeNegativeInfinity();
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected |1| to be -Infinity.'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeNull', function() {
|
describe('toBeNull', function() {
|
||||||
@@ -247,55 +321,104 @@ describe('Matchers (Integration)', function() {
|
|||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(2).toBePositiveInfinity();
|
env.expect(2).toBePositiveInfinity();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
env.expect(1).toBePositiveInfinity();
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected |1| to be Infinity.'
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeResolved', function() {
|
describe('toBeResolved', function() {
|
||||||
verifyPassesAsync(function(env) {
|
verifyPassesAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeResolved();
|
return env.expectAsync(Promise.resolve()).toBeResolved(); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.reject()).toBeResolved();
|
return env.expectAsync(Promise.reject()).toBeResolved(); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeResolvedTo', function() {
|
describe('toBeResolvedTo', function() {
|
||||||
verifyPassesAsync(function(env) {
|
verifyPassesAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('foo');
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
return env.expectAsync(Promise.resolve('5')).toBeResolvedTo(5); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('bar');
|
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('bar'); // eslint-disable-line compat/compat
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormattersAsync({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
return env.expectAsync(Promise.resolve('x')).toBeResolvedTo('y'); // eslint-disable-line compat/compat
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected a promise to be resolved to |y| ' +
|
||||||
|
'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();
|
return env.expectAsync(Promise.reject('nope')).toBeRejected(); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeRejected();
|
return env.expectAsync(Promise.resolve()).toBeRejected(); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeRejectedWith', function() {
|
describe('toBeRejectedWith', function() {
|
||||||
verifyPassesAsync(function(env) {
|
verifyPassesAsync(function(env) {
|
||||||
return env.expectAsync(Promise.reject('nope')).toBeRejectedWith('nope');
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
return env.expectAsync(Promise.reject('5')).toBeRejectedWith(5); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeRejectedWith('nope');
|
return env.expectAsync(Promise.resolve()).toBeRejectedWith('nope'); // eslint-disable-line compat/compat
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormattersAsync({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
return env.expectAsync(Promise.reject('x')).toBeRejectedWith('y'); // eslint-disable-line compat/compat
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected a promise to be rejected with |y| ' +
|
||||||
|
'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);
|
return env.expectAsync(Promise.reject(new Error())).toBeRejectedWithError(Error); // eslint-disable-line compat/compat
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error);
|
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error); // eslint-disable-line compat/compat
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormattersAsync({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
return env.expectAsync(Promise.reject('foo')).toBeRejectedWithError('foo'); // eslint-disable-line compat/compat
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected a promise to be rejected with Error: |foo| ' +
|
||||||
|
'but it was rejected with |foo|.'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -331,7 +454,10 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
describe('toContain', function() {
|
describe('toContain', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect('foobar').toContain('oo');
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
env.expect(['1', '2', '3']).toContain(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
@@ -341,12 +467,39 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
describe('toEqual', function() {
|
describe('toEqual', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect('a').toEqual('a');
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
env.expect(5).toEqual('5');
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect('a').toEqual('b');
|
env.expect('a').toEqual('b');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
if (val === 5) {
|
||||||
|
return 'five';
|
||||||
|
} else if (val === 4) {
|
||||||
|
return 'four';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
env.expect([{foo: 4}]).toEqual([{foo: 5}]);
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected $[0].foo = four to equal five.'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toHaveSize', function() {
|
||||||
|
verifyPasses(function(env) {
|
||||||
|
env.expect(['a','b']).toHaveSize(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function(env) {
|
||||||
|
env.expect(['a','b']).toHaveSize(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toHaveBeenCalled', function() {
|
describe('toHaveBeenCalled', function() {
|
||||||
@@ -394,14 +547,46 @@ describe('Matchers (Integration)', function() {
|
|||||||
describe('toHaveBeenCalledWith', function() {
|
describe('toHaveBeenCalledWith', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
var spy = env.createSpy();
|
var spy = env.createSpy();
|
||||||
spy('foo');
|
spy('5');
|
||||||
env.expect(spy).toHaveBeenCalledWith('foo');
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
env.expect(spy).toHaveBeenCalledWith(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
var spy = env.createSpy();
|
var spy = env.createSpy();
|
||||||
env.expect(spy).toHaveBeenCalledWith('foo');
|
env.expect(spy).toHaveBeenCalledWith('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
var spy = env.createSpy('foo');
|
||||||
|
env.expect(spy).toHaveBeenCalledWith('x');
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected spy foo to have been called with:\n' +
|
||||||
|
' |x|\n' +
|
||||||
|
'but it was never called.'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toHaveBeenCalledOnceWith', function() {
|
||||||
|
verifyPasses(function(env) {
|
||||||
|
var spy = env.createSpy();
|
||||||
|
spy('5', 3);
|
||||||
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
env.expect(spy).toHaveBeenCalledOnceWith(5, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function(env) {
|
||||||
|
var spy = env.createSpy();
|
||||||
|
env.expect(spy).toHaveBeenCalledOnceWith(5, 3);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toHaveClass', function() {
|
describe('toHaveClass', function() {
|
||||||
@@ -434,12 +619,28 @@ describe('Matchers (Integration)', function() {
|
|||||||
|
|
||||||
describe('toThrow', function() {
|
describe('toThrow', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(function() { throw new Error(); }).toThrow();
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
return a.toString() === b.toString();
|
||||||
|
});
|
||||||
|
env.expect(function() { throw '5'; }).toThrow(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(function() {}).toThrow();
|
env.expect(function() {}).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
var spy = env.createSpy('foo');
|
||||||
|
env.expect(function() {
|
||||||
|
throw 'x'
|
||||||
|
}).not.toThrow();
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected function not to throw, but it threw |x|.'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toThrowError', function() {
|
describe('toThrowError', function() {
|
||||||
@@ -450,6 +651,19 @@ describe('Matchers (Integration)', function() {
|
|||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(function() { }).toThrowError();
|
env.expect(function() { }).toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
var spy = env.createSpy('foo');
|
||||||
|
env.expect(function() {
|
||||||
|
throw 'x'
|
||||||
|
}).toThrowError();
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected function to throw an Error, but it threw |x|.'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toThrowMatching', function() {
|
describe('toThrowMatching', function() {
|
||||||
@@ -464,5 +678,21 @@ describe('Matchers (Integration)', function() {
|
|||||||
verifyFails(function(env) {
|
verifyFails(function(env) {
|
||||||
env.expect(throws).toThrowMatching(function() { return false; });
|
env.expect(throws).toThrowMatching(function() { return false; });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
verifyFailsWithCustomObjectFormatters({
|
||||||
|
formatter: function(val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
expectations: function(env) {
|
||||||
|
var spy = env.createSpy('foo');
|
||||||
|
env.expect(function() {
|
||||||
|
throw new Error('nope')
|
||||||
|
}).toThrowMatching(function() {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
expectedMessage: 'Expected function to throw an exception matching ' +
|
||||||
|
'a predicate, but it threw Error with message |nope|.'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ describe("spec running", function () {
|
|||||||
env.configure({random: false});
|
env.configure({random: false});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
it('should assign spec ids sequentially', function() {
|
it('should assign spec ids sequentially', function() {
|
||||||
var it0, it1, it2, it3, it4;
|
var it0, it1, it2, it3, it4;
|
||||||
env.describe('test suite', function() {
|
env.describe('test suite', function() {
|
||||||
|
|||||||
@@ -1,47 +1,182 @@
|
|||||||
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.record({x: 'actual'}, {x: 'expected'});
|
diffBuilder.setRoots({x: 'actual'}, {x: 'expected'});
|
||||||
|
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.withPath('foo', function() {
|
diffBuilder.withPath('foo', function () {
|
||||||
diffBuilder.record({x: 'actual'}, {x: 'expected'});
|
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.withPath('foo', function() {
|
diffBuilder.withPath('foo', function () {
|
||||||
diffBuilder.record(1, 2);
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
diffBuilder.withPath('bar', function () {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
});
|
});
|
||||||
|
|
||||||
var message =
|
var message =
|
||||||
"Expected $.foo = 1 to equal 2.\n" +
|
"Expected $.foo = 1 to equal 2.\n" +
|
||||||
"Expected 3 to equal 4.";
|
"Expected $.bar = 3 to equal 4.";
|
||||||
|
|
||||||
diffBuilder.record(3, 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'});
|
||||||
|
|
||||||
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.record('bar', 'foo', 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 () {
|
||||||
|
var prettyPrinter = function (val) {
|
||||||
|
return '|' + val + '|';
|
||||||
|
},
|
||||||
|
diffBuilder = jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
||||||
|
prettyPrinter.customFormat_ = function () {
|
||||||
|
};
|
||||||
|
|
||||||
|
diffBuilder.setRoots({foo: 'actual'}, {foo: 'expected'});
|
||||||
|
diffBuilder.withPath('foo', function () {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(diffBuilder.getMessage()).toEqual("Expected $.foo = |actual| to equal |expected|.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes the injected pretty-printer to the diff formatter", function () {
|
||||||
|
var diffFormatter = jasmine.createSpy('diffFormatter'),
|
||||||
|
prettyPrinter = function () {
|
||||||
|
},
|
||||||
|
diffBuilder = jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
||||||
|
prettyPrinter.customFormat_ = function () {
|
||||||
|
};
|
||||||
|
|
||||||
|
diffBuilder.setRoots({x: 'bar'}, {x: 'foo'});
|
||||||
|
diffBuilder.withPath('x', function () {
|
||||||
|
diffBuilder.recordMismatch(diffFormatter);
|
||||||
|
});
|
||||||
|
|
||||||
|
diffBuilder.getMessage();
|
||||||
|
|
||||||
|
expect(diffFormatter).toHaveBeenCalledWith('bar', 'foo', jasmine.anything(), prettyPrinter);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses custom object formatters on leaf nodes", function() {
|
||||||
|
var formatter = function(x) {
|
||||||
|
if (typeof x === 'number') {
|
||||||
|
return '[number:' + x + ']';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
||||||
|
var diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter});
|
||||||
|
|
||||||
|
diffBuilder.setRoots(5, 4);
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
|
||||||
|
expect(diffBuilder.getMessage()).toEqual('Expected [number:5] to equal [number:4].');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("uses custom object formatters on non leaf nodes", function () {
|
||||||
|
var formatter = function (x) {
|
||||||
|
if (x.hasOwnProperty('a')) {
|
||||||
|
return '[thing with a=' + x.a + ', b=' + JSON.stringify(x.b) + ']';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]);
|
||||||
|
var diffBuilder = new jasmineUnderTest.DiffBuilder({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'.";
|
||||||
|
|
||||||
|
diffBuilder.setRoots(
|
||||||
|
[{foo: {a: 1, b: {x: 42}}, bar: 'yes'}],
|
||||||
|
[{foo: {a: 1, b: {x: 43}}, bar: 'no'}]
|
||||||
|
);
|
||||||
|
|
||||||
|
diffBuilder.withPath(0, function () {
|
||||||
|
diffBuilder.withPath('foo', function () {
|
||||||
|
diffBuilder.withPath('b', function () {
|
||||||
|
diffBuilder.withPath('x', function () {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
diffBuilder.withPath('bar', function () {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ at the root', function() {
|
||||||
|
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
||||||
|
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
|
||||||
|
expectedMsg = 'Expected $.foo = 1 to equal 2.\n' +
|
||||||
|
"Expected $.baz = undefined to equal 3.";
|
||||||
|
|
||||||
|
|
||||||
|
diffBuilder.setRoots(
|
||||||
|
{foo: 1, bar: 2},
|
||||||
|
jasmine.objectContaining({foo: 2, baz: 3})
|
||||||
|
);
|
||||||
|
|
||||||
|
diffBuilder.withPath('foo', function() {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
diffBuilder.withPath('baz', function() {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ below the root', function() {
|
||||||
|
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
|
||||||
|
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
|
||||||
|
expectedMsg = 'Expected $.x.foo = 1 to equal 2.\n' +
|
||||||
|
"Expected $.x.baz = undefined to equal 3.";
|
||||||
|
|
||||||
|
|
||||||
|
diffBuilder.setRoots(
|
||||||
|
{x: {foo: 1, bar: 2}},
|
||||||
|
{x: jasmine.objectContaining({foo: 2, baz: 3})}
|
||||||
|
);
|
||||||
|
|
||||||
|
diffBuilder.withPath('x', function() {
|
||||||
|
diffBuilder.withPath('foo', function () {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
diffBuilder.withPath('baz', function () {
|
||||||
|
diffBuilder.recordMismatch();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
136
spec/core/matchers/MismatchTreeSpec.js
Normal file
136
spec/core/matchers/MismatchTreeSpec.js
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
describe('MismatchTree', function () {
|
||||||
|
describe('#add', function () {
|
||||||
|
describe('When the path is empty', function () {
|
||||||
|
it('flags the root node as mismatched', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath([]));
|
||||||
|
expect(tree.isMismatch).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When the path is not empty', function () {
|
||||||
|
it('flags the node as mismatched', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
|
|
||||||
|
expect(tree.child('a').child('b').isMismatch).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not flag ancestors as mismatched', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
|
|
||||||
|
expect(tree.isMismatch).toBe(false);
|
||||||
|
expect(tree.child('a').isMismatch).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stores the formatter on only the target node', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||||
|
|
||||||
|
expect(tree.formatter).toBeFalsy();
|
||||||
|
expect(tree.child('a').formatter).toBeFalsy();
|
||||||
|
expect(tree.child('a').child('b').formatter).toBe(formatter);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stores the path to the node', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||||
|
|
||||||
|
expect(tree.child('a').child('b').path.components).toEqual(['a', 'b']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#traverse', function () {
|
||||||
|
it('calls the callback for all nodes that are or contain mismatches', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']), formatter);
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['c']));
|
||||||
|
var visit = jasmine.createSpy('visit').and.returnValue(true);
|
||||||
|
|
||||||
|
tree.traverse(visit);
|
||||||
|
|
||||||
|
expect(visit).toHaveBeenCalledWith(
|
||||||
|
new jasmineUnderTest.ObjectPath([]), false, undefined
|
||||||
|
);
|
||||||
|
expect(visit).toHaveBeenCalledWith(
|
||||||
|
new jasmineUnderTest.ObjectPath(['a']), false, undefined
|
||||||
|
);
|
||||||
|
expect(visit).toHaveBeenCalledWith(
|
||||||
|
new jasmineUnderTest.ObjectPath(['a', 'b']), true, formatter
|
||||||
|
);
|
||||||
|
expect(visit).toHaveBeenCalledWith(
|
||||||
|
new jasmineUnderTest.ObjectPath(['c']), true, undefined
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not call the callback if there are no mismatches', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
var visit = jasmine.createSpy('visit');
|
||||||
|
|
||||||
|
tree.traverse(visit);
|
||||||
|
|
||||||
|
expect(visit).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('visits parents before children', function () {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
|
var visited = [];
|
||||||
|
|
||||||
|
tree.traverse(function (path) {
|
||||||
|
visited.push(path);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(visited).toEqual([
|
||||||
|
new jasmineUnderTest.ObjectPath([]),
|
||||||
|
new jasmineUnderTest.ObjectPath(['a']),
|
||||||
|
new jasmineUnderTest.ObjectPath(['a', 'b'])
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('visits children in the order they were recorded', function() {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['length']));
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath([1]));
|
||||||
|
var visited = [];
|
||||||
|
|
||||||
|
tree.traverse(function (path) {
|
||||||
|
visited.push(path);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(visited).toEqual([
|
||||||
|
new jasmineUnderTest.ObjectPath([]),
|
||||||
|
new jasmineUnderTest.ObjectPath(['length']),
|
||||||
|
new jasmineUnderTest.ObjectPath([1])
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not visit children if the callback returns falsy', function() {
|
||||||
|
var tree = new jasmineUnderTest.MismatchTree();
|
||||||
|
tree.add(new jasmineUnderTest.ObjectPath(['a', 'b']));
|
||||||
|
var visited = [];
|
||||||
|
|
||||||
|
tree.traverse(function (path) {
|
||||||
|
visited.push(path);
|
||||||
|
return path.depth() === 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(visited).toEqual([
|
||||||
|
new jasmineUnderTest.ObjectPath([]),
|
||||||
|
new jasmineUnderTest.ObjectPath(['a'])
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function formatter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('responds to record()', function() {
|
|
||||||
expect(function() {
|
|
||||||
jasmineUnderTest.NullDiffBuilder().record('does not matter');
|
|
||||||
}).not.toThrow();
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,5 +39,5 @@ describe('ObjectPath', function() {
|
|||||||
|
|
||||||
expect(path.toString()).toEqual('$.foo');
|
expect(path.toString()).toEqual('$.foo');
|
||||||
expect(root.toString()).toEqual('');
|
expect(root.toString()).toEqual('');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
52
spec/core/matchers/async/toBePendingSpec.js
Normal file
52
spec/core/matchers/async/toBePendingSpec.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
|
describe('toBePending', function() {
|
||||||
|
it('passes if the actual promise is pending', function() {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
|
||||||
|
actual = new Promise(function() {});
|
||||||
|
|
||||||
|
return matcher.compare(actual).then(function(result) {
|
||||||
|
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails if the actual promise is resolved', function() {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
|
||||||
|
actual = Promise.resolve();
|
||||||
|
|
||||||
|
return matcher.compare(actual).then(function(result) {
|
||||||
|
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails if the actual promise is rejected', function() {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
|
||||||
|
actual = Promise.reject(new Error('promise was rejected'));
|
||||||
|
|
||||||
|
return matcher.compare(actual).then(function(result) {
|
||||||
|
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails if actual is not a promise', function() {
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
|
||||||
|
actual = 'not a promise';
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
return matcher.compare(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(f).toThrowError(
|
||||||
|
'Expected toBePending to be called on a promise.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
describe('toBeRejected', function() {
|
describe('toBeRejected', function() {
|
||||||
it('passes if the actual is rejected', function() {
|
it('passes if the actual is rejected', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
@@ -13,7 +15,8 @@ describe('toBeRejected', function() {
|
|||||||
it('fails if the actual is resolved', function() {
|
it('fails if the actual is resolved', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||||
actual = Promise.resolve();
|
actual = Promise.resolve();
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
@@ -22,7 +25,8 @@ describe('toBeRejected', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
/* 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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -16,7 +18,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -30,7 +33,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -45,7 +49,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -59,7 +64,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -73,7 +79,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
it('passes when Error message is empty', function () {
|
it('passes when Error message is empty', function () {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -87,7 +94,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
it('passes when no arguments', function () {
|
it('passes when no arguments', function () {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -101,7 +109,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
it('fails when resolved', function () {
|
it('fails when resolved', function () {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -115,7 +124,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -129,7 +139,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
it('fails when Error type mismatches', function () {
|
it('fails when Error type mismatches', function () {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -143,7 +154,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
it('fails when Error message mismatches', function () {
|
it('fails when Error message mismatches', function () {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -155,7 +167,8 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
/* 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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -13,7 +15,8 @@ describe('#toBeRejectedWith', function () {
|
|||||||
it('should fail if the promise resolves', function () {
|
it('should fail if the promise resolves', function () {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -24,7 +27,8 @@ describe('#toBeRejectedWith', function () {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
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) {
|
||||||
@@ -38,7 +42,8 @@ describe('#toBeRejectedWith', function () {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
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) {
|
||||||
@@ -53,7 +58,8 @@ describe('#toBeRejectedWith', function () {
|
|||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var customEqualityTesters = [function() { return true; }],
|
var customEqualityTesters = [function() { return true; }],
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil, customEqualityTesters),
|
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
||||||
|
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) {
|
||||||
@@ -62,7 +68,8 @@ describe('#toBeRejectedWith', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
describe('toBeResolved', function() {
|
describe('toBeResolved', function() {
|
||||||
it('passes if the actual is resolved', function() {
|
it('passes if the actual is resolved', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||||
actual = Promise.resolve();
|
actual = Promise.resolve();
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
@@ -13,7 +15,8 @@ describe('toBeResolved', function() {
|
|||||||
it('fails if the actual is rejected', function() {
|
it('fails if the actual is rejected', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||||
|
|
||||||
return matcher.compare(actual).then(function(result) {
|
return matcher.compare(actual).then(function(result) {
|
||||||
@@ -22,7 +25,8 @@ describe('toBeResolved', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
describe('#toBeResolvedTo', function() {
|
describe('#toBeResolvedTo', function() {
|
||||||
it('passes if the promise is resolved to the expected value', function() {
|
it('passes if the promise is resolved to the expected value', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.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) {
|
||||||
@@ -13,7 +15,8 @@ describe('#toBeResolvedTo', function() {
|
|||||||
it('fails if the promise is rejected', function() {
|
it('fails if the promise is rejected', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
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) {
|
||||||
@@ -27,7 +30,8 @@ describe('#toBeResolvedTo', function() {
|
|||||||
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 matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
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) {
|
||||||
@@ -41,7 +45,8 @@ describe('#toBeResolvedTo', function() {
|
|||||||
it('builds its message correctly when negated', function() {
|
it('builds its message correctly when negated', function() {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
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) {
|
||||||
@@ -56,7 +61,11 @@ describe('#toBeResolvedTo', function() {
|
|||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var customEqualityTesters = [function() { return true; }],
|
var customEqualityTesters = [function() { return true; }],
|
||||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil, customEqualityTesters),
|
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
|
customTesters: customEqualityTesters,
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||||
actual = Promise.resolve('actual');
|
actual = Promise.resolve('actual');
|
||||||
|
|
||||||
return matcher.compare(actual, 'expected').then(function(result) {
|
return matcher.compare(actual, 'expected').then(function(result) {
|
||||||
@@ -65,7 +74,8 @@ describe('#toBeResolvedTo', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('fails if actual is not a promise', function() {
|
it('fails if actual is not a promise', function() {
|
||||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||||
actual = 'not a promise';
|
actual = 'not a promise';
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,9 @@ describe('toBeInstanceOf', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('passes for NaN', function() {
|
it('passes for NaN', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
});
|
||||||
var result = matcher.compare(NaN, Number);
|
var result = matcher.compare(NaN, Number);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
pass: true,
|
pass: true,
|
||||||
@@ -156,7 +158,9 @@ describe('toBeInstanceOf', function() {
|
|||||||
it('passes for objects with no constructor', function() {
|
it('passes for objects with no constructor', function() {
|
||||||
var object = Object.create(null);
|
var object = Object.create(null);
|
||||||
|
|
||||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
});
|
||||||
var result = matcher.compare(object, Object);
|
var result = matcher.compare(object, Object);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
pass: true,
|
pass: true,
|
||||||
@@ -219,7 +223,9 @@ describe('toBeInstanceOf', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('raises an error if missing an expected value', function() {
|
it('raises an error if missing an expected value', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
});
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare({}, undefined);
|
matcher.compare({}, undefined);
|
||||||
}).toThrowError('<toBeInstanceOf> : Expected value is not a constructor function\n' +
|
}).toThrowError('<toBeInstanceOf> : Expected value is not a constructor function\n' +
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ describe("toBeNaN", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
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.");
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ describe("toBeNegativeInfinity", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
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.")
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ describe("toBePositiveInfinity", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
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.")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
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 matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(1, 1);
|
result = matcher.compare(1, 1);
|
||||||
@@ -8,7 +9,8 @@ describe("toBe", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result,
|
result,
|
||||||
array = [1];
|
array = [1];
|
||||||
|
|
||||||
@@ -18,7 +20,8 @@ describe("toBe", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result,
|
result,
|
||||||
obj = {foo: "bar"};
|
obj = {foo: "bar"};
|
||||||
|
|
||||||
@@ -28,7 +31,8 @@ describe("toBe", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("fails with no message when actual !== expected", function() {
|
it("fails with no message when actual !== expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(1, 2);
|
result = matcher.compare(1, 2);
|
||||||
@@ -37,7 +41,8 @@ describe("toBe", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare([1], [1]);
|
result = matcher.compare([1], [1]);
|
||||||
@@ -46,11 +51,24 @@ describe("toBe", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 matcher = jasmineUnderTest.matchers.toBe(jasmineUnderTest.matchersUtil),
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
|
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() {
|
||||||
|
var formatter = function(x) { return '<' + x.foo + '>'; },
|
||||||
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: prettyPrinter}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toBe(matchersUtil),
|
||||||
|
result;
|
||||||
|
|
||||||
|
result = matcher.compare({foo: "bar"}, {foo: "bar"});
|
||||||
|
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().")
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
describe("toContain", function() {
|
describe("toContain", function() {
|
||||||
it("delegates to jasmineUnderTest.matchersUtil.contains", function() {
|
it("delegates to jasmineUnderTest.matchersUtil.contains", function() {
|
||||||
var util = {
|
var matchersUtil = {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toContain(util),
|
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare("ABC", "B");
|
result = matcher.compare("ABC", "B");
|
||||||
expect(util.contains).toHaveBeenCalledWith("ABC", "B", []);
|
expect(matchersUtil.contains).toHaveBeenCalledWith("ABC", "B");
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("delegates to jasmineUnderTest.matchersUtil.contains, passing in equality testers if present", function() {
|
it("works with custom equality testers", function() {
|
||||||
var util = {
|
var tester = function (a, b) {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
return a.toString() === b.toString();
|
||||||
},
|
},
|
||||||
customEqualityTesters = ['a', 'b'],
|
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]}),
|
||||||
matcher = jasmineUnderTest.matchers.toContain(util, customEqualityTesters),
|
matcher = jasmineUnderTest.matchers.toContain(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare("ABC", "B");
|
result = matcher.compare(['1', '2'], 2);
|
||||||
expect(util.contains).toHaveBeenCalledWith("ABC", "B", ['a', 'b']);
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ describe("toEqual", function() {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function compareEquals(actual, expected) {
|
function compareEquals(actual, expected) {
|
||||||
var util = jasmineUnderTest.matchersUtil,
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
matcher = jasmineUnderTest.matchers.toEqual(util);
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil);
|
||||||
|
|
||||||
var result = matcher.compare(actual, expected);
|
var result = matcher.compare(actual, expected);
|
||||||
|
|
||||||
@@ -11,37 +13,32 @@ describe("toEqual", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it("delegates to equals function", function() {
|
it("delegates to equals function", function() {
|
||||||
var util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
|
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'does not matter'
|
return 'does not matter';
|
||||||
},
|
},
|
||||||
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
|
DiffBuilder: new jasmineUnderTest.DiffBuilder()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toEqual(util),
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(1, 1);
|
result = matcher.compare(1, 1);
|
||||||
|
|
||||||
expect(util.equals).toHaveBeenCalledWith(1, 1, [], jasmine.anything());
|
expect(matchersUtil.equals).toHaveBeenCalledWith(1, 1, jasmine.anything());
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("delegates custom equality testers, if present", function() {
|
it("works with custom equality testers", function() {
|
||||||
var util = {
|
var tester = function (a, b) {
|
||||||
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
|
return a.toString() === b.toString();
|
||||||
buildFailureMessage: function() {
|
|
||||||
return 'does not matter'
|
|
||||||
},
|
|
||||||
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
|
|
||||||
},
|
},
|
||||||
customEqualityTesters = ['a', 'b'],
|
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]}),
|
||||||
matcher = jasmineUnderTest.matchers.toEqual(util, customEqualityTesters),
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(1, 1);
|
result = matcher.compare(1, '1');
|
||||||
|
|
||||||
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b'], jasmine.anything());
|
|
||||||
expect(result.pass).toBe(true);
|
expect(result.pass).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -100,16 +97,66 @@ describe("toEqual", function() {
|
|||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports extra and missing properties together", function() {
|
it("uses custom object formatters to pretty-print simple properties", function() {
|
||||||
|
function formatter(x) {
|
||||||
|
if (typeof x === 'number') {
|
||||||
|
return '|' + x + '|';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var actual = {x: {y: 1, z: 2, f: 4}},
|
var actual = {x: {y: 1, z: 2, f: 4}},
|
||||||
expected = {x: {y: 1, z: 2, g: 3}},
|
expected = {x: {y: 1, z: 2, g: 3}},
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||||
message =
|
message =
|
||||||
"Expected $.x to have properties\n" +
|
"Expected $.x to have properties\n" +
|
||||||
" g: 3\n" +
|
" g: |3|\n" +
|
||||||
"Expected $.x not to have properties\n" +
|
"Expected $.x not to have properties\n" +
|
||||||
" f: 4";
|
" f: |4|";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses custom object formatters to show simple values in diffs", function() {
|
||||||
|
function formatter(x) {
|
||||||
|
if (typeof x === 'number') {
|
||||||
|
return '|' + x + '|';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var actual = [{foo: 4}],
|
||||||
|
expected = [{foo: 5}],
|
||||||
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: prettyPrinter}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||||
|
message = "Expected $[0].foo = |4| to equal |5|.";
|
||||||
|
|
||||||
|
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses custom object formatters to show more complex objects diffs", function() {
|
||||||
|
function formatter(x) {
|
||||||
|
if (x.hasOwnProperty('a')) {
|
||||||
|
return '[thing with a=' + x.a + ', b=' + x.b + ']';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var actual = [{
|
||||||
|
foo: {a: 1, b: 2},
|
||||||
|
bar: 'should not be pretty printed'
|
||||||
|
}],
|
||||||
|
expected = [{
|
||||||
|
foo: {a: 5, b: 2},
|
||||||
|
bar: "shouldn't be pretty printed"
|
||||||
|
}],
|
||||||
|
prettyPrinter = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: prettyPrinter}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||||
|
message = "Expected $[0].foo = [thing with a=1, b=2] to equal [thing with a=5, b=2].\n" +
|
||||||
|
"Expected $[0].bar = 'should not be pretty printed' to equal 'shouldn't be pretty printed'.";
|
||||||
|
|
||||||
|
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports extra and missing properties of the root-level object", function() {
|
it("reports extra and missing properties of the root-level object", function() {
|
||||||
@@ -214,8 +261,8 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between arrays of different types", function() {
|
it("reports mismatches between arrays of different types", function() {
|
||||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||||
|
|
||||||
var actual = new Uint32Array([1, 2, 3]),
|
var actual = new Uint32Array([1, 2, 3]), // eslint-disable-line compat/compat
|
||||||
expected = new Uint16Array([1, 2, 3]),
|
expected = new Uint16Array([1, 2, 3]), // eslint-disable-line compat/compat
|
||||||
message = "Expected Uint32Array [ 1, 2, 3 ] to equal Uint16Array [ 1, 2, 3 ].";
|
message = "Expected Uint32Array [ 1, 2, 3 ] to equal Uint16Array [ 1, 2, 3 ].";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
@@ -282,12 +329,31 @@ describe("toEqual", function() {
|
|||||||
function Bar() {}
|
function Bar() {}
|
||||||
|
|
||||||
var actual = {x: new Foo()},
|
var actual = {x: new Foo()},
|
||||||
expected = {x: new Bar()},
|
expected = {x: new Bar()},
|
||||||
message = "Expected $.x to be a kind of Bar, but was Foo({ }).";
|
message = "Expected $.x to be a kind of Bar, but was Foo({ }).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses custom object formatters for the value but not the type when reporting objects with different constructors", function () {
|
||||||
|
function Foo() {}
|
||||||
|
function Bar() {}
|
||||||
|
function formatter(x) {
|
||||||
|
if (x instanceof Foo || x instanceof Bar) {
|
||||||
|
return '|' + x + '|';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var actual = {x: new Foo()},
|
||||||
|
expected = {x: new Bar()},
|
||||||
|
message = "Expected $.x to be a kind of Bar, but was |[object Object]|.",
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil);
|
||||||
|
|
||||||
|
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
it("reports type mismatches at the root level", function () {
|
it("reports type mismatches at the root level", function () {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
function Bar() {}
|
function Bar() {}
|
||||||
@@ -299,6 +365,11 @@ describe("toEqual", function() {
|
|||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("reports value mismatches at the root level", function() {
|
||||||
|
expect(compareEquals(1, 2).message).toEqual("Expected 1 to equal 2.");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it("reports mismatches between objects with their own constructor property", function () {
|
it("reports mismatches between objects with their own constructor property", function () {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
function Bar() {}
|
function Bar() {}
|
||||||
@@ -334,6 +405,14 @@ describe("toEqual", function() {
|
|||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("reports mismatches between 0 and Number.MIN_VALUE", function() {
|
||||||
|
var actual = {x: 0},
|
||||||
|
expected = {x: Number.MIN_VALUE},
|
||||||
|
message = "Expected $.x = 0 to equal 5e-324.";
|
||||||
|
|
||||||
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
it("reports mismatches between Errors", function() {
|
it("reports mismatches between Errors", function() {
|
||||||
var actual = {x: new Error("the error you got")},
|
var actual = {x: new Error("the error you got")},
|
||||||
expected = {x: new Error("the error you want")},
|
expected = {x: new Error("the error you want")},
|
||||||
@@ -350,14 +429,41 @@ describe("toEqual", function() {
|
|||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reports mismatches between an object and objectContaining', function() {
|
||||||
|
var actual = {a: 1, b: 4, c: 3, extra: 'ignored'};
|
||||||
|
var expected = jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4});
|
||||||
|
expect(compareEquals(actual, expected).message)
|
||||||
|
.toEqual(
|
||||||
|
'Expected $.b = 4 to equal 2.\n' +
|
||||||
|
'Expected $.d = undefined to equal 4.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports mismatches between a non-object and objectContaining", function() {
|
||||||
|
var actual = 1;
|
||||||
|
var expected = jasmineUnderTest.objectContaining({a: 1});
|
||||||
|
expect(compareEquals(actual, expected).message).toEqual(
|
||||||
|
"Expected 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports mismatches involving a nested objectContaining", function() {
|
||||||
|
var actual = {x: {a: 1, b: 4, c: 3, extra: 'ignored'}};
|
||||||
|
var expected = {x: jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4})};
|
||||||
|
expect(compareEquals(actual, expected).message).toEqual(
|
||||||
|
'Expected $.x.b = 4 to equal 2.\n' +
|
||||||
|
'Expected $.x.d = undefined to equal 4.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// == Sets ==
|
// == Sets ==
|
||||||
|
|
||||||
it("reports mismatches between Sets", function() {
|
it("reports mismatches between Sets", function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
var actual = new Set();
|
var actual = new Set(); // eslint-disable-line compat/compat
|
||||||
actual.add(1);
|
actual.add(1);
|
||||||
var expected = new Set();
|
var expected = new Set(); // eslint-disable-line compat/compat
|
||||||
expected.add(2);
|
expected.add(2);
|
||||||
var message = 'Expected Set( 1 ) to equal Set( 2 ).';
|
var message = 'Expected Set( 1 ) to equal Set( 2 ).';
|
||||||
|
|
||||||
@@ -367,9 +473,9 @@ describe("toEqual", function() {
|
|||||||
it("reports deep mismatches within Sets", function() {
|
it("reports deep mismatches within Sets", function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
var actual = new Set();
|
var actual = new Set(); // eslint-disable-line compat/compat
|
||||||
actual.add({x: 1});
|
actual.add({x: 1});
|
||||||
var expected = new Set();
|
var expected = new Set(); // eslint-disable-line compat/compat
|
||||||
expected.add({x: 2});
|
expected.add({x: 2});
|
||||||
var message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
|
var message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
|
||||||
|
|
||||||
@@ -379,9 +485,9 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Sets nested in objects", function() {
|
it("reports mismatches between Sets nested in objects", function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
var actualSet = new Set();
|
var actualSet = new Set(); // eslint-disable-line compat/compat
|
||||||
actualSet.add(1);
|
actualSet.add(1);
|
||||||
var expectedSet = new Set();
|
var expectedSet = new Set(); // eslint-disable-line compat/compat
|
||||||
expectedSet.add(2);
|
expectedSet.add(2);
|
||||||
|
|
||||||
var actual = { sets: [actualSet] };
|
var actual = { sets: [actualSet] };
|
||||||
@@ -394,10 +500,10 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Sets of different lengths", function() {
|
it("reports mismatches between Sets of different lengths", function() {
|
||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
var actual = new Set();
|
var actual = new Set(); // eslint-disable-line compat/compat
|
||||||
actual.add(1);
|
actual.add(1);
|
||||||
actual.add(2);
|
actual.add(2);
|
||||||
var expected = new Set();
|
var expected = new Set(); // eslint-disable-line compat/compat
|
||||||
expected.add(2);
|
expected.add(2);
|
||||||
var message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
|
var message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
|
||||||
|
|
||||||
@@ -408,10 +514,10 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
// Use 'duplicate' object in actual so sizes match
|
// Use 'duplicate' object in actual so sizes match
|
||||||
var actual = new Set();
|
var actual = new Set(); // eslint-disable-line compat/compat
|
||||||
actual.add({x: 1});
|
actual.add({x: 1});
|
||||||
actual.add({x: 1});
|
actual.add({x: 1});
|
||||||
var expected = new Set();
|
var expected = new Set(); // eslint-disable-line compat/compat
|
||||||
expected.add({x: 1});
|
expected.add({x: 1});
|
||||||
expected.add({x: 2});
|
expected.add({x: 2});
|
||||||
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
|
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
|
||||||
@@ -423,10 +529,10 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningSets();
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
// Use 'duplicate' object in expected so sizes match
|
// Use 'duplicate' object in expected so sizes match
|
||||||
var actual = new Set();
|
var actual = new Set(); // eslint-disable-line compat/compat
|
||||||
actual.add({x: 1});
|
actual.add({x: 1});
|
||||||
actual.add({x: 2});
|
actual.add({x: 2});
|
||||||
var expected = new Set();
|
var expected = new Set(); // eslint-disable-line compat/compat
|
||||||
expected.add({x: 1});
|
expected.add({x: 1});
|
||||||
expected.add({x: 1});
|
expected.add({x: 1});
|
||||||
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
|
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
|
||||||
@@ -440,9 +546,9 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
// values are the same but with different object identity
|
// values are the same but with different object identity
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set('a',{x:1});
|
actual.set('a',{x:1});
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set('a',{x:1});
|
expected.set('a',{x:1});
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
@@ -451,9 +557,9 @@ describe("toEqual", function() {
|
|||||||
it("reports deep mismatches within Maps", function() {
|
it("reports deep mismatches within Maps", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set('a',{x:1});
|
actual.set('a',{x:1});
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set('a',{x:2});
|
expected.set('a',{x:2});
|
||||||
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
||||||
|
|
||||||
@@ -463,9 +569,9 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps nested in objects", function() {
|
it("reports mismatches between Maps nested in objects", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = {Maps:[new Map()]};
|
var actual = {Maps:[new Map()]}; // eslint-disable-line compat/compat
|
||||||
actual.Maps[0].set('a',1);
|
actual.Maps[0].set('a',1);
|
||||||
var expected = {Maps:[new Map()]};
|
var expected = {Maps:[new Map()]}; // eslint-disable-line compat/compat
|
||||||
expected.Maps[0].set('a',2);
|
expected.Maps[0].set('a',2);
|
||||||
|
|
||||||
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
||||||
@@ -476,9 +582,9 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps of different lengths", function() {
|
it("reports mismatches between Maps of different lengths", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set('a',1);
|
actual.set('a',1);
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set('a',2);
|
expected.set('a',2);
|
||||||
expected.set('b',1);
|
expected.set('b',1);
|
||||||
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
||||||
@@ -489,9 +595,9 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps with equal values but differing keys", function() {
|
it("reports mismatches between Maps with equal values but differing keys", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set('a',1);
|
actual.set('a',1);
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set('b',1);
|
expected.set('b',1);
|
||||||
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
||||||
|
|
||||||
@@ -501,9 +607,9 @@ describe("toEqual", function() {
|
|||||||
it("does not report mismatches between Maps with keys with same object identity", function() {
|
it("does not report mismatches between Maps with keys with same object identity", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
var key = {x: 1};
|
var key = {x: 1};
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set(key,2);
|
actual.set(key,2);
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set(key,2);
|
expected.set(key,2);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
@@ -512,9 +618,9 @@ describe("toEqual", function() {
|
|||||||
it("reports mismatches between Maps with identical keys with different object identity", function() {
|
it("reports mismatches between Maps with identical keys with different object identity", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set({x:1},2);
|
actual.set({x:1},2);
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set({x:1},2);
|
expected.set({x:1},2);
|
||||||
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
||||||
|
|
||||||
@@ -524,9 +630,9 @@ describe("toEqual", function() {
|
|||||||
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set('a',1);
|
actual.set('a',1);
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set(jasmineUnderTest.anything(),1);
|
expected.set(jasmineUnderTest.anything(),1);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
@@ -536,10 +642,10 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var key = Symbol();
|
var key = Symbol(); // eslint-disable-line compat/compat
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set(key,1);
|
actual.set(key,1);
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set(key,1);
|
expected.set(key,1);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
@@ -549,10 +655,10 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set(Symbol(),1);
|
actual.set(Symbol(),1); // eslint-disable-line compat/compat
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set(Symbol(),1);
|
expected.set(Symbol(),1); // eslint-disable-line compat/compat
|
||||||
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).message).toBe(message);
|
expect(compareEquals(actual, expected).message).toBe(message);
|
||||||
@@ -562,9 +668,9 @@ describe("toEqual", function() {
|
|||||||
jasmine.getEnv().requireFunctioningMaps();
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
jasmine.getEnv().requireFunctioningSymbols();
|
jasmine.getEnv().requireFunctioningSymbols();
|
||||||
|
|
||||||
var actual = new Map();
|
var actual = new Map(); // eslint-disable-line compat/compat
|
||||||
actual.set(Symbol(),1);
|
actual.set(Symbol(),1); // eslint-disable-line compat/compat
|
||||||
var expected = new Map();
|
var expected = new Map(); // eslint-disable-line compat/compat
|
||||||
expected.set(jasmineUnderTest.anything(),1);
|
expected.set(jasmineUnderTest.anything(),1);
|
||||||
|
|
||||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||||
@@ -808,6 +914,24 @@ describe("toEqual", function() {
|
|||||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses custom object formatters when the actual array is longer", function() {
|
||||||
|
function formatter(x) {
|
||||||
|
if (typeof x === 'number') {
|
||||||
|
return '|' + x + '|';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var actual = [1, 1, 2, 3, 5],
|
||||||
|
expected = [1, 1, 2, 3],
|
||||||
|
pp = jasmineUnderTest.makePrettyPrinter([formatter]),
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toEqual(matchersUtil),
|
||||||
|
message = 'Expected $.length = |5| to equal |4|.\n' +
|
||||||
|
'Unexpected $[4] = |5| in array.';
|
||||||
|
|
||||||
|
expect(matcher.compare(actual, expected).message).toEqual(message);
|
||||||
|
});
|
||||||
|
|
||||||
it("expected array is longer", function() {
|
it("expected array is longer", function() {
|
||||||
var actual = [1, 1, 2, 3],
|
var actual = [1, 1, 2, 3],
|
||||||
expected = [1, 1, 2, 3, 5],
|
expected = [1, 1, 2, 3, 5],
|
||||||
|
|||||||
@@ -1,24 +1,32 @@
|
|||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {},
|
fn = function() {},
|
||||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
spy = new jasmineUnderTest.Env().createSpy('a spy');
|
||||||
|
|
||||||
expect(function() { matcher.compare(fn, secondSpy) }).toThrowError(Error, /Expected a spy, but got Function./);
|
expect(function () {
|
||||||
|
matcher.compare(fn, spy);
|
||||||
|
}).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({
|
||||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
spy = new jasmineUnderTest.Env().createSpy('a spy'),
|
||||||
fn = function() {};
|
fn = function() {};
|
||||||
|
|
||||||
expect(function() { matcher.compare(firstSpy, fn) }).toThrowError(Error, /Expected a spy, but got Function./);
|
expect(function () {
|
||||||
|
matcher.compare(spy, fn);
|
||||||
|
}).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.Env().createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
secondSpy = new jasmineUnderTest.Spy('second spy');
|
||||||
|
|
||||||
secondSpy();
|
secondSpy();
|
||||||
|
|
||||||
@@ -27,10 +35,10 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
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.Env().createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
secondSpy = new jasmineUnderTest.Spy('second spy');
|
||||||
|
|
||||||
firstSpy();
|
firstSpy();
|
||||||
|
|
||||||
@@ -39,11 +47,11 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
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.Env().createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
secondSpy();
|
secondSpy();
|
||||||
firstSpy();
|
firstSpy();
|
||||||
@@ -53,11 +61,11 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
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.Env().createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
firstSpy();
|
firstSpy();
|
||||||
secondSpy();
|
secondSpy();
|
||||||
@@ -68,11 +76,11 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
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.Env().createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
secondSpy();
|
secondSpy();
|
||||||
firstSpy();
|
firstSpy();
|
||||||
@@ -83,11 +91,11 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
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.Env().createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Spy('first spy'),
|
||||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Spy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
firstSpy();
|
firstSpy();
|
||||||
secondSpy();
|
secondSpy();
|
||||||
|
|||||||
88
spec/core/matchers/toHaveBeenCalledOnceWithSpec.js
Normal file
88
spec/core/matchers/toHaveBeenCalledOnceWithSpec.js
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
describe("toHaveBeenCalledOnceWith", function () {
|
||||||
|
|
||||||
|
it("passes when the actual was called only once and with matching parameters", function () {
|
||||||
|
var util = jasmineUnderTest.matchersUtil,
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
|
calledSpy('a', 'b');
|
||||||
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports custom equality testers", function () {
|
||||||
|
var customEqualityTesters = [function() { return true; }],
|
||||||
|
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(matchersUtil),
|
||||||
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
|
calledSpy('a', 'b');
|
||||||
|
result = matcher.compare(calledSpy, 'a', 'a');
|
||||||
|
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails when the actual was never called", function () {
|
||||||
|
var util = jasmineUnderTest.matchersUtil,
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails when the actual was called once with different parameters", function () {
|
||||||
|
var util = jasmineUnderTest.matchersUtil,
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
|
calledSpy('a', 'c');
|
||||||
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails when the actual was called multiple times with expected parameters", function () {
|
||||||
|
var util = jasmineUnderTest.matchersUtil,
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
|
calledSpy('a', 'b');
|
||||||
|
calledSpy('a', 'b');
|
||||||
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails when the actual was called multiple times (one of them - with expected parameters)", function () {
|
||||||
|
var util = jasmineUnderTest.matchersUtil,
|
||||||
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
|
||||||
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
|
result;
|
||||||
|
|
||||||
|
calledSpy('a', 'b');
|
||||||
|
calledSpy('a', 'c');
|
||||||
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws an exception when the actual is not a spy", function () {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(),
|
||||||
|
fn = function () { };
|
||||||
|
|
||||||
|
expect(function () { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
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.Env().createSpy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
calledSpy();
|
calledSpy();
|
||||||
@@ -13,7 +13,7 @@ describe("toHaveBeenCalled", function() {
|
|||||||
|
|
||||||
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.Env().createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy);
|
result = matcher.compare(uncalledSpy);
|
||||||
@@ -21,7 +21,9 @@ describe("toHaveBeenCalled", 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.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled({
|
||||||
|
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./);
|
||||||
@@ -29,14 +31,14 @@ describe("toHaveBeenCalled", 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.Env().createSpy('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.Env().createSpy('sample-spy'),
|
spy = new jasmineUnderTest.Spy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(spy);
|
result = matcher.compare(spy);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
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.Env().createSpy('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.Env().createSpy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
calledSpy();
|
calledSpy();
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
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.Env().createSpy('spy'),
|
spy = new jasmineUnderTest.Spy('spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
spy();
|
spy();
|
||||||
@@ -29,7 +29,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
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.Env().createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy, 2);
|
result = matcher.compare(uncalledSpy, 2);
|
||||||
@@ -38,7 +38,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
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.Env().createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
uncalledSpy();
|
uncalledSpy();
|
||||||
@@ -49,7 +49,9 @@ describe("toHaveBeenCalledTimes", 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.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
fn = function() {};
|
fn = function() {};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -59,7 +61,7 @@ describe("toHaveBeenCalledTimes", 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.Env().createSpy('sample-spy'),
|
spy = new jasmineUnderTest.Spy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
spy();
|
spy();
|
||||||
spy();
|
spy();
|
||||||
@@ -72,7 +74,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
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.Env().createSpy('sample-spy'),
|
spy = new jasmineUnderTest.Spy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
spy();
|
spy();
|
||||||
spy();
|
spy();
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
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 util = {
|
var matchersUtil = {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(true),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
calledSpy('a', 'b');
|
calledSpy('a', 'b');
|
||||||
@@ -15,26 +16,25 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
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("passes through the custom equality testers", function() {
|
it("supports custom equality testers", function() {
|
||||||
var util = {
|
var customEqualityTesters = [function() { return true; }],
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
||||||
},
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
customEqualityTesters = [function() { return true; }],
|
calledSpy = new jasmineUnderTest.Spy('called-spy'),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
|
result;
|
||||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy');
|
|
||||||
|
|
||||||
calledSpy('a', 'b');
|
calledSpy('a', 'b');
|
||||||
matcher.compare(calledSpy, 'a', 'b');
|
result = matcher.compare(calledSpy, 'a', 'b');
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
expect(util.contains).toHaveBeenCalledWith([['a', 'b']], ['a', 'b'], customEqualityTesters);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was not called", function() {
|
it("fails when the actual was not called", function() {
|
||||||
var util = {
|
var matchersUtil = {
|
||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(false),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Spy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy);
|
result = matcher.compare(uncalledSpy);
|
||||||
@@ -43,9 +43,9 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("fails when the actual was called with different parameters", function() {
|
it("fails when the actual was called with different parameters", function() {
|
||||||
var util = jasmineUnderTest.matchersUtil,
|
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(matchersUtil),
|
||||||
calledSpy = new jasmineUnderTest.Env().createSpy('called spy'),
|
calledSpy = new jasmineUnderTest.Spy('called spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
calledSpy('a');
|
calledSpy('a');
|
||||||
@@ -73,8 +73,11 @@ describe("toHaveBeenCalledWith", 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.toHaveBeenCalledWith(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith({
|
||||||
fn = function() {};
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
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./);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ describe('toHaveClass', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws an exception when actual is not a DOM element', function() {
|
it('throws an exception when actual is not a DOM element', function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveClass();
|
var matcher = jasmineUnderTest.matchers.toHaveClass({
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
});
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.compare('x', 'foo');
|
matcher.compare('x', 'foo');
|
||||||
|
|||||||
138
spec/core/matchers/toHaveSizeSpec.js
Normal file
138
spec/core/matchers/toHaveSizeSpec.js
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
|
describe('toHaveSize', function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
it('passes for an array whose length matches', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare([1, 2], 2);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for an array whose length does not match', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare([1, 2, 3], 2);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for an object with the proper number of keys', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare({a: 1, b: 2}, 2);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for an object with a different number of keys', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare({a: 1, b: 2}, 1);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for an object with an explicit `length` property that matches', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare({a: 1, b: 2, length: 5}, 5);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for an object with an explicit `length` property that does not match', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare({a: 1, b: 2, length: 5}, 1);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for a string whose length matches', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare('ab', 2);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for a string whose length does not match', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare('abc', 2);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for a Map whose length matches', function() {
|
||||||
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
map.set('a',1);
|
||||||
|
map.set('b',2);
|
||||||
|
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare(map, 2);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for a Map whose length does not match', function() {
|
||||||
|
jasmine.getEnv().requireFunctioningMaps();
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
map.set('a',1);
|
||||||
|
map.set('b',2);
|
||||||
|
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare(map, 1);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for a Set whose length matches', function() {
|
||||||
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
|
var set = new Set();
|
||||||
|
set.add('a');
|
||||||
|
set.add('b');
|
||||||
|
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare(set, 2);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for a Set whose length does not match', function() {
|
||||||
|
jasmine.getEnv().requireFunctioningSets();
|
||||||
|
|
||||||
|
var set = new Set();
|
||||||
|
set.add('a');
|
||||||
|
set.add('b');
|
||||||
|
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize(),
|
||||||
|
result = matcher.compare(set, 1);
|
||||||
|
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws an error for WeakSet', function() {
|
||||||
|
jasmine.getEnv().requireWeakSets();
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize();
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
matcher.compare(new WeakSet(), 2);
|
||||||
|
}).toThrowError('Cannot get size of [object WeakSet].');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws an error for WeakMap', function() {
|
||||||
|
jasmine.getEnv().requireWeakMaps();
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize();
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
matcher.compare(new WeakMap(), 2);
|
||||||
|
}).toThrowError(/Cannot get size of \[object (WeakMap|Object)\]\./);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws an error for DataView', function() {
|
||||||
|
var matcher = jasmineUnderTest.matchers.toHaveSize();
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
matcher.compare(new DataView(new ArrayBuffer(128)), 2);
|
||||||
|
}).toThrowError(/Cannot get size of \[object (DataView|Object)\]\./);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -54,7 +54,9 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw 4;
|
throw 4;
|
||||||
},
|
},
|
||||||
@@ -103,7 +105,9 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw undefined;
|
throw undefined;
|
||||||
},
|
},
|
||||||
@@ -128,7 +132,9 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error("foo");
|
||||||
},
|
},
|
||||||
@@ -141,7 +147,9 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("foo");
|
throw new Error("foo");
|
||||||
},
|
},
|
||||||
@@ -154,7 +162,9 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("a long message");
|
throw new Error("a long message");
|
||||||
},
|
},
|
||||||
@@ -167,7 +177,9 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error("a long message");
|
throw new Error("a long message");
|
||||||
},
|
},
|
||||||
@@ -180,10 +192,7 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
|
||||||
},
|
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
},
|
},
|
||||||
@@ -196,10 +205,7 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
|
||||||
},
|
|
||||||
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 });
|
||||||
@@ -215,10 +221,7 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
|
||||||
},
|
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
},
|
},
|
||||||
@@ -231,10 +234,11 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError("foo");
|
||||||
},
|
},
|
||||||
@@ -247,11 +251,12 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
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"});
|
||||||
},
|
},
|
||||||
@@ -266,10 +271,11 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError("foo");
|
||||||
},
|
},
|
||||||
@@ -282,10 +288,11 @@ describe("toThrowError", 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() {
|
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError("foo");
|
||||||
},
|
},
|
||||||
@@ -298,10 +305,11 @@ describe("toThrowError", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
matcher = jasmineUnderTest.matchers.toThrowError(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("foo");
|
throw new TypeError("foo");
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ describe("toThrowMatching", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw undefined;
|
throw undefined;
|
||||||
},
|
},
|
||||||
@@ -58,8 +60,10 @@ describe("toThrowMatching", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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({
|
||||||
predicate = function(e) { return e.message === "oh no" },
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
|
}),
|
||||||
|
predicate = function(e) { return e.message === "oh no" },
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw new TypeError("nope");
|
throw new TypeError("nope");
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ describe("toThrow", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("passes if it throws but there is no expected", function() {
|
it("passes if it throws but there is no expected", function() {
|
||||||
var util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw 5;
|
throw 5;
|
||||||
},
|
},
|
||||||
@@ -39,7 +40,9 @@ describe("toThrow", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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()
|
||||||
|
}),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw undefined;
|
throw undefined;
|
||||||
},
|
},
|
||||||
@@ -51,10 +54,11 @@ describe("toThrow", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw 5;
|
throw 5;
|
||||||
},
|
},
|
||||||
@@ -67,10 +71,11 @@ describe("toThrow", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw 5;
|
throw 5;
|
||||||
},
|
},
|
||||||
@@ -83,10 +88,11 @@ describe("toThrow", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 util = {
|
var matchersUtil = {
|
||||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||||
|
pp: jasmineUnderTest.makePrettyPrinter()
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
matcher = jasmineUnderTest.matchers.toThrow(matchersUtil),
|
||||||
fn = function() {
|
fn = function() {
|
||||||
throw 5;
|
throw 5;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
(function(env) {
|
(function(env) {
|
||||||
function hasFunctioningMaps() {
|
env.hasFunctioningMaps = function() {
|
||||||
if (typeof Map === 'undefined') {
|
if (typeof Map === 'undefined') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -36,11 +37,17 @@
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
env.requireFunctioningMaps = function() {
|
env.requireFunctioningMaps = function() {
|
||||||
if (!hasFunctioningMaps()) {
|
if (!env.hasFunctioningMaps()) {
|
||||||
env.pending('Browser has incomplete or missing support for Maps');
|
env.pending('Browser has incomplete or missing support for Maps');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
env.requireWeakMaps = function() {
|
||||||
|
if (typeof WeakMap === 'undefined') {
|
||||||
|
env.pending('Browser does not have support for WeakMap');
|
||||||
|
}
|
||||||
|
};
|
||||||
})(jasmine.getEnv());
|
})(jasmine.getEnv());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
(function(env) {
|
(function(env) {
|
||||||
function hasFunctioningSets() {
|
env.hasFunctioningSets = function() {
|
||||||
if (typeof Set === 'undefined') {
|
if (typeof Set === 'undefined') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -40,11 +41,17 @@
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
env.requireFunctioningSets = function() {
|
env.requireFunctioningSets = function() {
|
||||||
if (!hasFunctioningSets()) {
|
if (!env.hasFunctioningSets()) {
|
||||||
env.pending('Browser has incomplete or missing support for Sets');
|
env.pending('Browser has incomplete or missing support for Sets');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
env.requireWeakSets = function() {
|
||||||
|
if (typeof WeakSet === 'undefined') {
|
||||||
|
env.pending('Browser does not have support for WeakSet');
|
||||||
|
}
|
||||||
|
};
|
||||||
})(jasmine.getEnv());
|
})(jasmine.getEnv());
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
(function(env) {
|
(function(env) {
|
||||||
function hasFunctioningSymbols() {
|
function hasFunctioningSymbols() {
|
||||||
if (typeof Symbol === 'undefined') {
|
if (typeof Symbol === 'undefined') {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
(function(env) {
|
(function(env) {
|
||||||
function hasFunctioningTypedArrays() {
|
function hasFunctioningTypedArrays() {
|
||||||
if (typeof Uint32Array === 'undefined') {
|
if (typeof Uint32Array === 'undefined') {
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
(function(env) {
|
(function(env) {
|
||||||
env.registerIntegrationMatchers = function() {
|
env.registerIntegrationMatchers = function() {
|
||||||
jasmine.addMatchers({
|
jasmine.addMatchers({
|
||||||
toHaveFailedExpectationsForRunnable: function(
|
toHaveFailedExpectationsForRunnable: function() {
|
||||||
util,
|
|
||||||
customeEqualityTesters
|
|
||||||
) {
|
|
||||||
return {
|
return {
|
||||||
compare: function(actual, fullName, expectedFailures) {
|
compare: function(actual, fullName, expectedFailures) {
|
||||||
var foundRunnable = false,
|
var foundRunnable = false,
|
||||||
|
|||||||
16
spec/helpers/requireFastCheck.js
Normal file
16
spec/helpers/requireFastCheck.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
(function(env) {
|
||||||
|
var NODE_JS =
|
||||||
|
typeof process !== 'undefined' &&
|
||||||
|
process.versions &&
|
||||||
|
typeof process.versions.node === 'string';
|
||||||
|
|
||||||
|
env.requireFastCheck = function() {
|
||||||
|
if (!NODE_JS) {
|
||||||
|
env.pending(
|
||||||
|
"Property tests don't run in the browser. Use `npm test` to run them."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return require('fast-check');
|
||||||
|
};
|
||||||
|
})(jasmine.getEnv());
|
||||||
@@ -1,7 +1,16 @@
|
|||||||
describe('HtmlReporter', function() {
|
describe('HtmlReporter', function() {
|
||||||
|
var env;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
env = new jasmineUnderTest.Env();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
it('builds the initial DOM elements, including the title banner', function() {
|
it('builds the initial DOM elements, including the title banner', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -37,8 +46,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('builds a single reporter even if initialized multiple times', function() {
|
it('builds a single reporter even if initialized multiple times', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -71,7 +79,7 @@ describe('HtmlReporter', function() {
|
|||||||
|
|
||||||
container = document.createElement('div');
|
container = document.createElement('div');
|
||||||
reporter = new jasmineUnderTest.HtmlReporter({
|
reporter = new jasmineUnderTest.HtmlReporter({
|
||||||
env: new jasmineUnderTest.Env(),
|
env: env,
|
||||||
getContainer: function() {
|
getContainer: function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -119,8 +127,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports the status symbol of a excluded spec', function() {
|
it('reports the status symbol of a excluded spec', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -152,8 +159,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports the status symbol of a pending spec', function() {
|
it('reports the status symbol of a pending spec', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -182,8 +188,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports the status symbol of a passing spec', function() {
|
it('reports the status symbol of a passing spec', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -213,8 +218,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports the status symbol of a failing spec', function() {
|
it('reports the status symbol of a failing spec', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -246,8 +250,7 @@ describe('HtmlReporter', function() {
|
|||||||
|
|
||||||
describe('when there are deprecation warnings', function() {
|
describe('when there are deprecation warnings', function() {
|
||||||
it('displays the messages in their own alert bars', function() {
|
it('displays the messages in their own alert bars', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -298,8 +301,7 @@ describe('HtmlReporter', function() {
|
|||||||
if (!window.console) {
|
if (!window.console) {
|
||||||
window.console = { error: function() {} };
|
window.console = { error: function() {} };
|
||||||
}
|
}
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -343,8 +345,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports the run time', function() {
|
it('reports the run time', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -372,8 +373,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports the suite and spec names with status', function() {
|
it('reports the suite and spec names with status', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -490,8 +490,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has an options menu', function() {
|
it('has an options menu', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -529,8 +528,7 @@ describe('HtmlReporter', function() {
|
|||||||
|
|
||||||
describe('when there are global errors', function() {
|
describe('when there are global errors', function() {
|
||||||
it('displays the exceptions in their own alert bars', function() {
|
it('displays the exceptions in their own alert bars', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -576,8 +574,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('displays file and line information if available', function() {
|
it('displays file and line information if available', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -619,8 +616,7 @@ describe('HtmlReporter', function() {
|
|||||||
|
|
||||||
describe('UI for stop on spec failure', function() {
|
describe('UI for stop on spec failure', function() {
|
||||||
it('should be unchecked for full execution', function() {
|
it('should be unchecked for full execution', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -643,8 +639,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be checked if stopping short', function() {
|
it('should be checked if stopping short', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -669,8 +664,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and turn the setting on', function() {
|
it('should navigate and turn the setting on', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
navigationHandler = jasmine.createSpy('navigate'),
|
navigationHandler = jasmine.createSpy('navigate'),
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -697,8 +691,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and turn the setting off', function() {
|
it('should navigate and turn the setting off', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
navigationHandler = jasmine.createSpy('navigate'),
|
navigationHandler = jasmine.createSpy('navigate'),
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -729,8 +722,7 @@ describe('HtmlReporter', function() {
|
|||||||
|
|
||||||
describe('UI for throwing errors on expectation failures', function() {
|
describe('UI for throwing errors on expectation failures', function() {
|
||||||
it('should be unchecked if not throwing', function() {
|
it('should be unchecked if not throwing', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -753,8 +745,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be checked if throwing', function() {
|
it('should be checked if throwing', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -779,8 +770,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to on', function() {
|
it('should navigate and change the setting to on', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
navigateHandler = jasmine.createSpy('navigate'),
|
navigateHandler = jasmine.createSpy('navigate'),
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -807,8 +797,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to off', function() {
|
it('should navigate and change the setting to off', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
navigateHandler = jasmine.createSpy('navigate'),
|
navigateHandler = jasmine.createSpy('navigate'),
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -838,8 +827,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
describe('UI for hiding disabled specs', function() {
|
describe('UI for hiding disabled specs', function() {
|
||||||
it('should be unchecked if not hiding disabled specs', function() {
|
it('should be unchecked if not hiding disabled specs', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -863,8 +851,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be checked if hiding disabled', function() {
|
it('should be checked if hiding disabled', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -888,8 +875,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not display specs that have been disabled', function() {
|
it('should not display specs that have been disabled', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -922,8 +908,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
describe('UI for running tests in random order', function() {
|
describe('UI for running tests in random order', function() {
|
||||||
it('should be unchecked if not randomizing', function() {
|
it('should be unchecked if not randomizing', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -947,8 +932,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be checked if randomizing', function() {
|
it('should be checked if randomizing', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -972,8 +956,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to on', function() {
|
it('should navigate and change the setting to on', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
navigateHandler = jasmine.createSpy('navigate'),
|
navigateHandler = jasmine.createSpy('navigate'),
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -1001,8 +984,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to off', function() {
|
it('should navigate and change the setting to off', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
navigateHandler = jasmine.createSpy('navigate'),
|
navigateHandler = jasmine.createSpy('navigate'),
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -1030,8 +1012,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show the seed bar if randomizing', function() {
|
it('should show the seed bar if randomizing', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -1061,8 +1042,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not show the current seed bar if not randomizing', function() {
|
it('should not show the current seed bar if not randomizing', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -1085,8 +1065,7 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should include non-spec query params in the jasmine-skipped link when present', function() {
|
it('should include non-spec query params in the jasmine-skipped link when present', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
reporter = new jasmineUnderTest.HtmlReporter({
|
reporter = new jasmineUnderTest.HtmlReporter({
|
||||||
env: env,
|
env: env,
|
||||||
getContainer: function() {
|
getContainer: function() {
|
||||||
@@ -1113,9 +1092,8 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('and all specs pass', function() {
|
describe('and all specs pass', function() {
|
||||||
var env, container;
|
var container;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
|
||||||
container = document.createElement('div');
|
container = document.createElement('div');
|
||||||
var getContainer = function() {
|
var getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -1175,9 +1153,8 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('and there are excluded specs', function() {
|
describe('and there are excluded specs', function() {
|
||||||
var env, container, reporter, reporterConfig, specStatus;
|
var container, reporter, reporterConfig, specStatus;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
|
||||||
container = document.createElement('div');
|
container = document.createElement('div');
|
||||||
reporterConfig = {
|
reporterConfig = {
|
||||||
env: env,
|
env: env,
|
||||||
@@ -1239,9 +1216,8 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('and there are pending specs', function() {
|
describe('and there are pending specs', function() {
|
||||||
var env, container, reporter;
|
var container, reporter;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
|
||||||
container = document.createElement('div');
|
container = document.createElement('div');
|
||||||
var getContainer = function() {
|
var getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -1297,10 +1273,9 @@ describe('HtmlReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('and some tests fail', function() {
|
describe('and some tests fail', function() {
|
||||||
var env, container, reporter;
|
var container, reporter;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
|
||||||
container = document.createElement('div');
|
container = document.createElement('div');
|
||||||
var getContainer = function() {
|
var getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
@@ -1469,8 +1444,7 @@ describe('HtmlReporter', function() {
|
|||||||
describe('The overall result bar', function() {
|
describe('The overall result bar', function() {
|
||||||
describe("When the jasmineDone event's overallStatus is 'passed'", function() {
|
describe("When the jasmineDone event's overallStatus is 'passed'", function() {
|
||||||
it('has class jasmine-passed', function() {
|
it('has class jasmine-passed', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -1500,8 +1474,7 @@ describe('HtmlReporter', function() {
|
|||||||
|
|
||||||
describe("When the jasmineDone event's overallStatus is 'failed'", function() {
|
describe("When the jasmineDone event's overallStatus is 'failed'", function() {
|
||||||
it('has class jasmine-failed', function() {
|
it('has class jasmine-failed', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
@@ -1531,8 +1504,7 @@ describe('HtmlReporter', function() {
|
|||||||
|
|
||||||
describe("When the jasmineDone event's overallStatus is 'incomplete'", function() {
|
describe("When the jasmineDone event's overallStatus is 'incomplete'", function() {
|
||||||
it('has class jasmine-incomplete', function() {
|
it('has class jasmine-incomplete', function() {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var container = document.createElement('div'),
|
||||||
container = document.createElement('div'),
|
|
||||||
getContainer = function() {
|
getContainer = function() {
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ describe('MatchersSpec - HTML Dependent', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
env.cleanup_();
|
||||||
|
});
|
||||||
|
|
||||||
function match(value) {
|
function match(value) {
|
||||||
return spec.expect(value);
|
return spec.expect(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,46 @@
|
|||||||
describe('jasmineUnderTest.pp (HTML Dependent)', function() {
|
describe('PrettyPrinter (HTML Dependent)', function() {
|
||||||
it('should stringify non-element HTML nodes properly', function() {
|
it('should stringify non-element HTML nodes properly', function() {
|
||||||
var sampleNode = document.createTextNode('');
|
var sampleNode = document.createTextNode('');
|
||||||
expect(jasmineUnderTest.pp(sampleNode)).toEqual('HTMLNode');
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(jasmineUnderTest.pp({ foo: sampleNode })).toEqual(
|
expect(pp(sampleNode)).toEqual('HTMLNode');
|
||||||
'Object({ foo: HTMLNode })'
|
expect(pp({ foo: sampleNode })).toEqual('Object({ foo: HTMLNode })');
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify empty HTML elements as their opening tags', function() {
|
it('should stringify empty HTML elements as their opening tags', function() {
|
||||||
var simple = document.createElement('div');
|
var simple = document.createElement('div');
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
simple.className = 'foo';
|
simple.className = 'foo';
|
||||||
expect(jasmineUnderTest.pp(simple)).toEqual('<div class="foo">');
|
expect(pp(simple)).toEqual('<div class="foo">');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify non-empty HTML elements as tags with placeholders', function() {
|
it('should stringify non-empty HTML elements as tags with placeholders', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var nonEmpty = document.createElement('div');
|
var nonEmpty = document.createElement('div');
|
||||||
nonEmpty.className = 'foo';
|
nonEmpty.className = 'foo';
|
||||||
nonEmpty.innerHTML = '<p>Irrelevant</p>';
|
nonEmpty.innerHTML = '<p>Irrelevant</p>';
|
||||||
expect(jasmineUnderTest.pp(nonEmpty)).toEqual('<div class="foo">...</div>');
|
expect(pp(nonEmpty)).toEqual('<div class="foo">...</div>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should print Firefox's wrapped native objects correctly", function() {
|
it("should print Firefox's wrapped native objects correctly", function() {
|
||||||
if (jasmine.getEnv().firefoxVersion) {
|
if (jasmine.getEnv().firefoxVersion) {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
try {
|
try {
|
||||||
new CustomEvent();
|
new CustomEvent();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var err = e;
|
var err = e;
|
||||||
}
|
}
|
||||||
// Different versions of FF produce different error messages.
|
// Different versions of FF produce different error messages.
|
||||||
expect(jasmineUnderTest.pp(err)).toMatch(
|
expect(pp(err)).toMatch(
|
||||||
/Not enough arguments|CustomEvent requires at least 1 argument, but only 0 were passed/
|
/Not enough arguments|CustomEvent.*only 0.*passed/
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify HTML element with text and attributes', function() {
|
it('should stringify HTML element with text and attributes', function() {
|
||||||
|
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var el = document.createElement('div');
|
var el = document.createElement('div');
|
||||||
el.setAttribute('things', 'foo');
|
el.setAttribute('things', 'foo');
|
||||||
el.innerHTML = 'foo';
|
el.innerHTML = 'foo';
|
||||||
expect(jasmineUnderTest.pp(el)).toEqual('<div things="foo">...</div>');
|
expect(pp(el)).toEqual('<div things="foo">...</div>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe('npm package', function() {
|
|||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.addMatchers({
|
jasmine.addMatchers({
|
||||||
toExistInPath: function(util, customEquality) {
|
toExistInPath: function() {
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
var fullPath = path.resolve(expected, actual);
|
var fullPath = path.resolve(expected, actual);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ module.exports = {
|
|||||||
'helpers/domHelpers.js',
|
'helpers/domHelpers.js',
|
||||||
'helpers/integrationMatchers.js',
|
'helpers/integrationMatchers.js',
|
||||||
'helpers/promises.js',
|
'helpers/promises.js',
|
||||||
|
'helpers/requireFastCheck.js',
|
||||||
'helpers/defineJasmineUnderTest.js'
|
'helpers/defineJasmineUnderTest.js'
|
||||||
],
|
],
|
||||||
random: true,
|
random: true,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"helpers/domHelpers.js",
|
"helpers/domHelpers.js",
|
||||||
"helpers/integrationMatchers.js",
|
"helpers/integrationMatchers.js",
|
||||||
"helpers/promises.js",
|
"helpers/promises.js",
|
||||||
|
"helpers/requireFastCheck.js",
|
||||||
"helpers/nodeDefineJasmineUnderTest.js"
|
"helpers/nodeDefineJasmineUnderTest.js"
|
||||||
],
|
],
|
||||||
"random": true
|
"random": true
|
||||||
|
|||||||
128
src/core/Env.js
128
src/core/Env.js
@@ -276,6 +276,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
var customMatchers =
|
var customMatchers =
|
||||||
runnableResources[currentRunnable().id].customMatchers;
|
runnableResources[currentRunnable().id].customMatchers;
|
||||||
|
|
||||||
for (var matcherName in matchersToAdd) {
|
for (var matcherName in matchersToAdd) {
|
||||||
customMatchers[matcherName] = matchersToAdd[matcherName];
|
customMatchers[matcherName] = matchersToAdd[matcherName];
|
||||||
}
|
}
|
||||||
@@ -289,11 +290,24 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
var customAsyncMatchers =
|
var customAsyncMatchers =
|
||||||
runnableResources[currentRunnable().id].customAsyncMatchers;
|
runnableResources[currentRunnable().id].customAsyncMatchers;
|
||||||
|
|
||||||
for (var matcherName in matchersToAdd) {
|
for (var matcherName in matchersToAdd) {
|
||||||
customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
|
customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.addCustomObjectFormatter = function(formatter) {
|
||||||
|
if (!currentRunnable()) {
|
||||||
|
throw new Error(
|
||||||
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
runnableResources[currentRunnable().id].customObjectFormatters.push(
|
||||||
|
formatter
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
j$.Expectation.addCoreMatchers(j$.matchers);
|
j$.Expectation.addCoreMatchers(j$.matchers);
|
||||||
j$.Expectation.addAsyncCoreMatchers(j$.asyncMatchers);
|
j$.Expectation.addAsyncCoreMatchers(j$.asyncMatchers);
|
||||||
|
|
||||||
@@ -307,10 +321,28 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return 'suite' + nextSuiteId++;
|
return 'suite' + nextSuiteId++;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var makePrettyPrinter = function() {
|
||||||
|
var customObjectFormatters =
|
||||||
|
runnableResources[currentRunnable().id].customObjectFormatters;
|
||||||
|
return j$.makePrettyPrinter(customObjectFormatters);
|
||||||
|
};
|
||||||
|
|
||||||
|
var makeMatchersUtil = function() {
|
||||||
|
var customEqualityTesters =
|
||||||
|
runnableResources[currentRunnable().id].customEqualityTesters;
|
||||||
|
return new j$.MatchersUtil({
|
||||||
|
customTesters: customEqualityTesters,
|
||||||
|
pp: makePrettyPrinter()
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var expectationFactory = function(actual, spec) {
|
var expectationFactory = function(actual, spec) {
|
||||||
|
var customEqualityTesters =
|
||||||
|
runnableResources[spec.id].customEqualityTesters;
|
||||||
|
|
||||||
return j$.Expectation.factory({
|
return j$.Expectation.factory({
|
||||||
util: j$.matchersUtil,
|
matchersUtil: makeMatchersUtil(),
|
||||||
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
|
customEqualityTesters: customEqualityTesters,
|
||||||
customMatchers: runnableResources[spec.id].customMatchers,
|
customMatchers: runnableResources[spec.id].customMatchers,
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -321,9 +353,35 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var asyncExpectationFactory = function(actual, spec) {
|
function recordLateExpectation(runable, runableType, result) {
|
||||||
|
var delayedExpectationResult = {};
|
||||||
|
Object.keys(result).forEach(function(k) {
|
||||||
|
delayedExpectationResult[k] = result[k];
|
||||||
|
});
|
||||||
|
delayedExpectationResult.passed = false;
|
||||||
|
delayedExpectationResult.globalErrorType = 'lateExpectation';
|
||||||
|
delayedExpectationResult.message =
|
||||||
|
runableType +
|
||||||
|
' "' +
|
||||||
|
runable.getFullName() +
|
||||||
|
'" ran a "' +
|
||||||
|
result.matcherName +
|
||||||
|
'" expectation after it finished.\n';
|
||||||
|
|
||||||
|
if (result.message) {
|
||||||
|
delayedExpectationResult.message +=
|
||||||
|
'Message: "' + result.message + '"\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
delayedExpectationResult.message +=
|
||||||
|
'Did you forget to return or await the result of expectAsync?';
|
||||||
|
|
||||||
|
topSuite.result.failedExpectations.push(delayedExpectationResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
var asyncExpectationFactory = function(actual, spec, runableType) {
|
||||||
return j$.Expectation.asyncFactory({
|
return j$.Expectation.asyncFactory({
|
||||||
util: j$.matchersUtil,
|
matchersUtil: makeMatchersUtil(),
|
||||||
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
|
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
|
||||||
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
|
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
|
||||||
actual: actual,
|
actual: actual,
|
||||||
@@ -331,9 +389,19 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function addExpectationResult(passed, result) {
|
function addExpectationResult(passed, result) {
|
||||||
|
if (currentRunnable() !== spec) {
|
||||||
|
recordLateExpectation(spec, runableType, result);
|
||||||
|
}
|
||||||
return spec.addExpectationResult(passed, result);
|
return spec.addExpectationResult(passed, result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var suiteAsyncExpectationFactory = function(actual, suite) {
|
||||||
|
return asyncExpectationFactory(actual, suite, 'Suite');
|
||||||
|
};
|
||||||
|
|
||||||
|
var specAsyncExpectationFactory = function(actual, suite) {
|
||||||
|
return asyncExpectationFactory(actual, suite, 'Spec');
|
||||||
|
};
|
||||||
|
|
||||||
var defaultResourcesForRunnable = function(id, parentRunnableId) {
|
var defaultResourcesForRunnable = function(id, parentRunnableId) {
|
||||||
var resources = {
|
var resources = {
|
||||||
@@ -342,7 +410,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
customMatchers: {},
|
customMatchers: {},
|
||||||
customAsyncMatchers: {},
|
customAsyncMatchers: {},
|
||||||
customSpyStrategies: {},
|
customSpyStrategies: {},
|
||||||
defaultStrategyFn: undefined
|
defaultStrategyFn: undefined,
|
||||||
|
customObjectFormatters: []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (runnableResources[parentRunnableId]) {
|
if (runnableResources[parentRunnableId]) {
|
||||||
@@ -551,7 +620,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
id: getNextSuiteId(),
|
id: getNextSuiteId(),
|
||||||
description: 'Jasmine__TopLevel__Suite',
|
description: 'Jasmine__TopLevel__Suite',
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: asyncExpectationFactory,
|
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory
|
expectationResultFactory: expectationResultFactory
|
||||||
});
|
});
|
||||||
defaultResourcesForRunnable(topSuite.id);
|
defaultResourcesForRunnable(topSuite.id);
|
||||||
@@ -883,8 +952,9 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
id: getNextSuiteId(),
|
id: getNextSuiteId(),
|
||||||
description: description,
|
description: description,
|
||||||
parentSuite: currentDeclarationSuite,
|
parentSuite: currentDeclarationSuite,
|
||||||
|
timer: new j$.Timer(),
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: asyncExpectationFactory,
|
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory,
|
expectationResultFactory: expectationResultFactory,
|
||||||
throwOnExpectationFailure: config.oneFailurePerSpec
|
throwOnExpectationFailure: config.oneFailurePerSpec
|
||||||
});
|
});
|
||||||
@@ -978,7 +1048,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
id: getNextSpecId(),
|
id: getNextSpecId(),
|
||||||
beforeAndAfterFns: beforeAndAfterFns(suite),
|
beforeAndAfterFns: beforeAndAfterFns(suite),
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: asyncExpectationFactory,
|
asyncExpectationFactory: specAsyncExpectationFactory,
|
||||||
resultCallback: specResultCallback,
|
resultCallback: specResultCallback,
|
||||||
getSpecName: function(spec) {
|
getSpecName: function(spec) {
|
||||||
return getSpecName(spec, suite);
|
return getSpecName(spec, suite);
|
||||||
@@ -1054,6 +1124,40 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return spec;
|
return spec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a user-defined property that will be provided to reporters as part of the properties field of {@link SpecResult}
|
||||||
|
* @name Env#setSpecProperty
|
||||||
|
* @since 3.6.0
|
||||||
|
* @function
|
||||||
|
* @param {String} key The name of the property
|
||||||
|
* @param {*} value The value of the property
|
||||||
|
*/
|
||||||
|
this.setSpecProperty = function(key, value) {
|
||||||
|
if (!currentRunnable() || currentRunnable() == currentSuite()) {
|
||||||
|
throw new Error(
|
||||||
|
"'setSpecProperty' was used when there was no current spec"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
currentRunnable().setSpecProperty(key, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a user-defined property that will be provided to reporters as part of the properties field of {@link SuiteResult}
|
||||||
|
* @name Env#setSuiteProperty
|
||||||
|
* @since 3.6.0
|
||||||
|
* @function
|
||||||
|
* @param {String} key The name of the property
|
||||||
|
* @param {*} value The value of the property
|
||||||
|
*/
|
||||||
|
this.setSuiteProperty = function(key, value) {
|
||||||
|
if (!currentSuite()) {
|
||||||
|
throw new Error(
|
||||||
|
"'setSuiteProperty' was used when there was no current suite"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
currentSuite().setSuiteProperty(key, value);
|
||||||
|
};
|
||||||
|
|
||||||
this.expect = function(actual) {
|
this.expect = function(actual) {
|
||||||
if (!currentRunnable()) {
|
if (!currentRunnable()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -1135,7 +1239,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
message += error;
|
message += error;
|
||||||
} else {
|
} else {
|
||||||
// pretty print all kind of objects. This includes arrays.
|
// pretty print all kind of objects. This includes arrays.
|
||||||
message += j$.pp(error);
|
message += makePrettyPrinter()(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1152,6 +1256,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.cleanup_ = function() {
|
||||||
|
if (globalErrors) {
|
||||||
|
globalErrors.uninstall();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return Env;
|
return Env;
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function negatedFailureMessage(result, matcherName, args, util) {
|
function negatedFailureMessage(result, matcherName, args, matchersUtil) {
|
||||||
if (result.message) {
|
if (result.message) {
|
||||||
if (j$.isFunction_(result.message)) {
|
if (j$.isFunction_(result.message)) {
|
||||||
return result.message();
|
return result.message();
|
||||||
@@ -141,7 +141,7 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
args = args.slice();
|
args = args.slice();
|
||||||
args.unshift(true);
|
args.unshift(true);
|
||||||
args.unshift(matcherName);
|
args.unshift(matcherName);
|
||||||
return util.buildFailureMessage.apply(null, args);
|
return matchersUtil.buildFailureMessage.apply(matchersUtil, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function negate(result) {
|
function negate(result) {
|
||||||
@@ -176,9 +176,19 @@ getJasmineRequireObj().Expectation = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
|
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
|
||||||
return this.message + ': ' + msg;
|
var nl = msg.indexOf('\n');
|
||||||
|
|
||||||
|
if (nl === -1) {
|
||||||
|
return this.message + ': ' + msg;
|
||||||
|
} else {
|
||||||
|
return this.message + ':\n' + indent(msg);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function indent(s) {
|
||||||
|
return s.replace(/^/gm, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
factory: function(options) {
|
factory: function(options) {
|
||||||
return new Expectation(options || {});
|
return new Expectation(options || {});
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ getJasmineRequireObj().ExpectationFilterChain = function() {
|
|||||||
result,
|
result,
|
||||||
matcherName,
|
matcherName,
|
||||||
args,
|
args,
|
||||||
util
|
matchersUtil
|
||||||
) {
|
) {
|
||||||
return this.callFirst_('buildFailureMessage', arguments).result;
|
return this.callFirst_('buildFailureMessage', arguments).result;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//TODO: expectation result may make more sense as a presentation of an expectation.
|
//TODO: expectation result may make more sense as a presentation of an expectation.
|
||||||
getJasmineRequireObj().buildExpectationResult = function() {
|
getJasmineRequireObj().buildExpectationResult = function(j$) {
|
||||||
function buildExpectationResult(options) {
|
function buildExpectationResult(options) {
|
||||||
var messageFormatter = options.messageFormatter || function() {},
|
var messageFormatter = options.messageFormatter || function() {},
|
||||||
stackFormatter = options.stackFormatter || function() {};
|
stackFormatter = options.stackFormatter || function() {};
|
||||||
@@ -23,6 +23,22 @@ getJasmineRequireObj().buildExpectationResult = function() {
|
|||||||
if (!result.passed) {
|
if (!result.passed) {
|
||||||
result.expected = options.expected;
|
result.expected = options.expected;
|
||||||
result.actual = options.actual;
|
result.actual = options.actual;
|
||||||
|
|
||||||
|
if (options.error && !j$.isString_(options.error)) {
|
||||||
|
if ('code' in options.error) {
|
||||||
|
result.code = options.error.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
options.error.code === 'ERR_ASSERTION' &&
|
||||||
|
options.expected === '' &&
|
||||||
|
options.actual === ''
|
||||||
|
) {
|
||||||
|
result.expected = options.error.expected;
|
||||||
|
result.actual = options.error.actual;
|
||||||
|
result.matcherName = 'assert ' + options.error.operator;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
getJasmineRequireObj().Expector = function(j$) {
|
getJasmineRequireObj().Expector = function(j$) {
|
||||||
function Expector(options) {
|
function Expector(options) {
|
||||||
this.util = options.util || { buildFailureMessage: function() {} };
|
this.matchersUtil = options.matchersUtil || {
|
||||||
|
buildFailureMessage: function() {}
|
||||||
|
};
|
||||||
this.customEqualityTesters = options.customEqualityTesters || [];
|
this.customEqualityTesters = options.customEqualityTesters || [];
|
||||||
this.actual = options.actual;
|
this.actual = options.actual;
|
||||||
this.addExpectationResult = options.addExpectationResult || function() {};
|
this.addExpectationResult = options.addExpectationResult || function() {};
|
||||||
@@ -18,7 +20,7 @@ getJasmineRequireObj().Expector = function(j$) {
|
|||||||
|
|
||||||
this.args.unshift(this.actual);
|
this.args.unshift(this.actual);
|
||||||
|
|
||||||
var matcher = matcherFactory(this.util, this.customEqualityTesters);
|
var matcher = matcherFactory(this.matchersUtil, this.customEqualityTesters);
|
||||||
var comparisonFunc = this.filters.selectComparisonFunc(matcher);
|
var comparisonFunc = this.filters.selectComparisonFunc(matcher);
|
||||||
return comparisonFunc || matcher.compare;
|
return comparisonFunc || matcher.compare;
|
||||||
};
|
};
|
||||||
@@ -34,7 +36,7 @@ getJasmineRequireObj().Expector = function(j$) {
|
|||||||
result,
|
result,
|
||||||
this.matcherName,
|
this.matcherName,
|
||||||
this.args,
|
this.args,
|
||||||
this.util,
|
this.matchersUtil,
|
||||||
defaultMessage
|
defaultMessage
|
||||||
);
|
);
|
||||||
return this.filters.modifyFailureMessage(msg || defaultMessage());
|
return this.filters.modifyFailureMessage(msg || defaultMessage());
|
||||||
@@ -44,7 +46,10 @@ getJasmineRequireObj().Expector = function(j$) {
|
|||||||
var args = self.args.slice();
|
var args = self.args.slice();
|
||||||
args.unshift(false);
|
args.unshift(false);
|
||||||
args.unshift(self.matcherName);
|
args.unshift(self.matcherName);
|
||||||
return self.util.buildFailureMessage.apply(null, args);
|
return self.matchersUtil.buildFailureMessage.apply(
|
||||||
|
self.matchersUtil,
|
||||||
|
args
|
||||||
|
);
|
||||||
} else if (j$.isFunction_(result.message)) {
|
} else if (j$.isFunction_(result.message)) {
|
||||||
return result.message();
|
return result.message();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -63,8 +63,31 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
var originalHandler = global.onerror;
|
var originalHandler = global.onerror;
|
||||||
global.onerror = onerror;
|
global.onerror = onerror;
|
||||||
|
|
||||||
|
var browserRejectionHandler = function browserRejectionHandler(event) {
|
||||||
|
if (j$.isError_(event.reason)) {
|
||||||
|
event.reason.jasmineMessage =
|
||||||
|
'Unhandled promise rejection: ' + event.reason;
|
||||||
|
onerror(event.reason);
|
||||||
|
} else {
|
||||||
|
onerror('Unhandled promise rejection: ' + event.reason);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (global.addEventListener) {
|
||||||
|
global.addEventListener(
|
||||||
|
'unhandledrejection',
|
||||||
|
browserRejectionHandler
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.uninstall = function uninstall() {
|
this.uninstall = function uninstall() {
|
||||||
global.onerror = originalHandler;
|
global.onerror = originalHandler;
|
||||||
|
if (global.removeEventListener) {
|
||||||
|
global.removeEventListener(
|
||||||
|
'unhandledrejection',
|
||||||
|
browserRejectionHandler
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
* @hideconstructor
|
* @hideconstructor
|
||||||
*/
|
*/
|
||||||
function JsApiReporter(options) {
|
function JsApiReporter(options) {
|
||||||
var timer = options.timer || j$.noopTimer,
|
var timer = options.timer || new j$.Timer(),
|
||||||
status = 'loaded';
|
status = 'loaded';
|
||||||
|
|
||||||
this.started = false;
|
this.started = false;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
getJasmineRequireObj().pp = function(j$) {
|
getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||||
function PrettyPrinter() {
|
function SinglePrettyPrintRun(customObjectFormatters, pp) {
|
||||||
|
this.customObjectFormatters_ = customObjectFormatters;
|
||||||
this.ppNestLevel_ = 0;
|
this.ppNestLevel_ = 0;
|
||||||
this.seen = [];
|
this.seen = [];
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
this.stringParts = [];
|
this.stringParts = [];
|
||||||
|
this.pp_ = pp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCustomToString(value) {
|
function hasCustomToString(value) {
|
||||||
@@ -21,10 +23,14 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrettyPrinter.prototype.format = function(value) {
|
SinglePrettyPrintRun.prototype.format = function(value) {
|
||||||
this.ppNestLevel_++;
|
this.ppNestLevel_++;
|
||||||
try {
|
try {
|
||||||
if (j$.util.isUndefined(value)) {
|
var customFormatResult = this.applyCustomFormatters_(value);
|
||||||
|
|
||||||
|
if (customFormatResult) {
|
||||||
|
this.emitScalar(customFormatResult);
|
||||||
|
} else if (j$.util.isUndefined(value)) {
|
||||||
this.emitScalar('undefined');
|
this.emitScalar('undefined');
|
||||||
} else if (value === null) {
|
} else if (value === null) {
|
||||||
this.emitScalar('null');
|
this.emitScalar('null');
|
||||||
@@ -33,7 +39,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
} else if (value === j$.getGlobal()) {
|
} else if (value === j$.getGlobal()) {
|
||||||
this.emitScalar('<global>');
|
this.emitScalar('<global>');
|
||||||
} else if (value.jasmineToString) {
|
} else if (value.jasmineToString) {
|
||||||
this.emitScalar(value.jasmineToString());
|
this.emitScalar(value.jasmineToString(this.pp_));
|
||||||
} else if (typeof value === 'string') {
|
} else if (typeof value === 'string') {
|
||||||
this.emitString(value);
|
this.emitString(value);
|
||||||
} else if (j$.isSpy(value)) {
|
} else if (j$.isSpy(value)) {
|
||||||
@@ -95,7 +101,11 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
SinglePrettyPrintRun.prototype.applyCustomFormatters_ = function(value) {
|
||||||
|
return customFormat(value, this.customObjectFormatters_);
|
||||||
|
};
|
||||||
|
|
||||||
|
SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) {
|
||||||
var objKeys = keys(obj, j$.isArray_(obj));
|
var objKeys = keys(obj, j$.isArray_(obj));
|
||||||
var isGetter = function isGetter(prop) {};
|
var isGetter = function isGetter(prop) {};
|
||||||
|
|
||||||
@@ -114,15 +124,15 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
return objKeys.length > length;
|
return objKeys.length > length;
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitScalar = function(value) {
|
SinglePrettyPrintRun.prototype.emitScalar = function(value) {
|
||||||
this.append(value);
|
this.append(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitString = function(value) {
|
SinglePrettyPrintRun.prototype.emitString = function(value) {
|
||||||
this.append("'" + value + "'");
|
this.append("'" + value + "'");
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitArray = function(array) {
|
SinglePrettyPrintRun.prototype.emitArray = function(array) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Array');
|
this.append('Array');
|
||||||
return;
|
return;
|
||||||
@@ -158,7 +168,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' ]');
|
this.append(' ]');
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitSet = function(set) {
|
SinglePrettyPrintRun.prototype.emitSet = function(set) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Set');
|
this.append('Set');
|
||||||
return;
|
return;
|
||||||
@@ -183,7 +193,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' )');
|
this.append(' )');
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitMap = function(map) {
|
SinglePrettyPrintRun.prototype.emitMap = function(map) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Map');
|
this.append('Map');
|
||||||
return;
|
return;
|
||||||
@@ -208,7 +218,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' )');
|
this.append(' )');
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitObject = function(obj) {
|
SinglePrettyPrintRun.prototype.emitObject = function(obj) {
|
||||||
var ctor = obj.constructor,
|
var ctor = obj.constructor,
|
||||||
constructorName;
|
constructorName;
|
||||||
|
|
||||||
@@ -244,7 +254,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' })');
|
this.append(' })');
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitTypedArray = function(arr) {
|
SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) {
|
||||||
var constructorName = j$.fnNameFor(arr.constructor),
|
var constructorName = j$.fnNameFor(arr.constructor),
|
||||||
limitedArray = Array.prototype.slice.call(
|
limitedArray = Array.prototype.slice.call(
|
||||||
arr,
|
arr,
|
||||||
@@ -260,7 +270,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitDomElement = function(el) {
|
SinglePrettyPrintRun.prototype.emitDomElement = function(el) {
|
||||||
var tagName = el.tagName.toLowerCase(),
|
var tagName = el.tagName.toLowerCase(),
|
||||||
attrs = el.attributes,
|
attrs = el.attributes,
|
||||||
i,
|
i,
|
||||||
@@ -286,7 +296,11 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(out);
|
this.append(out);
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
SinglePrettyPrintRun.prototype.formatProperty = function(
|
||||||
|
obj,
|
||||||
|
property,
|
||||||
|
isGetter
|
||||||
|
) {
|
||||||
this.append(property);
|
this.append(property);
|
||||||
this.append(': ');
|
this.append(': ');
|
||||||
if (isGetter) {
|
if (isGetter) {
|
||||||
@@ -296,7 +310,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.append = function(value) {
|
SinglePrettyPrintRun.prototype.append = function(value) {
|
||||||
// This check protects us from the rare case where an object has overriden
|
// This check protects us from the rare case where an object has overriden
|
||||||
// `toString()` with an invalid implementation (returning a non-string).
|
// `toString()` with an invalid implementation (returning a non-string).
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
@@ -360,9 +374,32 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
|
|
||||||
return extraKeys;
|
return extraKeys;
|
||||||
}
|
}
|
||||||
return function(value) {
|
|
||||||
var prettyPrinter = new PrettyPrinter();
|
function customFormat(value, customObjectFormatters) {
|
||||||
prettyPrinter.format(value);
|
var i, result;
|
||||||
return prettyPrinter.stringParts.join('');
|
|
||||||
|
for (i = 0; i < customObjectFormatters.length; i++) {
|
||||||
|
result = customObjectFormatters[i](value);
|
||||||
|
|
||||||
|
if (result !== undefined) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return function(customObjectFormatters) {
|
||||||
|
customObjectFormatters = customObjectFormatters || [];
|
||||||
|
|
||||||
|
var pp = function(value) {
|
||||||
|
var prettyPrinter = new SinglePrettyPrintRun(customObjectFormatters, pp);
|
||||||
|
prettyPrinter.format(value);
|
||||||
|
return prettyPrinter.stringParts.join('');
|
||||||
|
};
|
||||||
|
|
||||||
|
pp.customFormat_ = function(value) {
|
||||||
|
return customFormat(value, customObjectFormatters);
|
||||||
|
};
|
||||||
|
|
||||||
|
return pp;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||||
this.timer = attrs.timer || j$.noopTimer;
|
this.timer = attrs.timer || new j$.Timer();
|
||||||
|
|
||||||
if (!this.queueableFn.fn) {
|
if (!this.queueableFn.fn) {
|
||||||
this.pend();
|
this.pend();
|
||||||
@@ -48,6 +48,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
|
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
|
||||||
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
|
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
|
||||||
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
||||||
|
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
||||||
*/
|
*/
|
||||||
this.result = {
|
this.result = {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
@@ -57,7 +58,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
passedExpectations: [],
|
passedExpectations: [],
|
||||||
deprecationWarnings: [],
|
deprecationWarnings: [],
|
||||||
pendingReason: '',
|
pendingReason: '',
|
||||||
duration: null
|
duration: null,
|
||||||
|
properties: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +76,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Spec.prototype.setSpecProperty = function(key, value) {
|
||||||
|
this.result.properties = this.result.properties || {};
|
||||||
|
this.result.properties[key] = value;
|
||||||
|
};
|
||||||
|
|
||||||
Spec.prototype.expect = function(actual) {
|
Spec.prototype.expect = function(actual) {
|
||||||
return this.expectationFactory(actual, this);
|
return this.expectationFactory(actual, this);
|
||||||
};
|
};
|
||||||
@@ -96,6 +103,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
self.queueableFn.fn = null;
|
self.queueableFn.fn = null;
|
||||||
self.result.status = self.status(excluded, failSpecWithNoExp);
|
self.result.status = self.status(excluded, failSpecWithNoExp);
|
||||||
|
self.result.duration = self.timer.elapsed();
|
||||||
self.resultCallback(self.result, done);
|
self.resultCallback(self.result, done);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -111,7 +119,6 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
self.onException.apply(self, arguments);
|
self.onException.apply(self, arguments);
|
||||||
},
|
},
|
||||||
onComplete: function() {
|
onComplete: function() {
|
||||||
self.result.duration = self.timer.elapsed();
|
|
||||||
onComplete(
|
onComplete(
|
||||||
self.result.status === 'failed' &&
|
self.result.status === 'failed' &&
|
||||||
new j$.StopExecutionError('spec failed')
|
new j$.StopExecutionError('spec failed')
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
var matchersUtil = new j$.MatchersUtil({
|
||||||
|
customTesters: [],
|
||||||
|
pp: j$.makePrettyPrinter()
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _Note:_ Do not construct this directly, use {@link spyOn}, {@link spyOnProperty}, {@link jasmine.createSpy}, or {@link jasmine.createSpyObj}
|
* _Note:_ Do not construct this directly, use {@link spyOn}, {@link spyOnProperty}, {@link jasmine.createSpy}, or {@link jasmine.createSpyObj}
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -20,8 +25,8 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
getPromise
|
getPromise
|
||||||
) {
|
) {
|
||||||
var numArgs = typeof originalFn === 'function' ? originalFn.length : 0,
|
var numArgs = typeof originalFn === 'function' ? originalFn.length : 0,
|
||||||
wrapper = makeFunc(numArgs, function() {
|
wrapper = makeFunc(numArgs, function(context, args, invokeNew) {
|
||||||
return spy.apply(this, Array.prototype.slice.call(arguments));
|
return spy(context, args, invokeNew);
|
||||||
}),
|
}),
|
||||||
strategyDispatcher = new SpyStrategyDispatcher({
|
strategyDispatcher = new SpyStrategyDispatcher({
|
||||||
name: name,
|
name: name,
|
||||||
@@ -33,7 +38,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
getPromise: getPromise
|
getPromise: getPromise
|
||||||
}),
|
}),
|
||||||
callTracker = new j$.CallTracker(),
|
callTracker = new j$.CallTracker(),
|
||||||
spy = function() {
|
spy = function(context, args, invokeNew) {
|
||||||
/**
|
/**
|
||||||
* @name Spy.callData
|
* @name Spy.callData
|
||||||
* @property {object} object - `this` context for the invocation.
|
* @property {object} object - `this` context for the invocation.
|
||||||
@@ -41,13 +46,13 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
* @property {Array} args - The arguments passed for this invocation.
|
* @property {Array} args - The arguments passed for this invocation.
|
||||||
*/
|
*/
|
||||||
var callData = {
|
var callData = {
|
||||||
object: this,
|
object: context,
|
||||||
invocationOrder: nextOrder(),
|
invocationOrder: nextOrder(),
|
||||||
args: Array.prototype.slice.apply(arguments)
|
args: Array.prototype.slice.apply(args)
|
||||||
};
|
};
|
||||||
|
|
||||||
callTracker.track(callData);
|
callTracker.track(callData);
|
||||||
var returnValue = strategyDispatcher.exec(this, arguments);
|
var returnValue = strategyDispatcher.exec(context, args, invokeNew);
|
||||||
callData.returnValue = returnValue;
|
callData.returnValue = returnValue;
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
@@ -56,44 +61,44 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
function makeFunc(length, fn) {
|
function makeFunc(length, fn) {
|
||||||
switch (length) {
|
switch (length) {
|
||||||
case 1:
|
case 1:
|
||||||
return function(a) {
|
return function wrap1(a) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap1);
|
||||||
};
|
};
|
||||||
case 2:
|
case 2:
|
||||||
return function(a, b) {
|
return function wrap2(a, b) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap2);
|
||||||
};
|
};
|
||||||
case 3:
|
case 3:
|
||||||
return function(a, b, c) {
|
return function wrap3(a, b, c) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap3);
|
||||||
};
|
};
|
||||||
case 4:
|
case 4:
|
||||||
return function(a, b, c, d) {
|
return function wrap4(a, b, c, d) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap4);
|
||||||
};
|
};
|
||||||
case 5:
|
case 5:
|
||||||
return function(a, b, c, d, e) {
|
return function wrap5(a, b, c, d, e) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap5);
|
||||||
};
|
};
|
||||||
case 6:
|
case 6:
|
||||||
return function(a, b, c, d, e, f) {
|
return function wrap6(a, b, c, d, e, f) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap6);
|
||||||
};
|
};
|
||||||
case 7:
|
case 7:
|
||||||
return function(a, b, c, d, e, f, g) {
|
return function wrap7(a, b, c, d, e, f, g) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap7);
|
||||||
};
|
};
|
||||||
case 8:
|
case 8:
|
||||||
return function(a, b, c, d, e, f, g, h) {
|
return function wrap8(a, b, c, d, e, f, g, h) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap8);
|
||||||
};
|
};
|
||||||
case 9:
|
case 9:
|
||||||
return function(a, b, c, d, e, f, g, h, i) {
|
return function wrap9(a, b, c, d, e, f, g, h, i) {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap9);
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return function() {
|
return function wrap() {
|
||||||
return fn.apply(this, arguments);
|
return fn(this, arguments, this instanceof wrap);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +155,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
|
|
||||||
this.and = baseStrategy;
|
this.and = baseStrategy;
|
||||||
|
|
||||||
this.exec = function(spy, args) {
|
this.exec = function(spy, args, invokeNew) {
|
||||||
var strategy = argsStrategies.get(args);
|
var strategy = argsStrategies.get(args);
|
||||||
|
|
||||||
if (!strategy) {
|
if (!strategy) {
|
||||||
@@ -167,7 +172,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return strategy.exec(spy, args);
|
return strategy.exec(spy, args, invokeNew);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.withArgs = function() {
|
this.withArgs = function() {
|
||||||
@@ -202,7 +207,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
|||||||
var i;
|
var i;
|
||||||
|
|
||||||
for (i = 0; i < this.strategies.length; i++) {
|
for (i = 0; i < this.strategies.length; i++) {
|
||||||
if (j$.matchersUtil.equals(args, this.strategies[i].args)) {
|
if (matchersUtil.equals(args, this.strategies[i].args)) {
|
||||||
return this.strategies[i].strategy;
|
return this.strategies[i].strategy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,8 +96,13 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @function
|
* @function
|
||||||
*/
|
*/
|
||||||
SpyStrategy.prototype.exec = function(context, args) {
|
SpyStrategy.prototype.exec = function(context, args, invokeNew) {
|
||||||
return this.plan.apply(context, args);
|
var contextArgs = [context].concat(
|
||||||
|
args ? Array.prototype.slice.call(args) : []
|
||||||
|
);
|
||||||
|
var target = this.plan.bind.apply(this.plan, contextArgs);
|
||||||
|
|
||||||
|
return invokeNew ? new target() : target();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,10 +150,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
* @name SpyStrategy#throwError
|
* @name SpyStrategy#throwError
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @function
|
* @function
|
||||||
* @param {Error|String} something Thing to throw
|
* @param {Error|Object|String} something Thing to throw
|
||||||
*/
|
*/
|
||||||
SpyStrategy.prototype.throwError = function(something) {
|
SpyStrategy.prototype.throwError = function(something) {
|
||||||
var error = something instanceof Error ? something : new Error(something);
|
var error = j$.isString_(something) ? new Error(something) : something;
|
||||||
this.plan = function() {
|
this.plan = function() {
|
||||||
throw error;
|
throw error;
|
||||||
};
|
};
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user