Compare commits
248 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e86a7f00a6 | ||
|
|
504ef27899 | ||
|
|
572452a15a | ||
|
|
896412367a | ||
|
|
503a7409f0 | ||
|
|
bb9175cb66 | ||
|
|
469b557828 | ||
|
|
503715c275 | ||
|
|
4482355885 | ||
|
|
6542364381 | ||
|
|
1fc911e0fa | ||
|
|
fdad8849df | ||
|
|
7a289f1de7 | ||
|
|
ef981bb794 | ||
|
|
c3fb3e985a | ||
|
|
7fc3408051 | ||
|
|
af1b43eeff | ||
|
|
4c043717a9 | ||
|
|
40be00310d | ||
|
|
1f318c3c93 | ||
|
|
be29aa95eb | ||
|
|
e3c9a59c6c | ||
|
|
b312ed4940 | ||
|
|
00f6708e1f | ||
|
|
3a47a3bd04 | ||
|
|
1c9382c990 | ||
|
|
394be99832 | ||
|
|
62a667a8e3 | ||
|
|
d277827d5e | ||
|
|
644c175338 | ||
|
|
a6d7eb2a06 | ||
|
|
dd8a65cb60 | ||
|
|
e72d161fab | ||
|
|
dcaac62a6c | ||
|
|
b696bec9e3 | ||
|
|
43073b3bc5 | ||
|
|
286524959b | ||
|
|
2c32dd5703 | ||
|
|
c1d1d69be2 | ||
|
|
3513249d73 | ||
|
|
21bfbbb721 | ||
|
|
88b90ec258 | ||
|
|
50c88e7774 | ||
|
|
3e64ce3310 | ||
|
|
00586e50e0 | ||
|
|
dc80a282ba | ||
|
|
27c650ec08 | ||
|
|
56daa6f461 | ||
|
|
e4c7d8af45 | ||
|
|
ee88ecc614 | ||
|
|
ec038273f1 | ||
|
|
c5bdd79a1e | ||
|
|
dbc1a0aa56 | ||
|
|
5862b22aef | ||
|
|
163f93d6ff | ||
|
|
1893bf6c16 | ||
|
|
095745ab12 | ||
|
|
68db3f6fcf | ||
|
|
1e4f0d1545 | ||
|
|
c546d2cb6d | ||
|
|
6e097528f5 | ||
|
|
4e1f36cbb0 | ||
|
|
0aee81cfb9 | ||
|
|
1e50b49092 | ||
|
|
6aecf16cde | ||
|
|
f2de1be96a | ||
|
|
5f4a1c4276 | ||
|
|
a4ef3687ee | ||
|
|
9065b4c3b7 | ||
|
|
140225e7c3 | ||
|
|
8b38389d56 | ||
|
|
b7c2a2f6fb | ||
|
|
c5d4a40219 | ||
|
|
c7c8b6b93e | ||
|
|
8a42437059 | ||
|
|
cacc6f4278 | ||
|
|
d815e99456 | ||
|
|
5e3f937221 | ||
|
|
d666f1efbb | ||
|
|
4515b76f07 | ||
|
|
0897e31a2d | ||
|
|
9555cb9842 | ||
|
|
d6fa9dd1a0 | ||
|
|
25fbe0646a | ||
|
|
316ce1e2d3 | ||
|
|
82cc1083b6 | ||
|
|
c2f04ba627 | ||
|
|
97a46f4560 | ||
|
|
113134cdbd | ||
|
|
dad5f5fd6b | ||
|
|
fa72544974 | ||
|
|
e303de52ed | ||
|
|
5f9315731e | ||
|
|
ce850c472a | ||
|
|
2fc5182ddc | ||
|
|
6be2102b64 | ||
|
|
c6a79d3ab7 | ||
|
|
3f232fba80 | ||
|
|
cde6ea79a3 | ||
|
|
0782a73a98 | ||
|
|
37073e2768 | ||
|
|
f7f928fdd3 | ||
|
|
503b653a10 | ||
|
|
cb044aa273 | ||
|
|
5c17456925 | ||
|
|
592fba22b8 | ||
|
|
58ef707bc6 | ||
|
|
050c1f051c | ||
|
|
8d0c52e2ec | ||
|
|
de91427356 | ||
|
|
324bc201c2 | ||
|
|
76f34e90dc | ||
|
|
46e7158c77 | ||
|
|
9ab039e330 | ||
|
|
3f5c47dff3 | ||
|
|
1320b0614f | ||
|
|
905e3fc3f9 | ||
|
|
89331bb1bb | ||
|
|
88de272c89 | ||
|
|
60bbe68148 | ||
|
|
623e638cd4 | ||
|
|
b1bcd6e825 | ||
|
|
204acf7297 | ||
|
|
cd1131354b | ||
|
|
c24aef15b1 | ||
|
|
d5d5d1965f | ||
|
|
d27bb8fa96 | ||
|
|
7d5ca27b9d | ||
|
|
795651d3b6 | ||
|
|
e7daa429a1 | ||
|
|
51ad18cb28 | ||
|
|
0b81705c11 | ||
|
|
00feef8632 | ||
|
|
5a715aecee | ||
|
|
8cb44582bc | ||
|
|
53d8073707 | ||
|
|
e0eb4755cb | ||
|
|
6277046213 | ||
|
|
6b9739030d | ||
|
|
b0d949e0d5 | ||
|
|
dfdcfc5be5 | ||
|
|
e5bb89847f | ||
|
|
1f68ed836e | ||
|
|
c4e65e4a9a | ||
|
|
0cfeb0b9c3 | ||
|
|
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 | ||
|
|
2745d7d515 |
205
.circleci/config.yml
Normal file
205
.circleci/config.yml
Normal file
@@ -0,0 +1,205 @@
|
||||
# Run tests against supported Node versions, and (except for pull requests)
|
||||
# against supported browsers.
|
||||
|
||||
version: 2.1
|
||||
|
||||
orbs:
|
||||
node: circleci/node@3.0.0
|
||||
|
||||
executors:
|
||||
node16:
|
||||
docker:
|
||||
- image: cimg/node:16.1.0-browsers
|
||||
working_directory: ~/workspace
|
||||
node14:
|
||||
docker:
|
||||
- image: circleci/node:14
|
||||
working_directory: ~/workspace
|
||||
node12:
|
||||
docker:
|
||||
- image: circleci/node:12
|
||||
working_directory: ~/workspace
|
||||
node10:
|
||||
docker:
|
||||
- image: circleci/node:10
|
||||
working_directory: ~/workspace
|
||||
|
||||
jobs:
|
||||
build:
|
||||
parameters:
|
||||
executor:
|
||||
type: executor
|
||||
executor: << parameters.executor >>
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Report Node and NPM versions
|
||||
command: echo "Using Node $(node --version) and NPM $(npm --version)"
|
||||
- run:
|
||||
name: Install dependencies
|
||||
command: npm install
|
||||
- run:
|
||||
name: Build
|
||||
command: npm run build
|
||||
- persist_to_workspace:
|
||||
root: .
|
||||
paths:
|
||||
- .
|
||||
|
||||
test_node: &test_node
|
||||
parameters:
|
||||
executor:
|
||||
type: executor
|
||||
executor: << parameters.executor >>
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Run tests
|
||||
command: npm test
|
||||
|
||||
test_browsers: &test_browsers
|
||||
executor: node14
|
||||
environment:
|
||||
SKIP_JASMINE_BROWSER_FLAKES: "true"
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Install Sauce Connect
|
||||
command: |
|
||||
cd /tmp
|
||||
curl https://saucelabs.com/downloads/sc-4.6.4-linux.tar.gz | tar zxf -
|
||||
chmod +x sc-4.6.4-linux/bin/sc
|
||||
mkdir ~/workspace/bin
|
||||
cp sc-4.6.4-linux/bin/sc ~/workspace/bin
|
||||
~/workspace/bin/sc --version
|
||||
- run:
|
||||
name: Run tests
|
||||
command: |
|
||||
# Do everything in one step because Sauce Connect won't exit
|
||||
# cleanly if we kill it from a different step than it started in.
|
||||
|
||||
export PATH=$PATH:$HOME/workspace/bin
|
||||
export SAUCE_TUNNEL_IDENTIFIER=$CIRCLE_BUILD_NUM
|
||||
scripts/start-sauce-connect sauce-pidfile
|
||||
set +o errexit
|
||||
scripts/run-all-browsers
|
||||
exitcode=$?
|
||||
set -o errexit
|
||||
scripts/stop-sauce-connect $(cat sauce-pidfile)
|
||||
exit $exitcode
|
||||
|
||||
test_browser_flakes:
|
||||
<<: *test_browsers
|
||||
environment:
|
||||
SKIP_JASMINE_BROWSER_FLAKES: "false"
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
cron:
|
||||
triggers:
|
||||
- schedule:
|
||||
# Times are UTC.
|
||||
cron: "0 11 * * *"
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
- "3.99"
|
||||
- "4.0"
|
||||
jobs:
|
||||
- build:
|
||||
executor: node16
|
||||
name: build_node_16
|
||||
- build:
|
||||
executor: node14
|
||||
name: build_node_14
|
||||
- build:
|
||||
executor: node12
|
||||
name: build_node_12
|
||||
- build:
|
||||
executor: node10
|
||||
name: build_node_10
|
||||
- test_node:
|
||||
executor: node16
|
||||
name: test_node_16
|
||||
requires:
|
||||
- build_node_16
|
||||
- test_node:
|
||||
executor: node12
|
||||
name: test_node_12
|
||||
requires:
|
||||
- build_node_12
|
||||
- test_node:
|
||||
executor: node10
|
||||
name: test_node_10
|
||||
requires:
|
||||
- build_node_10
|
||||
- test_browsers:
|
||||
requires:
|
||||
- build_node_14
|
||||
filters:
|
||||
branches:
|
||||
ignore: /pull\/.*/ # Don't run on pull requests.
|
||||
|
||||
push:
|
||||
jobs:
|
||||
- build:
|
||||
executor: node16
|
||||
name: build_node_16
|
||||
- build:
|
||||
executor: node14
|
||||
name: build_node_14
|
||||
- build:
|
||||
executor: node12
|
||||
name: build_node_12
|
||||
- build:
|
||||
executor: node10
|
||||
name: build_node_10
|
||||
- test_node:
|
||||
executor: node16
|
||||
name: test_node_16
|
||||
requires:
|
||||
- build_node_16
|
||||
- test_node:
|
||||
executor: node14
|
||||
name: test_node_14
|
||||
requires:
|
||||
- build_node_14
|
||||
- test_node:
|
||||
executor: node12
|
||||
name: test_node_12
|
||||
requires:
|
||||
- build_node_12
|
||||
- test_node:
|
||||
executor: node10
|
||||
name: test_node_10
|
||||
requires:
|
||||
- build_node_10
|
||||
- test_browsers:
|
||||
requires:
|
||||
- build_node_14
|
||||
filters:
|
||||
branches:
|
||||
ignore: /pull\/.*/ # Don't run on pull requests.
|
||||
|
||||
browser-flakes:
|
||||
triggers:
|
||||
- schedule:
|
||||
# Times are UTC.
|
||||
cron: "0 10 * * *"
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- browser-flakes
|
||||
jobs:
|
||||
- build:
|
||||
executor: node14
|
||||
name: build_node_14
|
||||
- test_browser_flakes:
|
||||
requires:
|
||||
- build_node_14
|
||||
filters:
|
||||
branches:
|
||||
ignore: /pull\/.*/ # Don't run on pull requests.
|
||||
87
.github/CONTRIBUTING.md
vendored
87
.github/CONTRIBUTING.md
vendored
@@ -1,6 +1,12 @@
|
||||
# Developing for Jasmine Core
|
||||
|
||||
We welcome your contributions! Thanks for helping make Jasmine a better project for everyone. Please review the backlog and discussion lists before starting work. What you're looking for may already have been done. If it hasn't, the community can help make your contribution better. If you want to contribute but don't know what to work on, [issues tagged ready for work](https://github.com/jasmine/jasmine/labels/ready%20for%20work) should have enough detail to get started.
|
||||
We welcome your contributions! Thanks for helping make Jasmine a better project
|
||||
for everyone. Please review the backlog and discussion lists before starting
|
||||
work. What you're looking for may already have been done. If it hasn't, the
|
||||
community can help make your contribution better. If you want to contribute but
|
||||
don't know what to work on,
|
||||
[issues tagged help needed](https://github.com/jasmine/jasmine/labels/help%20needed)
|
||||
should have enough detail to get started.
|
||||
|
||||
## Links
|
||||
|
||||
@@ -17,7 +23,7 @@ git clone git@github.com:yourUserName/jasmine.git # Clone your fork
|
||||
cd jasmine # Change directory
|
||||
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 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 commit -am 'Add some feature' # Commit your changes
|
||||
git push origin my-new-feature # Push to the branch
|
||||
@@ -35,8 +41,8 @@ Once you've pushed a feature branch to your forked repo, you're ready to open a
|
||||
* `/spec` contains all of the tests
|
||||
* mirrors the source directory
|
||||
* there are some additional files
|
||||
* `/dist` contains the standalone distributions as zip files
|
||||
* `/lib` contains the generated files for distribution as the Jasmine Rubygem and the Python package
|
||||
* `/lib` contains the compiled copy of Jasmine. This is used to self-test and
|
||||
distributed as the `jasmine-core` Node, Ruby, and Python packages.
|
||||
|
||||
### Self-testing
|
||||
|
||||
@@ -44,39 +50,31 @@ Note that Jasmine tests itself. The files in `lib` are loaded first, defining th
|
||||
|
||||
The tests should always use `jasmineUnderTest` to refer to the objects and functions that are being tested. But the tests can use functions on `jasmine` as needed. _Be careful how you structure any new test code_. Copy the patterns you see in the existing code - this ensures that the code you're testing is not leaking into the `jasmine` reference and vice-versa.
|
||||
|
||||
### `boot.js`
|
||||
### `boot0.js` and `boot1.js`
|
||||
|
||||
This file does all of the setup necessary for Jasmine to work. It loads all of the code, creates an `Env`, attaches the global functions, and builds the reporter. It also sets up the execution of the `Env` - for browsers this is in `window.onload`. While the default in `lib` is appropriate for browsers, projects may wish to customize this file.
|
||||
|
||||
For example, for Jasmine development there is a different `dev_boot.js` for Jasmine development that does more work.
|
||||
These files file does all of the setup necessary for Jasmine to work in a
|
||||
browser. They load all of the code, create an `Env`, attach the global
|
||||
functions, and build the reporter. It also sets up the execution of the
|
||||
`Env` - for browsers this is in `window.onload`. While the default in `lib`
|
||||
is appropriate for browsers, projects may wish to customize this file.
|
||||
|
||||
### Compatibility
|
||||
|
||||
Jasmine supports the following environments:
|
||||
|
||||
* Browsers
|
||||
* IE10+
|
||||
* Edge Latest
|
||||
* Firefox Latest
|
||||
* Chrome Latest
|
||||
* Safari 8+
|
||||
|
||||
* Node.js
|
||||
* 8
|
||||
* 10
|
||||
* 12
|
||||
Jasmine runs in both Node and browsers, including some older browsers that do
|
||||
not support the latest JavaScript features. See the README for the list of
|
||||
currently supported environments.
|
||||
|
||||
## Development
|
||||
|
||||
All source code belongs in `src/`. The `core/` directory contains the bulk of Jasmine's functionality. This code should remain browser- and environment-agnostic. If your feature or fix cannot be, as mentioned above, please degrade gracefully. Any code that depends on a browser (specifically, it expects `window` to be the global or `document` is present) should live in `src/html/`.
|
||||
|
||||
### Install Dependencies
|
||||
### Install Dev Dependencies
|
||||
|
||||
Jasmine Core relies on Node.js.
|
||||
|
||||
To install the Node dependencies, you will need Node.js, Npm, and [Grunt](http://gruntjs.com/), the [grunt-cli](https://github.com/gruntjs/grunt-cli) and ensure that `grunt` is on your path.
|
||||
To install the Node dependencies, you will need Node.js and npm.
|
||||
|
||||
$ npm install --local
|
||||
$ npm install
|
||||
|
||||
...will install all of the node modules locally. Now run
|
||||
|
||||
@@ -88,22 +86,35 @@ To install the Node dependencies, you will need Node.js, Npm, and [Grunt](http:/
|
||||
|
||||
Or, How to make a successful pull request
|
||||
|
||||
* _Do not change the public interface_. Lots of projects depend on Jasmine and if you aren't careful you'll break them
|
||||
* _Be environment agnostic_ - server-side developers are just as important as browser developers
|
||||
* _Be browser agnostic_ - if you must rely on browser-specific functionality, please write it in a way that degrades gracefully
|
||||
* _Write specs_ - Jasmine's a testing framework; don't add functionality without test-driving it
|
||||
* _Write code in the style of the rest of the repo_ - Jasmine should look like a cohesive whole
|
||||
* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and ESLint - your contribution shouldn't break Jasmine for other users
|
||||
* _Do not change the public interface_. Lots of projects depend on Jasmine and
|
||||
if you aren't careful you'll break them.
|
||||
* _Be environment agnostic_ - server-side developers are just as important as
|
||||
browser developers.
|
||||
* _Be browser agnostic_ - if you must rely on browser-specific functionality,
|
||||
please write it in a way that degrades gracefully.
|
||||
* _Write specs_ - Jasmine's a testing framework. Don't add functionality
|
||||
without test-driving it.
|
||||
* _Write code in the style of the rest of the repo_ - Jasmine should look like
|
||||
a cohesive whole.
|
||||
* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and
|
||||
ESLint. Your contribution shouldn't break Jasmine for other users.
|
||||
|
||||
Follow these tips and your pull request, patch, or suggestion is much more likely to be integrated.
|
||||
|
||||
### Running Specs
|
||||
|
||||
Jasmine uses some internal tooling to test itself in browser on Travis. This tooling _should_ work locally as well.
|
||||
Be sure to run the tests in at least one supported Node version and at least a
|
||||
couple of supported browsers. It's also a good idea to run the tests in Internet
|
||||
Explorer if you've touched code in `src/html`, if your change involves newer
|
||||
JavaScript language/runtime features, or if you're unfamiliar with writing code
|
||||
for older browsers. To run the tests in Node, simply use `npm test` as described
|
||||
above. To run the tests in a browser, run `npm run serve` and then visit
|
||||
`http://localhost:8888`.
|
||||
|
||||
$ node ci.js
|
||||
If you have the necessary Selenium drivers installed, you can also use Jasmine's
|
||||
CI tooling:
|
||||
|
||||
You can also set the `JASMINE_BROWSER` environment variable to specify which browser should be used.
|
||||
$ JASMINE_BROWSER=<name of browser> node spec/support/ci.js
|
||||
|
||||
The easiest way to run the tests in **Internet Explorer** is to run a VM that has IE installed. It's easy to do this with VirtualBox.
|
||||
|
||||
@@ -112,16 +123,16 @@ The easiest way to run the tests in **Internet Explorer** is to run a VM that ha
|
||||
1. Unzip the downloaded archive. There should be an OVA file inside.
|
||||
1. In VirtualBox, choose `File > Import Appliance` and select the OVA file. Accept the default settings in the dialog that appears. Now you have a Windows VM!
|
||||
1. Run the VM and start IE.
|
||||
1. With `npm run serve` running on your host machine, navigate to `http://10.0.2.2:8888` in IE.
|
||||
1. With `npm run serve` running on your host machine, navigate to `http://<your IP address>:8888` in IE.
|
||||
|
||||
## Before Committing or Submitting a Pull Request
|
||||
|
||||
1. Ensure all specs are green in browser *and* node
|
||||
1. Ensure all specs are green in browser *and* node.
|
||||
1. Ensure eslint and prettier are clean as part of your `npm test` command. You can run `npm run cleanup` to have prettier re-write the files.
|
||||
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`
|
||||
* 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 Circle CI for Continuous Integration. We only accept green pull requests.
|
||||
|
||||
|
||||
3
.github/ISSUE_TEMPLATE.md
vendored
3
.github/ISSUE_TEMPLATE.md
vendored
@@ -3,9 +3,12 @@
|
||||
- When in doubt, create an issue here.
|
||||
- If you have an issue with the Jasmine docs, file an issue in the docs repo
|
||||
here: https://github.com/jasmine/jasmine.github.io
|
||||
- If you have an issue with TypeScript typings, start a discussion at
|
||||
[DefinitelyTpyed](https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/new?category=issues-with-a-types-package)
|
||||
- This repository is for the core Jasmine framework
|
||||
- If you are using a test runner that wraps Jasmine, consider filing an issue with that library if appropriate:
|
||||
- [Jasmine npm](https://github.com/jasmine/jasmine-npm/issues)
|
||||
- [Jasmine browser runner](https://github.com/jasmine/jasmine-browser/issues)
|
||||
- [Jasmine gem](https://github.com/jasmine/jasmine-gem/issues)
|
||||
- [Jasmine py](https://github.com/jasmine/jasmine-py/issues)
|
||||
- [Gulp Jasmine Browser](https://github.com/jasmine/gulp-jasmine-browser/issues)
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,3 +25,4 @@ build/
|
||||
dist
|
||||
nbproject/
|
||||
*.iml
|
||||
.envrc
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "pages"]
|
||||
path = pages
|
||||
url = https://github.com/pivotal/jasmine.git
|
||||
29
.npmignore
29
.npmignore
@@ -1,29 +0,0 @@
|
||||
dist/
|
||||
grunt/
|
||||
node_modules
|
||||
pkg/
|
||||
release_notes/
|
||||
spec/
|
||||
src/
|
||||
Gemfile
|
||||
Gemfile.lock
|
||||
Rakefile
|
||||
jasmine-core.gemspec
|
||||
.bundle/
|
||||
.gitignore
|
||||
.gitmodules
|
||||
.idea
|
||||
.jshintrc
|
||||
.rspec
|
||||
.sass-cache/
|
||||
.travis.yml
|
||||
*.sh
|
||||
*.py
|
||||
Gruntfile.js
|
||||
lib/jasmine-core.rb
|
||||
lib/jasmine-core/boot/
|
||||
lib/jasmine-core/spec
|
||||
lib/jasmine-core/version.rb
|
||||
lib/jasmine-core/*.py
|
||||
sauce_connect.log
|
||||
ci.js
|
||||
52
.travis.yml
52
.travis.yml
@@ -1,52 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10"
|
||||
- "8"
|
||||
- "12"
|
||||
|
||||
script: $TEST_COMMAND
|
||||
|
||||
env:
|
||||
global:
|
||||
- USE_SAUCE=true
|
||||
- TEST_COMMAND="bash travis-core-script.sh"
|
||||
- secure: WSPWhlnC4mWSnSPquX+m1/BCu5ch5NygkaHuM2Nea7lD8oS3XLX8QncZZAsQ4lnNfqoDDuBOizG0AESiqNvE4y6x5qvLLTS6q+ce255ZEMZ71TBdZgDEEvGMEjOPPsVXiXyTQOP1lwOPlrbZvaPgWV7e11KIBab6DfFcQpnvDgo=
|
||||
- secure: SW7CJhZnwaNT749Gdnhvqb5rbXlAOsygUAzh9qhtyvbqXKkmJdBIEsO01YF6pbju1X2twE9JvWCOxeZju43NgQChJlPsGbjY2j3k/TdQeTAJesQe2K7ytwghunI30gjEovtRH0T3w1EmcKPH8yj5eBIcB2OYoJHx8KEC7e68q1g=
|
||||
matrix:
|
||||
- TEST_COMMAND="npm test"
|
||||
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- env: JASMINE_BROWSER="firefox" SAUCE_BROWSER_VERSION='' SAUCE_OS="Linux"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="chrome" SAUCE_BROWSER_VERSION='' SAUCE_OS="Linux"
|
||||
if: type != pull_request
|
||||
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"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="internet explorer" SAUCE_BROWSER_VERSION=10 SAUCE_OS="Windows 8"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
66
README.md
66
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://circleci.com/gh/jasmine/jasmine)
|
||||
[](https://www.codetriage.com/jasmine/jasmine)
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_shield)
|
||||
|
||||
@@ -9,59 +9,65 @@
|
||||
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/)
|
||||
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).
|
||||
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).
|
||||
|
||||
## 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
|
||||
|
||||
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 browser runner:<br>
|
||||
[https://github.com/jasmine/jasmine-browser](https://github.com/jasmine/jasmine-browser).
|
||||
|
||||
For the Jasmine Ruby Gem:<br>
|
||||
[https://github.com/jasmine/jasmine-gem](https://github.com/jasmine/jasmine-gem)
|
||||
|
||||
For the Jasmine Python Egg:<br>
|
||||
[https://github.com/jasmine/jasmine-py](https://github.com/jasmine/jasmine-py)
|
||||
|
||||
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/jasmine-gem](https://github.com/jasmine/jasmine-gem).
|
||||
|
||||
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)
|
||||
* 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`
|
||||
* Change directory - `cd my-project/jasmine`
|
||||
* Unzip the dist - `unzip jasmine-standalone-{#.#.#}.zip`
|
||||
* 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`
|
||||
* Move the dist to your project directory. - `mv jasmine/dist/jasmine-standalone-{#.#.#}.zip my-project/jasmine`
|
||||
* Change directory. - `cd my-project/jasmine`
|
||||
* Unzip the dist. - `unzip jasmine-standalone-{#.#.#}.zip`
|
||||
|
||||
Add the following to your HTML file:
|
||||
|
||||
```html
|
||||
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-{#.#.#}/jasmine_favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-{#.#.#}/jasmine.css">
|
||||
<link rel="shortcut icon" type="image/png" href="lib/jasmine-{#.#.#}/jasmine_favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="lib/jasmine-{#.#.#}/jasmine.css">
|
||||
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine.js"></script>
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine-html.js"></script>
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/boot.js"></script>
|
||||
<script type="text/javascript" src="lib/jasmine-{#.#.#}/jasmine.js"></script>
|
||||
<script type="text/javascript" src="lib/jasmine-{#.#.#}/jasmine-html.js"></script>
|
||||
<script type="text/javascript" src="lib/jasmine-{#.#.#}/boot.js"></script>
|
||||
```
|
||||
|
||||
## 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 | 10, 12, 14, 16 |
|
||||
| Safari | 8-14 |
|
||||
| Chrome | Evergreen |
|
||||
| Firefox | Evergreen, 68, 78 |
|
||||
| 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
|
||||
|
||||
* 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)
|
||||
* 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)
|
||||
* 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).
|
||||
* 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).
|
||||
|
||||
## Maintainers
|
||||
|
||||
|
||||
73
RELEASE.md
73
RELEASE.md
@@ -7,7 +7,7 @@ Follow the instructions in `CONTRIBUTING.md` during development.
|
||||
|
||||
### 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
|
||||
|
||||
@@ -28,31 +28,38 @@ When jasmine-core revs its major or minor version, the binding libraries should
|
||||
|
||||
When ready to release - specs are all green and the stories are done:
|
||||
|
||||
1. Update the release notes in `release_notes` - use the Anchorman gem to generate the markdown file and edit accordingly
|
||||
1. Update the version in `package.json` to a release candidate
|
||||
1. Update any links or top-level landing page for the Github Pages
|
||||
1. Update the release notes in `release_notes` - use the Anchorman gem to generate the markdown file and edit accordingly. Include a list of supported environments.
|
||||
1. Update the version in `package.json`
|
||||
1. Run `npm run build`.
|
||||
1. Copy version to the Ruby gem with `grunt build:copyVersionToGem`
|
||||
|
||||
### Commit and push core changes
|
||||
|
||||
1. Run the browser tests using `scripts/run-all-browsers`.
|
||||
1. Commit release notes and version changes (jasmine.js, version.rb, package.json)
|
||||
1. Push
|
||||
1. Wait for Circle CI to go green
|
||||
|
||||
### Build standalone distribution
|
||||
|
||||
1. Build the standalone distribution with `grunt buildStandaloneDist`
|
||||
1. This will generate `dist/jasmine-standalone-<version>.zip`, which you will upload later (see "Finally" below).
|
||||
|
||||
### Release the Python egg
|
||||
### Release the core Ruby gem
|
||||
|
||||
1. __NOTE__: You will likely need to push a new jasmine gem with a dependent version right after this release. See below.
|
||||
1. `rake release` - tags the repo with the version, builds the `jasmine-core` gem, pushes the gem to Rubygems.org. In order to release you will have to ensure you have rubygems creds locally.
|
||||
|
||||
### Release the core Python egg
|
||||
|
||||
Install [twine](https://github.com/pypa/twine)
|
||||
|
||||
1. `python setup.py sdist`
|
||||
1. `twine upload dist/jasmine-core-<version>.tar.gz` You will need pypi credentials to upload the egg.
|
||||
|
||||
### Release the Ruby gem
|
||||
|
||||
1. Copy version to the Ruby gem with `grunt build:copyVersionToGem`
|
||||
1. __NOTE__: You will likely need to point to a local jasmine gem in order to run tests locally. _Do not_ push this version of the Gemfile.
|
||||
1. __NOTE__: You will likely need to push a new jasmine gem with a dependent version right after this release.
|
||||
1. Push these changes to GitHub and verify that this SHA is green
|
||||
1. `rake release` - tags the repo with the version, builds the `jasmine-core` gem, pushes the gem to Rubygems.org. In order to release you will have to ensure you have rubygems creds locally.
|
||||
|
||||
### Release the NPM
|
||||
### Release the core NPM module
|
||||
|
||||
1. Run the tests on Windows. (CI only tests on Linux.)
|
||||
1. `npm adduser` to save your credentials locally
|
||||
1. `npm publish .` to publish what's in `package.json`
|
||||
|
||||
@@ -60,15 +67,35 @@ Install [twine](https://github.com/pypa/twine)
|
||||
|
||||
Probably only need to do this when releasing a minor version, and not a patch version.
|
||||
|
||||
1. `cp -R edge ${version}` to copy the current edge docs to the new version
|
||||
1. Add a link to the new version in `index.html`
|
||||
1. `rake update_edge_jasmine`
|
||||
1. `npm run jsdoc`
|
||||
1. `rake release[${version}]` to copy the current edge docs to the new version
|
||||
1. Commit and push.
|
||||
|
||||
### Release the binding libraries
|
||||
|
||||
#### NPM
|
||||
|
||||
1. Create release notes using Anchorman as above
|
||||
1. In `package.json`, update both the package version and the jasmine-core dependency version
|
||||
1. Commit and push.
|
||||
1. Wait for Circle CI to go green again.
|
||||
1. Run the tests on Windows locally.
|
||||
1. `grunt release `. (Note: This will publish the package by running `npm publish`.)
|
||||
|
||||
#### Gem
|
||||
|
||||
1. Create release notes using Anchorman as above
|
||||
1. Update the version number in `lib/jasmine/version.rb`.
|
||||
1. Update the jasmine-core dependency version in `jasmine.gemspec`.
|
||||
1. Commit and push.
|
||||
1. Wait for Circle CI to go green again.
|
||||
1. `rake release`
|
||||
|
||||
### Finally
|
||||
|
||||
1. Visit the [Releases page for Jasmine](https://github.com/jasmine/jasmine/releases), find the tag just pushed.
|
||||
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
|
||||
1. If it is a pre-release, mark it as such.
|
||||
1. Attach the standalone zipfile
|
||||
|
||||
|
||||
There should be a post to Pivotal Labs blog and a tweet to that link.
|
||||
For each of the above GitHub repos:
|
||||
1. Visit the releases page and find the tag just published.
|
||||
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
|
||||
1. If it is a pre-release, mark it as such.
|
||||
1. For core, attach the standalone zipfile.
|
||||
|
||||
@@ -29,7 +29,7 @@ module.exports = {
|
||||
cwd: libJasmineCore("")
|
||||
},
|
||||
{
|
||||
src: [ "boot.js" ],
|
||||
src: [ "boot0.js", "boot1.js" ],
|
||||
dest: standaloneLibDir,
|
||||
expand: true,
|
||||
cwd: libJasmineCore("boot")
|
||||
|
||||
@@ -41,6 +41,14 @@ module.exports = {
|
||||
src: ['lib/jasmine-core/boot/boot.js'],
|
||||
dest: 'lib/jasmine-core/boot.js'
|
||||
},
|
||||
boot0: {
|
||||
src: ['lib/jasmine-core/boot/boot0.js'],
|
||||
dest: 'lib/jasmine-core/boot0.js'
|
||||
},
|
||||
boot1: {
|
||||
src: ['lib/jasmine-core/boot/boot1.js'],
|
||||
dest: 'lib/jasmine-core/boot1.js'
|
||||
},
|
||||
nodeBoot: {
|
||||
src: ['lib/jasmine-core/boot/node_boot.js'],
|
||||
dest: 'lib/jasmine-core/node_boot.js'
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
const sass = require('node-sass');
|
||||
const sass = require('sass');
|
||||
|
||||
module.exports = {
|
||||
options: {
|
||||
implementation: sass,
|
||||
outputStyle: 'compact',
|
||||
sourceComments: false
|
||||
},
|
||||
dist: {
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/jasmine.js"></script>
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/jasmine-html.js"></script>
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/boot.js"></script>
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/boot0.js"></script>
|
||||
<!-- optional: include a file here that configures the Jasmine env -->
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/boot1.js"></script>
|
||||
|
||||
<!-- include source files here... -->
|
||||
<script src="src/Player.js"></script>
|
||||
|
||||
@@ -8,7 +8,18 @@ Gem::Specification.new do |s|
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["Gregg Van Hove"]
|
||||
s.summary = %q{JavaScript BDD framework}
|
||||
s.description = %q{Test your JavaScript without any framework dependencies, in any environment, and with a nice descriptive syntax.}
|
||||
s.description = <<~DESC
|
||||
Test your JavaScript without any framework dependencies, in any environment,
|
||||
and with a nice descriptive syntax.
|
||||
|
||||
Jasmine for Ruby is deprecated. The direct replacment for the jasmine-core
|
||||
gem is the jasmine-core NPM package. If you are also using the jasmine gem,
|
||||
we recommend using the jasmine-browser-runner NPM package instead. It
|
||||
supports all the same scenarios as the jasmine gem gem plus Webpacker. See
|
||||
https://jasmine.github.io/setup/browser.html for setup instructions, and
|
||||
https://github.com/jasmine/jasmine-gem/blob/main/release_notes/3.9.0.md
|
||||
for other options.
|
||||
DESC
|
||||
s.email = %q{jasmine-js@googlegroups.com}
|
||||
s.homepage = "http://jasmine.github.io"
|
||||
s.license = "MIT"
|
||||
|
||||
@@ -5,11 +5,12 @@ var path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
var rootPath = path.join(__dirname, "jasmine-core"),
|
||||
bootFiles = ['boot.js'],
|
||||
bootFiles = ['boot0.js', 'boot1.js'],
|
||||
legacyBootFiles = ['boot.js'],
|
||||
nodeBootFiles = ['node_boot.js'],
|
||||
cssFiles = [],
|
||||
jsFiles = [],
|
||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, nodeBootFiles);
|
||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles, nodeBootFiles);
|
||||
|
||||
fs.readdirSync(rootPath).forEach(function(file) {
|
||||
if(fs.statSync(path.join(rootPath, file)).isFile()) {
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
if ENV["SUPPRESS_JASMINE_DEPRECATION"].nil?
|
||||
puts <<~END_DEPRECATION_MSG
|
||||
The Jasmine Ruby gems are deprecated. There will be no further releases after
|
||||
the end of the Jasmine 3.x series. We recommend that most users migrate to the
|
||||
jasmine-browser-runner npm package, which is the direct replacement for the
|
||||
jasmine gem. See <https://jasmine.github.io/setup/browser.html> for setup
|
||||
instructions, including for Rails applications that use either Sprockets or
|
||||
Webpacker.
|
||||
|
||||
If jasmine-browser-runner doesn't meet your needs, one of these might:
|
||||
|
||||
* The jasmine npm package to run specs in Node.js:
|
||||
<https://github.com/jasmine/jasmine-npm>
|
||||
* The standalone distribution to run specs in browsers with no additional
|
||||
tools: <https://github.com/jasmine/jasmine#installation>
|
||||
* The jasmine-core npm package if all you need is the Jasmine assets:
|
||||
<https://github.com/jasmine/jasmine>. This is the direct equivalent of the
|
||||
jasmine-core Ruby gem.
|
||||
|
||||
To prevent this message from appearing, set the SUPPRESS_JASMINE_DEPRECATION
|
||||
environment variable.
|
||||
|
||||
END_DEPRECATION_MSG
|
||||
end
|
||||
|
||||
module Jasmine
|
||||
module Core
|
||||
class << self
|
||||
@@ -6,7 +31,7 @@ module Jasmine
|
||||
end
|
||||
|
||||
def js_files
|
||||
(["jasmine.js"] + Dir.glob(File.join(path, "*.js"))).map { |f| File.basename(f) }.uniq - boot_files - node_boot_files
|
||||
(["jasmine.js"] + Dir.glob(File.join(path, "*.js"))).map { |f| File.basename(f) }.uniq - boot_files - ["boot0.js", "boot1.js"] - node_boot_files
|
||||
end
|
||||
|
||||
SPEC_TYPES = ["core", "html", "node"]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-2021 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
@@ -21,6 +21,10 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
|
||||
NOTE: This file is deprecated and will be removed in a future release.
|
||||
Include both boot0.js and boot1.js (in that order) instead.
|
||||
|
||||
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
|
||||
@@ -31,13 +35,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* 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.
|
||||
@@ -59,7 +66,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`.
|
||||
*/
|
||||
extend(window, jasmineInterface);
|
||||
extend(global, jasmineInterface);
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
/**
|
||||
|
||||
NOTE: This file is deprecated and will be removed in a future release.
|
||||
Include both boot0.js and boot1.js (in that order) instead.
|
||||
|
||||
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
|
||||
@@ -9,13 +13,16 @@
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* 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.
|
||||
@@ -37,7 +44,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`.
|
||||
*/
|
||||
extend(window, jasmineInterface);
|
||||
extend(global, jasmineInterface);
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
|
||||
42
lib/jasmine-core/boot/boot0.js
Normal file
42
lib/jasmine-core/boot/boot0.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
This file starts the process of "booting" Jasmine. It initializes Jasmine,
|
||||
makes its globals available, and creates the env. This file should be loaded
|
||||
after `jasmine.js` and `jasmine_html.js`, but before `boot1.js` or any project
|
||||
source files or spec files are loaded.
|
||||
*/
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
jasmineRequire.html(jasmine);
|
||||
|
||||
/**
|
||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||
*/
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## The Global Interface
|
||||
*
|
||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||
*/
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
*/
|
||||
for (var property in jasmineInterface) {
|
||||
global[property] = jasmineInterface[property];
|
||||
}
|
||||
}());
|
||||
111
lib/jasmine-core/boot/boot1.js
Normal file
111
lib/jasmine-core/boot/boot1.js
Normal file
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
This file finishes "booting" Jasmine, performing all of the necessary
|
||||
initialization before executing the loaded environment and all of a project's
|
||||
specs. This file should be loaded after `boot0.js` but before any project
|
||||
source files or spec files are loaded. Thus this file can also be used to
|
||||
customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can
|
||||
be customized directly. If you only wish to configure the Jasmine env, you
|
||||
can load another file that calls `jasmine.getEnv().configure({...})`
|
||||
after `boot0.js` is loaded and before this file is loaded.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
*
|
||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() { return window.location; }
|
||||
});
|
||||
|
||||
var filterSpecs = !!queryString.getParam("spec");
|
||||
|
||||
var config = {
|
||||
failFast: queryString.getParam("failFast"),
|
||||
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
|
||||
hideDisabled: queryString.getParam("hideDisabled")
|
||||
};
|
||||
|
||||
var random = queryString.getParam("random");
|
||||
|
||||
if (random !== undefined && random !== "") {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam("seed");
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
|
||||
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
|
||||
getContainer: function() { return document.body; },
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||
timer: new jasmine.Timer(),
|
||||
filterSpecs: filterSpecs
|
||||
});
|
||||
|
||||
/**
|
||||
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
|
||||
*/
|
||||
env.addReporter(jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() { return queryString.getParam("spec"); }
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
env.configure(config);
|
||||
|
||||
/**
|
||||
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
|
||||
*/
|
||||
window.setTimeout = window.setTimeout;
|
||||
window.setInterval = window.setInterval;
|
||||
window.clearTimeout = window.clearTimeout;
|
||||
window.clearInterval = window.clearInterval;
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
*
|
||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function for readability above.
|
||||
*/
|
||||
function extend(destination, source) {
|
||||
for (var property in source) destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
}());
|
||||
64
lib/jasmine-core/boot0.js
Normal file
64
lib/jasmine-core/boot0.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright (c) 2008-2021 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
This file starts the process of "booting" Jasmine. It initializes Jasmine,
|
||||
makes its globals available, and creates the env. This file should be loaded
|
||||
after `jasmine.js` and `jasmine_html.js`, but before `boot1.js` or any project
|
||||
source files or spec files are loaded.
|
||||
*/
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
jasmineRequire.html(jasmine);
|
||||
|
||||
/**
|
||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||
*/
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## The Global Interface
|
||||
*
|
||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||
*/
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
*/
|
||||
for (var property in jasmineInterface) {
|
||||
global[property] = jasmineInterface[property];
|
||||
}
|
||||
}());
|
||||
133
lib/jasmine-core/boot1.js
Normal file
133
lib/jasmine-core/boot1.js
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
Copyright (c) 2008-2021 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
This file finishes "booting" Jasmine, performing all of the necessary
|
||||
initialization before executing the loaded environment and all of a project's
|
||||
specs. This file should be loaded after `boot0.js` but before any project
|
||||
source files or spec files are loaded. Thus this file can also be used to
|
||||
customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can
|
||||
be customized directly. If you only wish to configure the Jasmine env, you
|
||||
can load another file that calls `jasmine.getEnv().configure({...})`
|
||||
after `boot0.js` is loaded and before this file is loaded.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
*
|
||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() { return window.location; }
|
||||
});
|
||||
|
||||
var filterSpecs = !!queryString.getParam("spec");
|
||||
|
||||
var config = {
|
||||
failFast: queryString.getParam("failFast"),
|
||||
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
|
||||
hideDisabled: queryString.getParam("hideDisabled")
|
||||
};
|
||||
|
||||
var random = queryString.getParam("random");
|
||||
|
||||
if (random !== undefined && random !== "") {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam("seed");
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
|
||||
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
|
||||
getContainer: function() { return document.body; },
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||
timer: new jasmine.Timer(),
|
||||
filterSpecs: filterSpecs
|
||||
});
|
||||
|
||||
/**
|
||||
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
|
||||
*/
|
||||
env.addReporter(jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() { return queryString.getParam("spec"); }
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
env.configure(config);
|
||||
|
||||
/**
|
||||
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
|
||||
*/
|
||||
window.setTimeout = window.setTimeout;
|
||||
window.setInterval = window.setInterval;
|
||||
window.clearTimeout = window.clearTimeout;
|
||||
window.clearInterval = window.clearInterval;
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
*
|
||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function for readability above.
|
||||
*/
|
||||
function extend(destination, source) {
|
||||
for (var property in source) destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
}());
|
||||
@@ -1,4 +1,33 @@
|
||||
import pkg_resources
|
||||
import os
|
||||
|
||||
if 'SUPPRESS_JASMINE_DEPRECATION' not in os.environ:
|
||||
print('DEPRECATION WARNING:\n' +
|
||||
'\n' +
|
||||
'The Jasmine packages for Python are deprecated. There will be no further\n' +
|
||||
'releases after the end of the Jasmine 3.x series. We recommend migrating to the\n' +
|
||||
'following options:\n' +
|
||||
'\n' +
|
||||
'* jasmine-browser-runner (<https://github.com/jasmine/jasmine-browser>,\n' +
|
||||
' `npm install jasmine-browser-runner`) to run specs in browsers, including\n' +
|
||||
' headless Chrome and Saucelabs. This is the most direct replacement for the\n' +
|
||||
' jasmine server` and `jasmine ci` commands provided by the `jasmine` Python\n' +
|
||||
' package.\n' +
|
||||
'* The jasmine npm package (<https://github.com/jasmine/jasmine-npm>,\n' +
|
||||
' `npm install jasmine`) to run specs under Node.js.\n' +
|
||||
'* The standalone distribution from the latest Jasmine release\n' +
|
||||
' <https://github.com/jasmine/jasmine/releases> to run specs in browsers with\n' +
|
||||
' no additional tools.\n' +
|
||||
'* The jasmine-core npm package (`npm install jasmine-core`) if all you need is\n' +
|
||||
' the Jasmine assets. This is the direct equivalent of the jasmine-core Python\n' +
|
||||
' package.\n' +
|
||||
'\n' +
|
||||
'Except for the standalone distribution, all of the above are distributed through\n' +
|
||||
'npm.\n' +
|
||||
'\n' +
|
||||
'To prevent this message from appearing, set the SUPPRESS_JASMINE_DEPRECATION\n' +
|
||||
'environment variable.\n')
|
||||
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
@@ -29,6 +58,11 @@ class Core(object):
|
||||
js_files.remove('boot.js')
|
||||
js_files.append('boot.js')
|
||||
|
||||
# Remove the new boot files. jasmine-py will continue to use the legacy
|
||||
# boot.js.
|
||||
js_files.remove('boot0.js')
|
||||
js_files.remove('boot1.js')
|
||||
|
||||
return cls._uniq(js_files)
|
||||
|
||||
@classmethod
|
||||
@@ -57,4 +91,4 @@ class Core(object):
|
||||
|
||||
seen[marker] = 1
|
||||
result.append(item)
|
||||
return result
|
||||
return result
|
||||
|
||||
@@ -19,4 +19,4 @@ Player.prototype.resume = function() {
|
||||
|
||||
Player.prototype.makeFavorite = function() {
|
||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,4 +4,4 @@ function Song() {
|
||||
Song.prototype.persistFavoriteStatus = function(value) {
|
||||
// something complicated
|
||||
throw new Error("not yet implemented");
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-2021 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
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
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
jasmineRequire.html = function(j$) {
|
||||
j$.ResultsNode = jasmineRequire.ResultsNode();
|
||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||
@@ -130,7 +132,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
if (result.status === 'failed') {
|
||||
failures.push(failureDom(result));
|
||||
}
|
||||
addDeprecationWarnings(result);
|
||||
addDeprecationWarnings(result, 'suite');
|
||||
};
|
||||
|
||||
this.specStarted = function(result) {
|
||||
@@ -166,7 +168,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
failures.push(failureDom(result));
|
||||
}
|
||||
|
||||
addDeprecationWarnings(result);
|
||||
addDeprecationWarnings(result, 'spec');
|
||||
};
|
||||
|
||||
this.displaySpecInCorrectFormat = function(result) {
|
||||
@@ -206,7 +208,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
' of ' +
|
||||
totalSpecsDefined +
|
||||
' specs - run all';
|
||||
var skippedLink = addToExistingQueryString('spec', '');
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
var skippedLink =
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('spec', '');
|
||||
alert.appendChild(
|
||||
createDom(
|
||||
'span',
|
||||
@@ -305,14 +310,27 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
addDeprecationWarnings(doneResult);
|
||||
|
||||
var warningBarClassName = 'jasmine-bar jasmine-warning';
|
||||
for (i = 0; i < deprecationWarnings.length; i++) {
|
||||
var warning = deprecationWarnings[i];
|
||||
var context;
|
||||
|
||||
switch (deprecationWarnings[i].runnableType) {
|
||||
case 'spec':
|
||||
context = '(in spec: ' + deprecationWarnings[i].runnableName + ')';
|
||||
break;
|
||||
case 'suite':
|
||||
context = '(in suite: ' + deprecationWarnings[i].runnableName + ')';
|
||||
break;
|
||||
default:
|
||||
context = '';
|
||||
}
|
||||
|
||||
alert.appendChild(
|
||||
createDom(
|
||||
'span',
|
||||
{ className: warningBarClassName },
|
||||
'DEPRECATION: ' + warning
|
||||
{ className: 'jasmine-bar jasmine-warning' },
|
||||
'DEPRECATION: ' + deprecationWarnings[i].message,
|
||||
createDom('br'),
|
||||
context
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -350,9 +368,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
find('.jasmine-failures-menu').onclick = function() {
|
||||
setMenuModeTo('jasmine-failure-list');
|
||||
return false;
|
||||
};
|
||||
find('.jasmine-spec-list-menu').onclick = function() {
|
||||
setMenuModeTo('jasmine-spec-list');
|
||||
return false;
|
||||
};
|
||||
|
||||
setMenuModeTo('jasmine-failure-list');
|
||||
@@ -538,17 +558,20 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
);
|
||||
|
||||
var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast');
|
||||
failFastCheckbox.checked = config.failFast;
|
||||
failFastCheckbox.checked = config.stopOnSpecFailure;
|
||||
failFastCheckbox.onclick = function() {
|
||||
navigateWithNewParam('failFast', !config.failFast);
|
||||
navigateWithNewParam('failFast', !config.stopOnSpecFailure);
|
||||
};
|
||||
|
||||
var throwCheckbox = optionsMenuDom.querySelector(
|
||||
'#jasmine-throw-failures'
|
||||
);
|
||||
throwCheckbox.checked = config.oneFailurePerSpec;
|
||||
throwCheckbox.checked = config.stopSpecOnExpectationFailure;
|
||||
throwCheckbox.onclick = function() {
|
||||
navigateWithNewParam('throwFailures', !config.oneFailurePerSpec);
|
||||
navigateWithNewParam(
|
||||
'oneFailurePerSpec',
|
||||
!config.stopSpecOnExpectationFailure
|
||||
);
|
||||
};
|
||||
|
||||
var randomCheckbox = optionsMenuDom.querySelector(
|
||||
@@ -618,15 +641,23 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
suite = suite.parent;
|
||||
}
|
||||
|
||||
return addToExistingQueryString('spec', els.join(' '));
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
return (
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('spec', els.join(' '))
|
||||
);
|
||||
}
|
||||
|
||||
function addDeprecationWarnings(result) {
|
||||
function addDeprecationWarnings(result, runnableType) {
|
||||
if (result && result.deprecationWarnings) {
|
||||
for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
||||
var warning = result.deprecationWarnings[i].message;
|
||||
if (!j$.util.arrayContains(warning)) {
|
||||
deprecationWarnings.push(warning);
|
||||
deprecationWarnings.push({
|
||||
message: warning,
|
||||
runnableName: result.fullName,
|
||||
runnableType: runnableType
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -678,11 +709,19 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function specHref(result) {
|
||||
return addToExistingQueryString('spec', result.fullName);
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
return (
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('spec', result.fullName)
|
||||
);
|
||||
}
|
||||
|
||||
function seedHref(seed) {
|
||||
return addToExistingQueryString('seed', seed);
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
return (
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('seed', seed)
|
||||
);
|
||||
}
|
||||
|
||||
function defaultQueryString(key, value) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2019 Pivotal Labs
|
||||
Copyright (c) 2008-2021 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
#
|
||||
module Jasmine
|
||||
module Core
|
||||
VERSION = "3.5.0"
|
||||
VERSION = "3.10.1"
|
||||
end
|
||||
end
|
||||
|
||||
46
package.json
46
package.json
@@ -1,35 +1,42 @@
|
||||
{
|
||||
"name": "jasmine-core",
|
||||
"license": "MIT",
|
||||
"version": "3.5.0",
|
||||
"version": "3.10.1",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jasmine/jasmine.git"
|
||||
},
|
||||
"keywords": [
|
||||
"test",
|
||||
"testing",
|
||||
"jasmine",
|
||||
"tdd",
|
||||
"bdd"
|
||||
],
|
||||
"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",
|
||||
"cleanup": "prettier --write src/**/*.js spec/**/*.js",
|
||||
"cleanup": "prettier --write \"src/**/*.js\" \"spec/**/*.js\"",
|
||||
"build": "grunt buildDistribution",
|
||||
"serve": "node spec/support/localJasmineBrowser.js",
|
||||
"serve:performance": "node spec/support/localJasmineBrowser.js jasmine-browser-performance.json",
|
||||
"ci": "node spec/support/ci.js",
|
||||
"ci:performance": "node spec/support/ci.js jasmine-browser-performance.json"
|
||||
},
|
||||
"description": "Official packaging of Jasmine's core files for use by Node.js projects.",
|
||||
"description": "Simple JavaScript testing framework for browsers and node.js",
|
||||
"homepage": "https://jasmine.github.io",
|
||||
"main": "./lib/jasmine-core.js",
|
||||
"files": [
|
||||
"MIT.LICENSE",
|
||||
"README.md",
|
||||
"images/*.{png,svg}",
|
||||
"lib/**/*.{js,css}",
|
||||
"package.json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"acorn": "^6.0.0",
|
||||
"ejs": "^2.5.5",
|
||||
"eslint": "^5.16.0",
|
||||
"express": "^4.16.4",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-compat": "^3.8.0",
|
||||
"fast-glob": "^2.2.6",
|
||||
"grunt": "^1.0.4",
|
||||
"grunt-cli": "^1.3.2",
|
||||
@@ -38,12 +45,11 @@
|
||||
"grunt-css-url-embed": "^1.11.1",
|
||||
"grunt-sass": "^3.0.2",
|
||||
"jasmine": "^3.4.0",
|
||||
"jasmine-browser-runner": "0.3.0",
|
||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser#main",
|
||||
"jsdom": "^15.0.0",
|
||||
"load-grunt-tasks": "^4.0.0",
|
||||
"node-sass": "^4.11.0",
|
||||
"prettier": "1.17.1",
|
||||
"selenium-webdriver": "^3.6.0",
|
||||
"sass": "^1.32.12",
|
||||
"shelljs": "^0.8.3",
|
||||
"temp": "^0.9.0"
|
||||
},
|
||||
@@ -51,6 +57,12 @@
|
||||
"singleQuote": true
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"plugin:compat/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 5
|
||||
},
|
||||
"rules": {
|
||||
"quotes": [
|
||||
"error",
|
||||
@@ -66,10 +78,6 @@
|
||||
}
|
||||
],
|
||||
"block-spacing": "error",
|
||||
"comma-dangle": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"func-call-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
@@ -84,5 +92,13 @@
|
||||
],
|
||||
"space-before-blocks": "error"
|
||||
}
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
"Safari >= 8",
|
||||
"last 2 Chrome versions",
|
||||
"last 2 Firefox versions",
|
||||
"Firefox 68",
|
||||
"last 2 Edge versions",
|
||||
"IE >= 10"
|
||||
]
|
||||
}
|
||||
|
||||
57
release_notes/3.10.0.md
Normal file
57
release_notes/3.10.0.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Jasmine Core 3.10 Release Notes
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Added support for running Jasmine multiple times
|
||||
* If the env is configured with `autoCleanClosures: false`, then it can be
|
||||
executed repeatedly.
|
||||
* Merges #1934 from @nicojs
|
||||
* Fixes #1925
|
||||
|
||||
* Improved error message when an async expectation occurs after the spec
|
||||
finishes
|
||||
* Merges #1937 from @AndreWillomitzer
|
||||
* Fixes #1854
|
||||
|
||||
* Reject timeout values that are too large for setTimeout
|
||||
* See #1930
|
||||
|
||||
* Don't immediately move to the next queueable fn on async error
|
||||
|
||||
This allows assertion failures and other errors that occur after the async
|
||||
error to be routed to the correct spec/suite.
|
||||
|
||||
* Added a stringContaining asymmetric equality tester
|
||||
* Fixes #1923.
|
||||
|
||||
* The jasmine-core Ruby gem now prints a deprecation message when loaded unless
|
||||
the SUPPRESS_JASMINE_DEPRECATION environment variable is set.
|
||||
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Added discussion of max timeout value to jsdocs
|
||||
* Merges #1931 from @trusktr
|
||||
|
||||
* Added missing @since annotations
|
||||
|
||||
* Improved jsdocs for asymmetric equality testers
|
||||
|
||||
* Added a deprecation notice to the jasmine-core Ruby gem's description
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 3.10.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 10, 12, 14, 16 |
|
||||
| Safari | 8-14 |
|
||||
| Chrome | 94 |
|
||||
| Firefox | 93, 78, 68 |
|
||||
| Edge | 94 |
|
||||
| Internet Explorer | 10, 11 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
12
release_notes/3.10.1.md
Normal file
12
release_notes/3.10.1.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Jasmine Core 3.10.1 Release Notes
|
||||
|
||||
## Bugfixes
|
||||
|
||||
* Fixed missing pendingReason in pending spec results
|
||||
* Fixes [#1939](https://github.com/jasmine/jasmine/issues/1939)
|
||||
* Merges [#1940](https://github.com/jasmine/jasmine/pull/1940) from @jan-molak
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
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)_
|
||||
80
release_notes/3.7.0.md
Normal file
80
release_notes/3.7.0.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# Jasmine Core 3.7 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a maintenance release of Jasmine with a number of new features and fixes.
|
||||
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Allow custom object formatters to be added in beforeAll
|
||||
- Fixes [#1876](http://github.com/jasmine/jasmine/issues/1876)
|
||||
|
||||
* Allow specs to disable Jasmine's global error handling by overwriting `onerror`.
|
||||
- Merges [#1860](https://github.com/jasmine/jasmine/pull/1860) from @greghuc
|
||||
|
||||
* Fixed comparison between URL objects
|
||||
- Fixes [#1866](http://github.com/jasmine/jasmine/issues/1866)
|
||||
|
||||
* Added support for stack traces created by `node --enable-source-maps`
|
||||
with tools like the Typescript compiler.
|
||||
- Merges [#1862](https://github.com/jasmine/jasmine/pull/1862) from @JannesMeyer
|
||||
|
||||
* Made properties added by createSpyObj() enumerable.
|
||||
- Merges [#1859](https://github.com/jasmine/jasmine/pull/1859) from DCtheTall
|
||||
- Fixes [#1837](http://github.com/jasmine/jasmine/issues/1837)
|
||||
|
||||
* Show the name of the spec/suite that caused a deprecation
|
||||
|
||||
* Warn if a spec or before/after function both takes a callback and returns a promise
|
||||
|
||||
* Don't overwrite MatchersUtil methods with ones that were added to
|
||||
`Array.prototype`, esp. `contains`
|
||||
- Fixes [#1849](http://github.com/jasmine/jasmine/issues/1849)
|
||||
|
||||
* Allow generator functions to be passed to `.and.callFake`
|
||||
- Fixes [#1848](http://github.com/jasmine/jasmine/issues/1848)
|
||||
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Fixed instructions for contributors to run Jasmine's ci script
|
||||
|
||||
* Updated supported Node versions in README
|
||||
|
||||
* Fixed script and CSS URLs in standalone example in README
|
||||
- Merges [#1839](https://github.com/jasmine/jasmine/pull/1839) from @snowman
|
||||
|
||||
* Fixed typo in asyncMatcher toBePending comment
|
||||
- Merges [#1847](https://github.com/jasmine/jasmine/pull/1847) from @SnailCoil
|
||||
|
||||
* Fixed link to custom object formatter tutorial
|
||||
|
||||
* Added jasmine.isSpy to the public interface
|
||||
- Fixes [#1880](http://github.com/jasmine/jasmine/issues/1880)
|
||||
|
||||
|
||||
|
||||
## Internal notes
|
||||
|
||||
* Fixed intermittent test failures
|
||||
|
||||
* Added additional assertions to tests for toBeTruthy and toBeFalsy
|
||||
- Merges [#1875](https://github.com/jasmine/jasmine/pull/1875) from @yasinkocak
|
||||
|
||||
* Pointed Travis badge at travis-ci.com, not .org
|
||||
|
||||
* Fixed file globs so that Prettier runs on all files
|
||||
|
||||
* Check for forgotten console and debugger statements
|
||||
|
||||
* Fixed code in Jasmine that will trigger deprecations in 3.99
|
||||
|
||||
* Use jasmine-browser from npm rather than from the main branch
|
||||
- The current released version now works with IE, so we no longer need to
|
||||
depend on main.
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
8
release_notes/3.7.1.md
Normal file
8
release_notes/3.7.1.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Jasmine Core 3.7.1 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a bug fix release of Jasmine. It's identical to 3.7.0 except that it
|
||||
correctly reports its version number. Please see the
|
||||
[3.7.0 release notes](https://github.com/jasmine/jasmine/blob/main/release_notes/3.7.0.md)
|
||||
if you're upgrading directly from 3.6.0 or earlier.
|
||||
132
release_notes/3.8.0.md
Normal file
132
release_notes/3.8.0.md
Normal file
@@ -0,0 +1,132 @@
|
||||
# Jasmine Core 3.8 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a maintenance release of Jasmine with a number of new features and fixes.
|
||||
|
||||
## Python deprecation
|
||||
|
||||
The Jasmine packages for Python are deprecated. We intend to continue releasing
|
||||
them through the end of the 3.x series, but after that they will be
|
||||
discontinued. We recommend migrating to the following alternatives:
|
||||
|
||||
* The [jasmine-browser-runner](https://github.com/jasmine/jasmine-browser)
|
||||
npm package to run specs in browsers, including headless Chrome and
|
||||
Saucelabs. This is the most direct replacement for the `jasmine server`
|
||||
and `jasmine ci` commands provided by the `jasmine` Python package.
|
||||
* The [jasmine](https://github.com/jasmine/jasmine-npm) npm package (
|
||||
`npm install jasmine`) to run specs under Node.js.
|
||||
* The standalone distribution from the
|
||||
[latest Jasmine release](https://github.com/jasmine/jasmine/releases) to
|
||||
run specs in browsers with no additional tools.
|
||||
* The [jasmine-core](https://github.com/jasmine/jasmine) npm package if all
|
||||
you need is the Jasmine assets. This is the direct equivalent of the
|
||||
jasmine-core Python package.
|
||||
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Fixed spec filtering in Karma
|
||||
* Merges [#1920](https://github.com/jasmine/jasmine/pull/1920) from @jlpstolwijk
|
||||
* Fixes [#1906](https://github.com/jasmine/jasmine/issues/1906)
|
||||
|
||||
* Added expectAsync(...).already
|
||||
* Causes async matchers to immediately fail if the promise is pending
|
||||
* See https://jasmine.github.io/api/3.8/async-matchers.html#already
|
||||
* Fixes [#1845](https://github.com/jasmine/jasmine/issues/1845)
|
||||
|
||||
* Include rejection details in failure messages for toBeResolved and toBeResolvedWith
|
||||
|
||||
* Fixed "stop spec on expectation failure" checkbox in standalone
|
||||
|
||||
* Added option for spyOnAllFunctions to include non-enumerable props
|
||||
* Makes spyOnAllFunctions work on instance methods of ES6 classes
|
||||
* Merges [#1909](https://github.com/jasmine/jasmine/pull/1909) from @Dari-k
|
||||
* Fixes [#1897](https://github.com/jasmine/jasmine/issues/1897)
|
||||
|
||||
* Added Spy#calls#thisFor
|
||||
* Provides the `this` value for a given spy call
|
||||
* Merges [#1903](https://github.com/jasmine/jasmine/pull/1903) from @ajvincent
|
||||
|
||||
* Improved handling of unhandled promise rejections with no error in Node
|
||||
* Fixes [#1759](https://github.com/jasmine/jasmine/issues/1759)
|
||||
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Updated package description
|
||||
|
||||
* Updated contributing guide
|
||||
|
||||
* Added TypeScript typings and jasmine-browser-runner to issue template
|
||||
|
||||
* Removed constructors from jsdocs of classes that aren't user-constructable
|
||||
|
||||
* Fixed config.seed type in jsdocs
|
||||
* Merges [#1892](https://github.com/jasmine/jasmine/pull/1892) from @UziTech
|
||||
|
||||
* Added jsdocs for the following:
|
||||
* asymmetric equality testers
|
||||
* Env#execute
|
||||
* Env#allowRespy
|
||||
* The public portion of Spec
|
||||
* Spy.callData.returnValue
|
||||
* Env#topSuite and Suite
|
||||
|
||||
* Added a jsdoc cross-reference from Configuration to its usage
|
||||
|
||||
* Added a note about correct usage of async matchers
|
||||
|
||||
* Added support for ArrayBuffers to matchersUtil.equals
|
||||
* Merges [#1891](https://github.com/jasmine/jasmine/pull/1892) from @Finesse
|
||||
* Merges [#1689](https://github.com/jasmine/jasmine/pull/1892) from @dankurka
|
||||
* Fixes [#1687](https://github.com/jasmine/jasmine/issues/1687)
|
||||
|
||||
|
||||
## Internal notes
|
||||
|
||||
* Fixed typo in spec name
|
||||
* Merges [#1918](https://github.com/jasmine/jasmine/pull/1918) from @eltociear
|
||||
|
||||
* Specify files to include in the NPM package rather than files to exclude
|
||||
|
||||
* Added test coverage for MatchersUtil#equals with typed arrays
|
||||
|
||||
* Removed checks for typed array support in the test suite
|
||||
* All supported browsers have all typed arrays except for Uint8ClampedArray,
|
||||
BigInt64Array, and BigUint64Array.
|
||||
|
||||
* Fixed test failures on IE 10
|
||||
|
||||
* Test matrix updates
|
||||
* Added Node 16
|
||||
* Added Safari 14
|
||||
* Added Firefox 78 (closest match to current ESR)
|
||||
* Removed Safari 10-12 to speed up CI. The newer and older versions we test
|
||||
provide a good measure of safety.
|
||||
|
||||
* Replaced node-sass dev dependency that isn't compatible with Node 16
|
||||
|
||||
* Removed unused dev dependencies
|
||||
|
||||
* Migrated CI from Travis to Circle
|
||||
|
||||
* Compensate for clock jitter in specs
|
||||
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 3.8.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 10, 12, 14, 16 |
|
||||
| Safari | 8-14 |
|
||||
| Chrome | 91 |
|
||||
| Firefox | 89, 68, 78 |
|
||||
| Edge | 91 |
|
||||
| Internet Explorer | 10, 11 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
65
release_notes/3.9.0.md
Normal file
65
release_notes/3.9.0.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Jasmine Core 3.9 Release Notes
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Fixed Trusted Types error in `j$.isError_` in Chromium-based browsers
|
||||
* Merges [#1921](https://github.com/jasmine/jasmine/pull/1921) from @bjarkler
|
||||
* Fixes [#1910](https://github.com/jasmine/jasmine/issues/1910)
|
||||
* Fixes [#1653](https://github.com/jasmine/jasmine/issues/1653)
|
||||
|
||||
* Better reporting of unhandled promise rejections with truthy but non-`Error`
|
||||
reasons on Node
|
||||
* `Env#execute` returns a promise in environments that support promises
|
||||
* Renamed `failFast` and `oneFailurePerSpec` config props to `stopOnSpecFailure`
|
||||
and `stopSpecOnExpectationFailure`
|
||||
|
||||
The new names are more self-explanatory and consistent with jasmine-npm. The
|
||||
old names are deprecated but will still work until the next major release.
|
||||
|
||||
* Split `boot.js` into two files to allow the env to be configured in between
|
||||
|
||||
This is mainly intended to support jasmine-browser-runner, which will load
|
||||
a script that configures the env in between the two boot files (`boot0.js` and
|
||||
`boot1.js`). The single-file `boot.js` will still be included until the next
|
||||
major release.
|
||||
|
||||
## Ruby deprecation
|
||||
|
||||
The Jasmine Ruby gems are deprecated. There will be no further releases after
|
||||
the end of the Jasmine 3.x series. We recommend that most users migrate to the
|
||||
[jasmine-browser-runner](https://github.com/jasmine/jasmine-browser)
|
||||
npm package, which is the direct replacement for the `jasmine` gem.
|
||||
|
||||
If `jasmine-browser-runner` doesn't meet your needs, one of these might:
|
||||
|
||||
* The [jasmine](https://github.com/jasmine/jasmine-npm) npm package to run
|
||||
specs in Node.js.
|
||||
* The [standalone distribution](https://github.com/jasmine/jasmine#installation)
|
||||
to run specs in browsers with no additional tools.
|
||||
* The [jasmine-core](https://github.com/jasmine/jasmine) npm package if all
|
||||
you need is the Jasmine assets. This is the direct equivalent of the
|
||||
`jasmine-core` Ruby gem.
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Added API docs for `Suite#id` and `Spec#id`
|
||||
* Marked `Env#hideDisabled` deprecated in jsdocs
|
||||
|
||||
|
||||
------
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 3.9.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 10, 12, 14, 16 |
|
||||
| Safari | 8-14 |
|
||||
| Chrome | 92 |
|
||||
| Firefox | 91, 78, 68 |
|
||||
| Edge | 92 |
|
||||
| Internet Explorer | 10, 11 |
|
||||
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
43
scripts/run-all-browsers
Executable file
43
scripts/run-all-browsers
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/sh
|
||||
|
||||
run_browser() {
|
||||
browser=$1
|
||||
version=$2
|
||||
description="$browser $version"
|
||||
if [ $version = "latest" ]; then
|
||||
version=""
|
||||
fi
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "Running $description"
|
||||
echo
|
||||
USE_SAUCE=true JASMINE_BROWSER=$browser SAUCE_BROWSER_VERSION=$version npm run ci
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "PASS: $description" >> "$passfile"
|
||||
else
|
||||
echo "FAIL: $description" >> "$failfile"
|
||||
fi
|
||||
}
|
||||
|
||||
passfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||
failfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||
run_browser "internet explorer" 11
|
||||
run_browser "internet explorer" 10
|
||||
run_browser chrome latest
|
||||
run_browser firefox latest
|
||||
run_browser firefox 78
|
||||
run_browser firefox 68
|
||||
run_browser safari 14
|
||||
run_browser safari 13
|
||||
run_browser safari 9
|
||||
run_browser safari 8
|
||||
run_browser MicrosoftEdge latest
|
||||
|
||||
echo
|
||||
cat "$passfile" "$failfile"
|
||||
|
||||
if [ -s "$failfile" ]; then
|
||||
exit 1
|
||||
fi
|
||||
37
scripts/start-sauce-connect
Executable file
37
scripts/start-sauce-connect
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
if [ $# -gt 1 -o "$1" = "--help" ]; then
|
||||
echo "Usage: $0 [pidfile]" 1>&2
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
pidfile=`mktemp`
|
||||
else
|
||||
pidfile="$1"
|
||||
fi
|
||||
|
||||
outfile=`mktemp`
|
||||
echo "Starting Sauce Connect"
|
||||
if [ -z "$SAUCE_TUNNEL_IDENTIFIER" ]; then
|
||||
sc -u "$SAUCE_USERNAME" -k "$SAUCE_ACCESS_KEY" -X 4445 --pidfile "$pidfile" 2>&1 | tee "$outfile" &
|
||||
else
|
||||
sc -u "$SAUCE_USERNAME" -k "$SAUCE_ACCESS_KEY" -X 4445 --pidfile "$pidfile" -i "$SAUCE_TUNNEL_IDENTIFIER" 2>&1 | tee "$outfile" &
|
||||
fi
|
||||
|
||||
while ! fgrep "Sauce Connect is up, you may start your tests." "$outfile" > /dev/null; do
|
||||
sleep 1
|
||||
|
||||
if ! ps -p $(cat "$pidfile") > /dev/null; then
|
||||
echo "Sauce Connect exited"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if ! nc -z localhost 4445; then
|
||||
echo "Can't connect to Sauce tunnel"
|
||||
killall sc
|
||||
exit 1
|
||||
fi
|
||||
33
scripts/stop-sauce-connect
Executable file
33
scripts/stop-sauce-connect
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 sauce-connect-pid" 1>&2
|
||||
exit
|
||||
fi
|
||||
|
||||
pid="$1"
|
||||
echo "PID: $pid"
|
||||
|
||||
echo "Stopping Sauce Connect"
|
||||
# Sauce Connect docs say that we can just kill -9 it if we don't care about
|
||||
# failing any ongoing sessions. In practice, that sometimes works but usually
|
||||
# leaks a tunnel so badly that you can't even stop it from the web UI.
|
||||
# Instead of doing that, we give Sauce Connect some time to shut down
|
||||
# gracefully and then give up.
|
||||
kill -INT $pid
|
||||
|
||||
# Wait up to 2 minutes, then give up if it's still running
|
||||
n=0
|
||||
while [ $n -lt 120 ] && ps -p $pid > /dev/null; do
|
||||
sleep 1
|
||||
kill -INT $pid 2> /dev/null || true
|
||||
n=$(($n + 1))
|
||||
done
|
||||
|
||||
if ps -p $pid > /dev/null; then
|
||||
echo "Could not shut down Sauce Connect"
|
||||
fi
|
||||
|
||||
exit $exitcode
|
||||
32
setup.py
32
setup.py
@@ -4,15 +4,41 @@ import json
|
||||
with open('package.json') as packageFile:
|
||||
version = json.load(packageFile)['version']
|
||||
|
||||
short_description=('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.')
|
||||
deprecation=('The Jasmine packages for Python are deprecated. There will be no further\n' +
|
||||
'releases after the end of the Jasmine 3.x series. We recommend migrating to the\n' +
|
||||
'following options:\n' +
|
||||
'\n' +
|
||||
'* jasmine-browser-runner (<https://github.com/jasmine/jasmine-browser>,\n' +
|
||||
' `npm install jasmine-browser-runner`) to run specs in browsers, including\n' +
|
||||
' headless Chrome and Saucelabs. This is the most direct replacement for the\n' +
|
||||
' jasmine server` and `jasmine ci` commands provided by the `jasmine` Python\n' +
|
||||
' package.\n' +
|
||||
'* The jasmine npm package (<https://github.com/jasmine/jasmine-npm>,\n' +
|
||||
' `npm install jasmine`) to run specs under Node.js.\n' +
|
||||
'* The standalone distribution from the latest Jasmine release\n' +
|
||||
' <https://github.com/jasmine/jasmine/releases> to run specs in browsers with\n' +
|
||||
' no additional tools.\n' +
|
||||
'* The jasmine-core npm package (`npm install jasmine-core`) if all you need is\n' +
|
||||
' the Jasmine assets. This is the direct equivalent of the jasmine-core Python\n' +
|
||||
' package.\n' +
|
||||
'\n' +
|
||||
'Except for the standalone distribution, all of the above are distributed through\n'
|
||||
'npm.\n')
|
||||
long_description = short_description + '\n\n' + deprecation
|
||||
|
||||
|
||||
setup(
|
||||
name="jasmine-core",
|
||||
version=version,
|
||||
url="http://jasmine.github.io",
|
||||
author="Pivotal Labs",
|
||||
author_email="jasmine-js@googlegroups.com",
|
||||
description=('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.'),
|
||||
description=short_description,
|
||||
long_description=long_description,
|
||||
long_description_content_type='text/plain',
|
||||
license='MIT',
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
|
||||
20
spec/.eslintrc.js
Normal file
20
spec/.eslintrc.js
Normal file
@@ -0,0 +1,20 @@
|
||||
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',
|
||||
|
||||
// Since linting is done at the end of the process and doesn't stop us
|
||||
// from running tests, it makes sense to fail if debugger statements
|
||||
// or console references are present.
|
||||
'no-debugger': 'error',
|
||||
'no-console': 'error'
|
||||
}
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('AsyncExpectation', function() {
|
||||
beforeEach(function() {
|
||||
jasmineUnderTest.Expectation.addAsyncCoreMatchers(
|
||||
@@ -24,8 +25,9 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.resolve(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
util: jasmineUnderTest.matchersUtil,
|
||||
matchersUtil: new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -47,7 +49,9 @@ describe('AsyncExpectation', function() {
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.reject(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
util: jasmineUnderTest.matchersUtil,
|
||||
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
||||
pp: function() {}
|
||||
}),
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -91,16 +95,16 @@ describe('AsyncExpectation', function() {
|
||||
it('prepends the context to the generated failure message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var util = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
var matchersUtil = {
|
||||
pp: function(val) {
|
||||
return val.toString();
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: Promise.reject('rejected'),
|
||||
addExpectationResult: addExpectationResult,
|
||||
util: util
|
||||
matchersUtil: matchersUtil
|
||||
});
|
||||
|
||||
return expectation
|
||||
@@ -110,7 +114,8 @@ describe('AsyncExpectation', function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: failure message'
|
||||
message:
|
||||
'Some context: Expected a promise to be resolved but it was rejected with rejected.'
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -119,16 +124,17 @@ describe('AsyncExpectation', function() {
|
||||
it('prepends the context to a custom failure message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var util = {
|
||||
var matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
},
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: Promise.reject('b'),
|
||||
addExpectationResult: addExpectationResult,
|
||||
util: util
|
||||
matchersUtil: matchersUtil
|
||||
});
|
||||
|
||||
return expectation
|
||||
@@ -139,7 +145,8 @@ describe('AsyncExpectation', function() {
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message:
|
||||
"Some context: Expected a promise to be resolved to 'a' but it was rejected."
|
||||
"Some context: Expected a promise to be resolved to 'a' " +
|
||||
"but it was rejected with 'b'."
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -149,7 +156,7 @@ describe('AsyncExpectation', function() {
|
||||
pending('should actually work, but no custom matchers for async yet');
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var util = {
|
||||
var matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
@@ -159,7 +166,7 @@ describe('AsyncExpectation', function() {
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult,
|
||||
util: util
|
||||
matchersUtil: matchersUtil
|
||||
});
|
||||
|
||||
return expectation
|
||||
@@ -180,10 +187,11 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.resolve(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult,
|
||||
util: jasmineUnderTest.matchersUtil
|
||||
matchersUtil: new jasmineUnderTest.MatchersUtil({ pp: pp })
|
||||
});
|
||||
|
||||
return expectation
|
||||
@@ -208,7 +216,9 @@ describe('AsyncExpectation', function() {
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult,
|
||||
util: jasmineUnderTest.matchersUtil
|
||||
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
})
|
||||
});
|
||||
|
||||
return expectation
|
||||
@@ -256,7 +266,7 @@ describe('AsyncExpectation', function() {
|
||||
matchers = {
|
||||
toFoo: matcherFactory
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
customEqualityTesters = ['a'],
|
||||
@@ -264,7 +274,7 @@ describe('AsyncExpectation', function() {
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
customAsyncMatchers: matchers,
|
||||
customEqualityTesters: customEqualityTesters,
|
||||
actual: 'an actual',
|
||||
@@ -273,7 +283,7 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
return expectation.toFoo('hello').then(function() {
|
||||
expect(matcherFactory).toHaveBeenCalledWith(
|
||||
util,
|
||||
matchersUtil,
|
||||
customEqualityTesters
|
||||
);
|
||||
});
|
||||
@@ -292,14 +302,14 @@ describe('AsyncExpectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -322,7 +332,7 @@ describe('AsyncExpectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
@@ -335,7 +345,7 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -365,7 +375,7 @@ describe('AsyncExpectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return '';
|
||||
}
|
||||
@@ -380,7 +390,7 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -536,7 +546,7 @@ describe('AsyncExpectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'default message';
|
||||
}
|
||||
@@ -553,7 +563,7 @@ describe('AsyncExpectation', function() {
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
addExpectationResult: addExpectationResult
|
||||
}).not;
|
||||
|
||||
|
||||
@@ -30,6 +30,20 @@ describe('CallTracker', function() {
|
||||
expect(callTracker.argsFor(1)).toEqual([0, 'foo']);
|
||||
});
|
||||
|
||||
it("tracks the 'this' object from each execution", function() {
|
||||
var callTracker = new jasmineUnderTest.CallTracker();
|
||||
|
||||
var this0 = {},
|
||||
this1 = {};
|
||||
callTracker.track({ object: this0, args: [] });
|
||||
callTracker.track({ object: this1, args: [] });
|
||||
callTracker.track({ args: [] });
|
||||
|
||||
expect(callTracker.thisFor(0)).toBe(this0);
|
||||
expect(callTracker.thisFor(1)).toBe(this1);
|
||||
expect(callTracker.thisFor(2)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('returns any empty array when there was no call', function() {
|
||||
var callTracker = new jasmineUnderTest.CallTracker();
|
||||
|
||||
|
||||
@@ -5,6 +5,10 @@ describe('Env', function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
describe('#pending', function() {
|
||||
it('throws the Pending Spec exception', function() {
|
||||
expect(function() {
|
||||
@@ -56,6 +60,93 @@ describe('Env', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('ignores configuration properties that are present but undefined', function() {
|
||||
var initialConfig = {
|
||||
random: true,
|
||||
seed: '123',
|
||||
failFast: true,
|
||||
failSpecWithNoExpectations: true,
|
||||
oneFailurePerSpec: true,
|
||||
stopSpecOnExpectationFailure: true,
|
||||
stopOnSpecFailure: true,
|
||||
hideDisabled: true
|
||||
};
|
||||
env.configure(initialConfig);
|
||||
|
||||
env.configure({
|
||||
random: undefined,
|
||||
seed: undefined,
|
||||
failFast: undefined,
|
||||
failSpecWithNoExpectations: undefined,
|
||||
oneFailurePerSpec: undefined,
|
||||
stopSpecOnExpectationFailure: undefined,
|
||||
stopOnSpecFailure: undefined,
|
||||
hideDisabled: undefined
|
||||
});
|
||||
|
||||
expect(env.configuration()).toEqual(
|
||||
jasmine.objectContaining(initialConfig)
|
||||
);
|
||||
});
|
||||
|
||||
it('sets stopOnSpecFailure when failFast is set, and vice versa', function() {
|
||||
env.configure({ failFast: true });
|
||||
expect(env.configuration()).toEqual(
|
||||
jasmine.objectContaining({
|
||||
failFast: true,
|
||||
stopOnSpecFailure: true
|
||||
})
|
||||
);
|
||||
|
||||
env.configure({ stopOnSpecFailure: false });
|
||||
expect(env.configuration()).toEqual(
|
||||
jasmine.objectContaining({
|
||||
failFast: false,
|
||||
stopOnSpecFailure: false
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects a single call that sets stopOnSpecFailure and failFast to different values', function() {
|
||||
expect(function() {
|
||||
env.configure({ failFast: true, stopOnSpecFailure: false });
|
||||
}).toThrowError(
|
||||
'stopOnSpecFailure and failFast are aliases for each ' +
|
||||
"other. Don't set failFast if you also set stopOnSpecFailure."
|
||||
);
|
||||
});
|
||||
|
||||
it('sets stopSpecOnExpectationFailure when oneFailurePerSpec is set, and vice versa', function() {
|
||||
env.configure({ oneFailurePerSpec: true });
|
||||
expect(env.configuration()).toEqual(
|
||||
jasmine.objectContaining({
|
||||
oneFailurePerSpec: true,
|
||||
stopSpecOnExpectationFailure: true
|
||||
})
|
||||
);
|
||||
|
||||
env.configure({ stopSpecOnExpectationFailure: false });
|
||||
expect(env.configuration()).toEqual(
|
||||
jasmine.objectContaining({
|
||||
oneFailurePerSpec: false,
|
||||
stopSpecOnExpectationFailure: false
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects a single call that sets stopSpecOnExpectationFailure and oneFailurePerSpec to different values', function() {
|
||||
expect(function() {
|
||||
env.configure({
|
||||
oneFailurePerSpec: true,
|
||||
stopSpecOnExpectationFailure: false
|
||||
});
|
||||
}).toThrowError(
|
||||
'stopSpecOnExpectationFailure and oneFailurePerSpec are ' +
|
||||
"aliases for each other. Don't set oneFailurePerSpec if you also set " +
|
||||
'stopSpecOnExpectationFailure.'
|
||||
);
|
||||
});
|
||||
|
||||
describe('promise library', function() {
|
||||
it('can be configured without a custom library', function() {
|
||||
env.configure({});
|
||||
@@ -165,12 +256,30 @@ describe('Env', function() {
|
||||
env.it('async', jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.it('huge timeout', function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#xit', function() {
|
||||
it('calls spec.exclude with "Temporarily disabled with xit"', function() {
|
||||
var excludeSpy = jasmine.createSpy();
|
||||
spyOn(env, 'it').and.returnValue({
|
||||
exclude: excludeSpy
|
||||
});
|
||||
env.xit('foo', function() {});
|
||||
expect(excludeSpy).toHaveBeenCalledWith('Temporarily disabled with xit');
|
||||
});
|
||||
|
||||
it('calls spec.pend with "Temporarily disabled with xit"', function() {
|
||||
var pendSpy = jasmine.createSpy();
|
||||
var realExclude = jasmineUnderTest.Spec.prototype.exclude;
|
||||
|
||||
spyOn(env, 'it').and.returnValue({
|
||||
exclude: realExclude,
|
||||
pend: pendSpy
|
||||
});
|
||||
env.xit('foo', function() {});
|
||||
@@ -207,6 +316,12 @@ describe('Env', function() {
|
||||
/fit expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/
|
||||
);
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.fit('huge timeout', function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#beforeEach', function() {
|
||||
@@ -224,6 +339,12 @@ describe('Env', function() {
|
||||
env.beforeEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.beforeEach(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#beforeAll', function() {
|
||||
@@ -241,6 +362,12 @@ describe('Env', function() {
|
||||
env.beforeAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.beforeAll(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterEach', function() {
|
||||
@@ -258,6 +385,12 @@ describe('Env', function() {
|
||||
env.afterEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.afterEach(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterAll', function() {
|
||||
@@ -275,17 +408,25 @@ describe('Env', function() {
|
||||
env.afterAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.afterAll(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when not constructed with suppressLoadErrors: true', function() {
|
||||
it('installs a global error handler on construction', function() {
|
||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||
'install',
|
||||
'uninstall',
|
||||
'pushListener',
|
||||
'popListener'
|
||||
]);
|
||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||
new jasmineUnderTest.Env();
|
||||
env.cleanup_();
|
||||
env = new jasmineUnderTest.Env();
|
||||
expect(globalErrors.install).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -294,14 +435,116 @@ describe('Env', function() {
|
||||
it('does not install a global error handler until execute is called', function() {
|
||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||
'install',
|
||||
'uninstall',
|
||||
'pushListener',
|
||||
'popListener'
|
||||
]);
|
||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||
env.cleanup_();
|
||||
env = new jasmineUnderTest.Env({ suppressLoadErrors: true });
|
||||
expect(globalErrors.install).not.toHaveBeenCalled();
|
||||
env.execute();
|
||||
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.execute(null, function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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.execute(null, function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#execute', function() {
|
||||
it('returns a promise when the environment supports promises', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
expect(env.execute()).toBeInstanceOf(Promise);
|
||||
});
|
||||
|
||||
it('returns a promise when a custom promise constructor is provided', function() {
|
||||
function CustomPromise() {}
|
||||
CustomPromise.resolve = function() {};
|
||||
CustomPromise.reject = function() {};
|
||||
|
||||
env.configure({ Promise: CustomPromise });
|
||||
expect(env.execute()).toBeInstanceOf(CustomPromise);
|
||||
});
|
||||
|
||||
it('returns undefined when promises are unavailable', function() {
|
||||
jasmine.getEnv().requireNoPromises();
|
||||
expect(env.execute()).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should reset the topSuite when run twice', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
spyOn(env.topSuite(), 'reset');
|
||||
return env
|
||||
.execute() // 1
|
||||
.then(function() {
|
||||
return env.execute(); // 2
|
||||
})
|
||||
.then(function() {
|
||||
expect(env.topSuite().reset).toHaveBeenCalledOnceWith();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,6 +86,37 @@ describe('ExceptionFormatter', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames from V8-style traces but leaves unmatched lines intact', function() {
|
||||
var error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||
" new Error('nope');\n" +
|
||||
' ^\n' +
|
||||
'\n' +
|
||||
'Error: nope\n' +
|
||||
' at fn1 (C:\\__spec__\\core\\UtilSpec.js:115:19)\n' +
|
||||
' -> C:\\__spec__\\core\\UtilSpec.ts:120:15\n' +
|
||||
' at fn2 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7533:40)\n' +
|
||||
' at fn3 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7575:25)\n' +
|
||||
' at fn4 (node:internal/timers:462:21)\n'
|
||||
};
|
||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: 'C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js'
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
expect(result).toEqual(
|
||||
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||
" new Error('nope');\n" +
|
||||
' ^\n' +
|
||||
'Error: nope\n' +
|
||||
' at fn1 (C:\\__spec__\\core\\UtilSpec.js:115:19)\n' +
|
||||
' -> C:\\__spec__\\core\\UtilSpec.ts:120:15\n' +
|
||||
' at <Jasmine>\n' +
|
||||
' at fn4 (node:internal/timers:462:21)'
|
||||
);
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames from V8 style traces', function() {
|
||||
var error = {
|
||||
message: 'nope',
|
||||
|
||||
@@ -5,6 +5,10 @@ describe('Exceptions:', function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
it('should handle exceptions thrown, but continue', function(done) {
|
||||
var secondTest = jasmine.createSpy('second test');
|
||||
env.describe('Suite for handles exceptions', function() {
|
||||
@@ -25,8 +29,7 @@ describe('Exceptions:', function() {
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
|
||||
@@ -45,7 +48,6 @@ describe('Exceptions:', function() {
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,21 +72,21 @@ describe('ExpectationFilterChain', function() {
|
||||
matcherResult = { pass: false },
|
||||
matcherName = 'foo',
|
||||
args = [],
|
||||
util = {},
|
||||
matchersUtil = {},
|
||||
result;
|
||||
|
||||
result = chain.buildFailureMessage(
|
||||
matcherResult,
|
||||
matcherName,
|
||||
args,
|
||||
util
|
||||
matchersUtil
|
||||
);
|
||||
|
||||
expect(first).toHaveBeenCalledWith(
|
||||
matcherResult,
|
||||
matcherName,
|
||||
args,
|
||||
util
|
||||
matchersUtil
|
||||
);
|
||||
expect(second).not.toHaveBeenCalled();
|
||||
expect(result).toEqual('first');
|
||||
|
||||
@@ -90,4 +90,37 @@ describe('buildExpectationResult', function() {
|
||||
});
|
||||
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 = {
|
||||
toFoo: matcherFactory
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
customEqualityTesters = ['a'],
|
||||
@@ -45,7 +45,7 @@ describe('Expectation', function() {
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
customMatchers: matchers,
|
||||
customEqualityTesters: customEqualityTesters,
|
||||
actual: 'an actual',
|
||||
@@ -54,7 +54,10 @@ describe('Expectation', function() {
|
||||
|
||||
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() {
|
||||
@@ -68,14 +71,14 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -96,7 +99,7 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
@@ -104,7 +107,7 @@ describe('Expectation', function() {
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -132,7 +135,7 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return '';
|
||||
}
|
||||
@@ -142,7 +145,7 @@ describe('Expectation', function() {
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -275,7 +278,7 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'default message';
|
||||
}
|
||||
@@ -287,7 +290,7 @@ describe('Expectation', function() {
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
addExpectationResult: addExpectationResult
|
||||
}).not;
|
||||
|
||||
@@ -539,7 +542,7 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
util = {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
@@ -547,7 +550,7 @@ describe('Expectation', function() {
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
util: util,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
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() {
|
||||
var matchers = {
|
||||
toFoo: function() {
|
||||
@@ -632,9 +661,10 @@ describe('Expectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
util: jasmineUnderTest.matchersUtil,
|
||||
matchersUtil: new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
@@ -12,6 +12,23 @@ describe('GlobalErrors', function() {
|
||||
expect(handler).toHaveBeenCalledWith('foo');
|
||||
});
|
||||
|
||||
it('enables external interception of error by overriding global.onerror', function() {
|
||||
var fakeGlobal = { onerror: null },
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
|
||||
fakeGlobal.onerror('foo');
|
||||
|
||||
expect(hijackHandler).toHaveBeenCalledWith('foo');
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls the global error handler with all parameters', function() {
|
||||
var fakeGlobal = { onerror: null },
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
@@ -58,7 +75,7 @@ describe('GlobalErrors', function() {
|
||||
errors.pushListener(handler1);
|
||||
errors.pushListener(handler2);
|
||||
|
||||
errors.popListener();
|
||||
errors.popListener(handler2);
|
||||
|
||||
fakeGlobal.onerror('foo');
|
||||
|
||||
@@ -66,6 +83,13 @@ describe('GlobalErrors', function() {
|
||||
expect(handler2).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws when no listener is passed to #popListener', function() {
|
||||
var errors = new jasmineUnderTest.GlobalErrors({});
|
||||
expect(function() {
|
||||
errors.popListener();
|
||||
}).toThrowError('popListener expects a listener');
|
||||
});
|
||||
|
||||
it('uninstalls itself, putting back a previous callback', function() {
|
||||
var originalCallback = jasmine.createSpy('error'),
|
||||
fakeGlobal = { onerror: originalCallback },
|
||||
@@ -98,7 +122,7 @@ describe('GlobalErrors', function() {
|
||||
errors.uninstall();
|
||||
});
|
||||
|
||||
it('reports uncaughtException in node.js', function() {
|
||||
it('reports uncaught exceptions in node.js', function() {
|
||||
var fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
@@ -146,51 +170,252 @@ describe('GlobalErrors', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('reports unhandledRejection in node.js', function() {
|
||||
var fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: jasmine.createSpy('process.removeListener'),
|
||||
listeners: jasmine
|
||||
.createSpy('process.listeners')
|
||||
.and.returnValue(['foo']),
|
||||
removeAllListeners: jasmine.createSpy('process.removeAllListeners')
|
||||
describe('Reporting unhandled promise rejections in node.js', function() {
|
||||
it('reports rejections with `Error` reasons', function() {
|
||||
var fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: jasmine.createSpy('process.removeListener'),
|
||||
listeners: jasmine
|
||||
.createSpy('process.listeners')
|
||||
.and.returnValue(['foo']),
|
||||
removeAllListeners: jasmine.createSpy('process.removeAllListeners')
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
jasmine.any(Function)
|
||||
);
|
||||
expect(fakeGlobal.process.listeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
expect(fakeGlobal.process.removeAllListeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
|
||||
errors.pushListener(handler);
|
||||
|
||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(new Error('bar'));
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
||||
expect(handler.calls.argsFor(0)[0].jasmineMessage).toBe(
|
||||
'Unhandled promise rejection: Error: bar'
|
||||
);
|
||||
|
||||
errors.uninstall();
|
||||
|
||||
expect(fakeGlobal.process.removeListener).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
addedListener
|
||||
);
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
'foo'
|
||||
);
|
||||
});
|
||||
|
||||
it('reports rejections with non-`Error` reasons', function() {
|
||||
var fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: function() {},
|
||||
listeners: function() {
|
||||
return [];
|
||||
},
|
||||
removeAllListeners: function() {}
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
||||
'unhandledRejection'
|
||||
);
|
||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(17);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
new Error(
|
||||
'Unhandled promise rejection: 17\n' +
|
||||
'(Tip: to get a useful stack trace, use ' +
|
||||
'Promise.reject(new Error(...)) instead of Promise.reject(...).)'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('reports rejections with no reason provided', function() {
|
||||
var fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: function() {},
|
||||
listeners: function() {
|
||||
return [];
|
||||
},
|
||||
removeAllListeners: function() {}
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
||||
'unhandledRejection'
|
||||
);
|
||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(undefined);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
new Error(
|
||||
'Unhandled promise rejection with no error or message\n' +
|
||||
'(Tip: to get a useful stack trace, use ' +
|
||||
'Promise.reject(new Error(...)) instead of Promise.reject().)'
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
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
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('Enabling external interception of reported rejections by overriding global.onerror', function() {
|
||||
it('overriding global.onerror intercepts rejections whose reason is a string', function() {
|
||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
|
||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
addedListener({ reason: 'nope' });
|
||||
|
||||
expect(hijackHandler).toHaveBeenCalledWith(
|
||||
'Unhandled promise rejection: nope'
|
||||
);
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('overriding global.onerror intercepts rejections whose reason is an Error', function() {
|
||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
|
||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
var reason;
|
||||
|
||||
try {
|
||||
// Throwing ensures that we get a stack property in all browsers
|
||||
throw new Error('bar');
|
||||
} catch (e) {
|
||||
reason = e;
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
jasmine.any(Function)
|
||||
);
|
||||
expect(fakeGlobal.process.listeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
expect(fakeGlobal.process.removeAllListeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
addedListener({ reason: reason });
|
||||
|
||||
errors.pushListener(handler);
|
||||
|
||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(new Error('bar'));
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
||||
expect(handler.calls.argsFor(0)[0].jasmineMessage).toBe(
|
||||
'Unhandled promise rejection: Error: bar'
|
||||
);
|
||||
|
||||
errors.uninstall();
|
||||
|
||||
expect(fakeGlobal.process.removeListener).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
addedListener
|
||||
);
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
'foo'
|
||||
);
|
||||
expect(hijackHandler).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||
message: reason.message,
|
||||
stack: reason.stack
|
||||
})
|
||||
);
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
describe('jasmineUnderTest.pp', function() {
|
||||
describe('PrettyPrinter', function() {
|
||||
it('should wrap strings in single quotes', function() {
|
||||
expect(jasmineUnderTest.pp('some string')).toEqual("'some string'");
|
||||
expect(jasmineUnderTest.pp("som' string")).toEqual("'som' string'");
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp('some string')).toEqual("'some string'");
|
||||
expect(pp("som' string")).toEqual("'som' string'");
|
||||
});
|
||||
|
||||
it('should stringify primitives properly', function() {
|
||||
expect(jasmineUnderTest.pp(true)).toEqual('true');
|
||||
expect(jasmineUnderTest.pp(false)).toEqual('false');
|
||||
expect(jasmineUnderTest.pp(null)).toEqual('null');
|
||||
expect(jasmineUnderTest.pp(jasmine.undefined)).toEqual('undefined');
|
||||
expect(jasmineUnderTest.pp(3)).toEqual('3');
|
||||
expect(jasmineUnderTest.pp(-3.14)).toEqual('-3.14');
|
||||
expect(jasmineUnderTest.pp(-0)).toEqual('-0');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(true)).toEqual('true');
|
||||
expect(pp(false)).toEqual('false');
|
||||
expect(pp(null)).toEqual('null');
|
||||
expect(pp(jasmine.undefined)).toEqual('undefined');
|
||||
expect(pp(3)).toEqual('3');
|
||||
expect(pp(-3.14)).toEqual('-3.14');
|
||||
expect(pp(-0)).toEqual('-0');
|
||||
});
|
||||
|
||||
describe('stringify sets', function() {
|
||||
it('should stringify sets properly', function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var set = new Set();
|
||||
var set = new Set(); // eslint-disable-line compat/compat
|
||||
set.add(1);
|
||||
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() {
|
||||
@@ -29,11 +32,12 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
try {
|
||||
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('b');
|
||||
set.add('c');
|
||||
expect(jasmineUnderTest.pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
@@ -43,9 +47,10 @@ describe('jasmineUnderTest.pp', function() {
|
||||
describe('stringify maps', function() {
|
||||
it('should stringify maps properly', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var map = new Map();
|
||||
var map = new Map(); // eslint-disable-line compat/compat
|
||||
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() {
|
||||
@@ -54,13 +59,12 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
try {
|
||||
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('b', 2);
|
||||
map.set('c', 3);
|
||||
expect(jasmineUnderTest.pp(map)).toEqual(
|
||||
"Map( [ 'a', 1 ], [ 'b', 2 ], ... )"
|
||||
);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
@@ -69,43 +73,44 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
describe('stringify arrays', function() {
|
||||
it('should stringify arrays properly', function() {
|
||||
expect(jasmineUnderTest.pp([1, 2])).toEqual('[ 1, 2 ]');
|
||||
expect(
|
||||
jasmineUnderTest.pp([1, 'foo', {}, jasmine.undefined, null])
|
||||
).toEqual("[ 1, 'foo', Object({ }), undefined, null ]");
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp([1, 2])).toEqual('[ 1, 2 ]');
|
||||
expect(pp([1, 'foo', {}, jasmine.undefined, null])).toEqual(
|
||||
"[ 1, 'foo', Object({ }), undefined, null ]"
|
||||
);
|
||||
});
|
||||
|
||||
it('should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var array = [1, 2, 3];
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(array)).toEqual('[ 1, 2, ... ]');
|
||||
expect(pp(array)).toEqual('[ 1, 2, ... ]');
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||
}
|
||||
});
|
||||
|
||||
it('should stringify arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var arr = [1, 2];
|
||||
arr.foo = 'bar';
|
||||
arr.baz = {};
|
||||
expect(jasmineUnderTest.pp(arr)).toEqual(
|
||||
"[ 1, 2, foo: 'bar', baz: Object({ }) ]"
|
||||
);
|
||||
expect(pp(arr)).toEqual("[ 1, 2, foo: 'bar', baz: Object({ }) ]");
|
||||
});
|
||||
|
||||
it('should stringify empty arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var empty = [];
|
||||
empty.foo = 'bar';
|
||||
empty.baz = {};
|
||||
expect(jasmineUnderTest.pp(empty)).toEqual(
|
||||
"[ foo: 'bar', baz: Object({ }) ]"
|
||||
);
|
||||
expect(pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
|
||||
});
|
||||
|
||||
it('should stringify long arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = [1, 2, 3];
|
||||
long.foo = 'bar';
|
||||
@@ -113,7 +118,7 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(long)).toEqual(
|
||||
expect(pp(long)).toEqual(
|
||||
"[ 1, 2, ..., foo: 'bar', baz: Object({ }) ]"
|
||||
);
|
||||
} finally {
|
||||
@@ -122,26 +127,25 @@ describe('jasmineUnderTest.pp', function() {
|
||||
});
|
||||
|
||||
it('should indicate circular array references', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var array1 = [1, 2];
|
||||
var array2 = [array1];
|
||||
array1.push(array2);
|
||||
expect(jasmineUnderTest.pp(array1)).toEqual(
|
||||
'[ 1, 2, [ <circular reference: Array> ] ]'
|
||||
);
|
||||
expect(pp(array1)).toEqual('[ 1, 2, [ <circular reference: Array> ] ]');
|
||||
});
|
||||
|
||||
it('should not indicate circular references incorrectly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var array = [[1]];
|
||||
expect(jasmineUnderTest.pp(array)).toEqual('[ [ 1 ] ]');
|
||||
expect(pp(array)).toEqual('[ [ 1 ] ]');
|
||||
});
|
||||
});
|
||||
|
||||
it('should stringify objects properly', function() {
|
||||
expect(jasmineUnderTest.pp({ foo: 'bar' })).toEqual(
|
||||
"Object({ foo: 'bar' })"
|
||||
);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ foo: 'bar' })).toEqual("Object({ foo: 'bar' })");
|
||||
expect(
|
||||
jasmineUnderTest.pp({
|
||||
pp({
|
||||
foo: 'bar',
|
||||
baz: 3,
|
||||
nullValue: null,
|
||||
@@ -150,24 +154,24 @@ describe('jasmineUnderTest.pp', function() {
|
||||
).toEqual(
|
||||
"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 ] })'
|
||||
);
|
||||
});
|
||||
|
||||
it('should stringify objects that almost look like DOM nodes', function() {
|
||||
expect(jasmineUnderTest.pp({ nodeType: 1 })).toEqual(
|
||||
'Object({ nodeType: 1 })'
|
||||
);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ nodeType: 1 })).toEqual('Object({ nodeType: 1 })');
|
||||
});
|
||||
|
||||
it('should truncate objects with too many keys', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = { a: 1, b: 2, c: 3 };
|
||||
|
||||
try {
|
||||
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 {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||
}
|
||||
@@ -185,12 +189,11 @@ describe('jasmineUnderTest.pp', function() {
|
||||
}
|
||||
|
||||
it('should truncate outputs that are too long', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var big = [{ a: 1, b: 'a long string' }, {}];
|
||||
|
||||
withMaxChars(34, function() {
|
||||
expect(jasmineUnderTest.pp(big)).toEqual(
|
||||
"[ Object({ a: 1, b: 'a long st ..."
|
||||
);
|
||||
expect(pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -214,59 +217,55 @@ describe('jasmineUnderTest.pp', function() {
|
||||
jasmineToString: jasmine
|
||||
.createSpy('d jasmineToString')
|
||||
.and.returnValue('')
|
||||
};
|
||||
},
|
||||
pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
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(d.jasmineToString).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
||||
expect(jasmineUnderTest.pp({ constructor: function() {} })).toContain(
|
||||
'null({'
|
||||
);
|
||||
expect(jasmineUnderTest.pp({ constructor: 'foo' })).toContain('null({');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ constructor: function() {} })).toContain('null({');
|
||||
expect(pp({ constructor: 'foo' })).toContain('null({');
|
||||
});
|
||||
|
||||
it('should not include inherited properties when stringifying an object', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var SomeClass = function SomeClass() {};
|
||||
SomeClass.prototype.foo = 'inherited foo';
|
||||
var instance = new SomeClass();
|
||||
instance.bar = 'my own bar';
|
||||
expect(jasmineUnderTest.pp(instance)).toEqual(
|
||||
"SomeClass({ bar: 'my own bar' })"
|
||||
);
|
||||
expect(pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
|
||||
});
|
||||
|
||||
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 nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
||||
var nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
|
||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
||||
expect(pp(nestedObject)).toEqual(
|
||||
'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;
|
||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
||||
expect(pp(nestedObject)).toEqual(
|
||||
'Object({ level1: Object({ level2: Object({ level3: Object }) }) })'
|
||||
);
|
||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual(
|
||||
'[ 1, [ 2, [ 3, Array ] ] ]'
|
||||
);
|
||||
expect(pp(nestedArray)).toEqual('[ 1, [ 2, [ 3, Array ] ] ]');
|
||||
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 4;
|
||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
||||
expect(pp(nestedObject)).toEqual(
|
||||
"Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })"
|
||||
);
|
||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual(
|
||||
"[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]"
|
||||
);
|
||||
expect(pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
|
||||
}
|
||||
@@ -274,28 +273,32 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
it('should stringify immutable circular objects', function() {
|
||||
if (Object.freeze) {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var frozenObject = { foo: { bar: 'baz' } };
|
||||
frozenObject.circular = frozenObject;
|
||||
frozenObject = Object.freeze(frozenObject);
|
||||
expect(jasmineUnderTest.pp(frozenObject)).toEqual(
|
||||
expect(pp(frozenObject)).toEqual(
|
||||
"Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var sampleValue = { foo: 'hello' };
|
||||
sampleValue.nested = sampleValue;
|
||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual(
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
"Object({ foo: 'hello', nested: <circular reference: Object> })"
|
||||
);
|
||||
});
|
||||
|
||||
it('should indicate getters on objects as such', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var sampleValue = { id: 1 };
|
||||
if (sampleValue.__defineGetter__) {
|
||||
//not supported in IE!
|
||||
@@ -304,95 +307,117 @@ describe('jasmineUnderTest.pp', function() {
|
||||
});
|
||||
}
|
||||
if (sampleValue.__defineGetter__) {
|
||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual(
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
'Object({ id: 1, calculatedValue: <getter> })'
|
||||
);
|
||||
} 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() {
|
||||
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> &'"
|
||||
);
|
||||
});
|
||||
|
||||
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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
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() {
|
||||
var TestObject = {
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env();
|
||||
describe('with a spy object', function() {
|
||||
var env, pp;
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return [];
|
||||
},
|
||||
createSpy: function(name, originalFn) {
|
||||
return jasmineUnderTest.Spy(name, originalFn);
|
||||
}
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
pp = jasmineUnderTest.makePrettyPrinter();
|
||||
});
|
||||
|
||||
spyRegistry.spyOn(TestObject, 'someFunction');
|
||||
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual(
|
||||
'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);
|
||||
}
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
spyRegistry.spyOn(TestObject, 'toString');
|
||||
var testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
||||
it('should stringify spy objects properly', function() {
|
||||
var TestObject = {
|
||||
someFunction: function() {}
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.pp(testSpyObj)).toEqual(
|
||||
'spy on TheClassName.toString'
|
||||
);
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
jasmineToString: function() {
|
||||
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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
toString: function() {
|
||||
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
|
||||
// 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 })"
|
||||
);
|
||||
});
|
||||
|
||||
it("should stringify objects have have a toString that isn't a function", function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var MyAnonymousConstructor = (function() {
|
||||
return function() {};
|
||||
})();
|
||||
@@ -426,17 +453,19 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
var a = new MyAnonymousConstructor();
|
||||
|
||||
expect(jasmineUnderTest.pp(a)).toEqual('<anonymous>({ })');
|
||||
expect(pp(a)).toEqual('<anonymous>({ })');
|
||||
});
|
||||
|
||||
it('should handle objects with null prototype', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = Object.create(null);
|
||||
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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
foo: {
|
||||
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 })'
|
||||
);
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -512,6 +512,50 @@ describe('QueueRunner', function() {
|
||||
expect(onExceptionCallback).toHaveBeenCalledWith('foo');
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('issues a deprecation if the function also takes a parameter', function() {
|
||||
var queueableFn = {
|
||||
fn: function(done) {
|
||||
return new StubPromise();
|
||||
}
|
||||
},
|
||||
deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
deprecated: deprecated
|
||||
}),
|
||||
env = jasmineUnderTest.getEnv();
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(deprecated).toHaveBeenCalledWith(
|
||||
'An asynchronous ' +
|
||||
'before/it/after function took a done callback but also returned a ' +
|
||||
'promise. This is not supported and will stop working in the future. ' +
|
||||
'Either remove the done callback (recommended) or change the function ' +
|
||||
'to not return a promise.'
|
||||
);
|
||||
});
|
||||
|
||||
it('issues a more specific deprecation if the function is `async`', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
eval('var fn = async function(done){};');
|
||||
var deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [{ fn: fn }],
|
||||
deprecated: deprecated
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(deprecated).toHaveBeenCalledWith(
|
||||
'An asynchronous ' +
|
||||
'before/it/after function was defined with the async keyword but ' +
|
||||
'also took a done callback. This is not supported and will stop ' +
|
||||
'working in the future. Either remove the done callback ' +
|
||||
'(recommended) or remove the async keyword.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('passes the error instance to exception handlers in HTML browsers', function() {
|
||||
@@ -625,9 +669,13 @@ describe('QueueRunner', function() {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it('skips to cleanup functions on the first exception', function() {
|
||||
it('skips to cleanup functions once the fn completes after an unhandled exception', function() {
|
||||
var errorListeners = [],
|
||||
queueableFn = { fn: function(done) {} },
|
||||
queueableFn = {
|
||||
fn: function(done) {
|
||||
queueableFnDone = done;
|
||||
}
|
||||
},
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
@@ -642,10 +690,13 @@ describe('QueueRunner', function() {
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true
|
||||
});
|
||||
}),
|
||||
queueableFnDone;
|
||||
|
||||
queueRunner.execute();
|
||||
errorListeners[errorListeners.length - 1](new Error('error'));
|
||||
expect(cleanupFn.fn).not.toHaveBeenCalled();
|
||||
queueableFnDone();
|
||||
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
|
||||
expect(cleanupFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -227,7 +227,8 @@ describe('Spec', function() {
|
||||
passedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
pendingReason: '',
|
||||
duration: null
|
||||
duration: jasmine.any(Number),
|
||||
properties: null
|
||||
},
|
||||
'things'
|
||||
);
|
||||
@@ -273,8 +274,34 @@ describe('Spec', 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'),
|
||||
timer = jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||
catchExceptions: function() {
|
||||
@@ -283,11 +310,11 @@ describe('Spec', function() {
|
||||
resultCallback: function() {},
|
||||
queueRunnerFactory: function(attrs) {
|
||||
attrs.onComplete();
|
||||
},
|
||||
timer: timer
|
||||
}
|
||||
});
|
||||
spec.setSpecProperty('a', 4);
|
||||
spec.execute(done);
|
||||
expect(spec.result.duration).toBe(77000);
|
||||
expect(spec.result.properties).toEqual({ a: 4 });
|
||||
});
|
||||
|
||||
it('#status returns passing by default', function() {
|
||||
|
||||
@@ -407,6 +407,123 @@ describe('SpyRegistry', function() {
|
||||
expect(subject.toString).not.toBe('I am a spy');
|
||||
expect(subject.hasOwnProperty).not.toBe('I am a spy');
|
||||
});
|
||||
describe('when includeNonEnumerable is true', function() {
|
||||
it('does not override Object.prototype methods', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var subject = {
|
||||
spied1: function() {}
|
||||
};
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.spied1).toBe('I am a spy');
|
||||
expect(subject.toString).not.toBe('I am a spy');
|
||||
expect(subject.hasOwnProperty).not.toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('overrides non-enumerable properties', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var subject = {
|
||||
spied1: function() {},
|
||||
spied2: function() {}
|
||||
};
|
||||
|
||||
Object.defineProperty(subject, 'spied2', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.spied1).toBe('I am a spy');
|
||||
expect(subject.spied2).toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('should not spy on non-enumerable functions named constructor', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var subject = {
|
||||
constructor: function() {}
|
||||
};
|
||||
|
||||
Object.defineProperty(subject, 'constructor', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.constructor).not.toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('should spy on enumerable functions named constructor', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var subject = {
|
||||
constructor: function() {}
|
||||
};
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.constructor).toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('should not throw an exception if we try and access strict mode restricted properties', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var subject = function() {};
|
||||
var fn = function() {
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
};
|
||||
|
||||
expect(fn).not.toThrow();
|
||||
});
|
||||
|
||||
it('should not spy on properties which are more permissable further up the prototype chain', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var subjectParent = Object.defineProperty({}, 'sharedProp', {
|
||||
value: function() {},
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
var subject = Object.create(subjectParent);
|
||||
|
||||
Object.defineProperty(subject, 'sharedProp', {
|
||||
value: function() {}
|
||||
});
|
||||
|
||||
var fn = function() {
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
};
|
||||
|
||||
expect(fn).not.toThrow();
|
||||
expect(subject).not.toBe('I am a spy');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clearSpies', function() {
|
||||
|
||||
@@ -5,6 +5,10 @@ describe('Spies', function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
describe('createSpy', function() {
|
||||
var TestClass;
|
||||
|
||||
@@ -179,14 +183,13 @@ describe('Spies', function() {
|
||||
var spyObj = env.createSpyObj('base', ['method1'], ['prop1']);
|
||||
|
||||
expect(spyObj).toEqual({
|
||||
method1: jasmine.any(Function)
|
||||
method1: jasmine.any(Function),
|
||||
prop1: undefined
|
||||
});
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(spyObj, 'prop1');
|
||||
expect(descriptor.get.and.identity).toEqual('base.prop1.get');
|
||||
expect(descriptor.set.and.identity).toEqual('base.prop1.set');
|
||||
|
||||
expect(spyObj.prop1).toBeUndefined();
|
||||
});
|
||||
|
||||
it('creates an object with property names and return values if second object is passed', function() {
|
||||
@@ -196,7 +199,9 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
expect(spyObj).toEqual({
|
||||
method1: jasmine.any(Function)
|
||||
method1: jasmine.any(Function),
|
||||
prop1: 'foo',
|
||||
prop2: 37
|
||||
});
|
||||
|
||||
expect(spyObj.prop1).toEqual('foo');
|
||||
@@ -208,7 +213,7 @@ describe('Spies', function() {
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it('allows base name to be ommitted when assigning methods and properties', function() {
|
||||
it('allows base name to be omitted when assigning methods and properties', function() {
|
||||
var spyObj = env.createSpyObj({ m: 3 }, { p: 4 });
|
||||
|
||||
expect(spyObj.m()).toEqual(3);
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('SpyStrategy', function() {
|
||||
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'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
@@ -82,6 +82,18 @@ describe('SpyStrategy', function() {
|
||||
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(jasmine.objectContaining({ code: 'ESRCH' }));
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows a fake function to be called instead', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||
@@ -140,6 +152,28 @@ describe('SpyStrategy', function() {
|
||||
.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() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
@@ -176,6 +210,29 @@ describe('SpyStrategy', function() {
|
||||
.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) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
@@ -277,6 +334,17 @@ describe('SpyStrategy', function() {
|
||||
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
||||
});
|
||||
|
||||
it('allows generator functions to be passed to callFake strategy', function() {
|
||||
jasmine.getEnv().requireGeneratorFunctions();
|
||||
|
||||
var generator = jasmine.getEnv().makeGeneratorFunction('yield "ok";'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
|
||||
|
||||
spyStrategy.callFake(generator);
|
||||
|
||||
expect(spyStrategy.exec().next().value).toEqual('ok');
|
||||
});
|
||||
|
||||
it('allows a return to plan stubbing after another strategy', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||
|
||||
@@ -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() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
it('keeps its id', function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
id: 456,
|
||||
description: 'I am a suite'
|
||||
});
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
id: 456,
|
||||
description: 'I am a suite'
|
||||
});
|
||||
|
||||
expect(suite.id).toEqual(456);
|
||||
});
|
||||
|
||||
it('returns blank full name for top level suite', function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
});
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
});
|
||||
|
||||
expect(suite.getFullName()).toEqual('');
|
||||
});
|
||||
|
||||
it('returns its full name when it has parent suites', function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
parentSuite = new jasmineUnderTest.Suite({
|
||||
var parentSuite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a parent 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() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
suite = new jasmineUnderTest.Suite({
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
@@ -52,8 +58,7 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
it('adds after functions in order of needed execution', function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
suite = new jasmineUnderTest.Suite({
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
@@ -115,13 +120,12 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
it('calls timer to compute duration', function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
id: 456,
|
||||
description: 'I am a suite',
|
||||
timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 })
|
||||
});
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
id: 456,
|
||||
description: 'I am a suite',
|
||||
timer: jasmine.createSpyObj('timer', { start: null, elapsed: 77000 })
|
||||
});
|
||||
suite.startTimer();
|
||||
suite.endTimer();
|
||||
expect(suite.getResult().duration).toEqual(77000);
|
||||
@@ -138,4 +142,86 @@ describe('Suite', function() {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('attr.autoCleanClosures', function() {
|
||||
function arrangeSuite(attrs) {
|
||||
var suite = new jasmineUnderTest.Suite(attrs);
|
||||
suite.beforeAll(function() {});
|
||||
suite.beforeEach(function() {});
|
||||
suite.afterEach(function() {});
|
||||
suite.afterAll(function() {});
|
||||
return suite;
|
||||
}
|
||||
|
||||
it('should clean closures when "attr.autoCleanClosures" is missing', function() {
|
||||
var suite = arrangeSuite({});
|
||||
suite.cleanupBeforeAfter();
|
||||
expect(suite.beforeAllFns[0].fn).toBe(null);
|
||||
expect(suite.beforeFns[0].fn).toBe(null);
|
||||
expect(suite.afterFns[0].fn).toBe(null);
|
||||
expect(suite.afterAllFns[0].fn).toBe(null);
|
||||
});
|
||||
|
||||
it('should clean closures when "attr.autoCleanClosures" is true', function() {
|
||||
var suite = arrangeSuite({ autoCleanClosures: true });
|
||||
suite.cleanupBeforeAfter();
|
||||
expect(suite.beforeAllFns[0].fn).toBe(null);
|
||||
expect(suite.beforeFns[0].fn).toBe(null);
|
||||
expect(suite.afterFns[0].fn).toBe(null);
|
||||
expect(suite.afterAllFns[0].fn).toBe(null);
|
||||
});
|
||||
|
||||
it('should NOT clean closures when "attr.autoCleanClosures" is false', function() {
|
||||
var suite = arrangeSuite({ autoCleanClosures: false });
|
||||
suite.cleanupBeforeAfter();
|
||||
expect(suite.beforeAllFns[0].fn).not.toBe(null);
|
||||
expect(suite.beforeFns[0].fn).not.toBe(null);
|
||||
expect(suite.afterFns[0].fn).not.toBe(null);
|
||||
expect(suite.afterAllFns[0].fn).not.toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#reset', function() {
|
||||
it('should reset the "pending" status', function() {
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
suite.pend();
|
||||
suite.reset();
|
||||
expect(suite.getResult().status).toBe('passed');
|
||||
});
|
||||
|
||||
it('should not reset the "pending" status when the suite was excluded', function() {
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
suite.exclude();
|
||||
suite.reset();
|
||||
expect(suite.getResult().status).toBe('pending');
|
||||
});
|
||||
|
||||
it('should also reset the children', function() {
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
var child1 = jasmine.createSpyObj(['reset']);
|
||||
var child2 = jasmine.createSpyObj(['reset']);
|
||||
suite.addChild(child1);
|
||||
suite.addChild(child2);
|
||||
|
||||
suite.reset();
|
||||
|
||||
expect(child1.reset).toHaveBeenCalled();
|
||||
expect(child2.reset).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset the failedExpectations', function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
expectationResultFactory: function(error) {
|
||||
return error;
|
||||
}
|
||||
});
|
||||
suite.onException(new Error());
|
||||
|
||||
suite.reset();
|
||||
|
||||
var result = suite.getResult();
|
||||
expect(result.status).toBe('passed');
|
||||
expect(result.failedExpectations).toHaveSize(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('jasmineUnderTest.util', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
mockNativePromise = new Promise(function(res, rej) {});
|
||||
mockNativePromise = new Promise(function(res, rej) {}); // eslint-disable-line compat/compat
|
||||
mockPromiseLikeObject = new mockPromiseLike();
|
||||
});
|
||||
|
||||
|
||||
139
spec/core/asymmetricEqualityTesterArgCompatShimSpec.js
Normal file
139
spec/core/asymmetricEqualityTesterArgCompatShimSpec.js
Normal file
@@ -0,0 +1,139 @@
|
||||
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',
|
||||
'every',
|
||||
'filter',
|
||||
'forEach',
|
||||
'indexOf',
|
||||
'join',
|
||||
'lastIndexOf',
|
||||
'length',
|
||||
'map',
|
||||
'pop',
|
||||
'push',
|
||||
'reduce',
|
||||
'reduceRight',
|
||||
'reverse',
|
||||
'shift',
|
||||
'slice',
|
||||
'some',
|
||||
'sort',
|
||||
'splice',
|
||||
'unshift'
|
||||
],
|
||||
optionalKeys = [
|
||||
'copyWithin',
|
||||
'entries',
|
||||
'fill',
|
||||
'find',
|
||||
'findIndex',
|
||||
'flat',
|
||||
'flatMap',
|
||||
'includes',
|
||||
'keys',
|
||||
'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]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe('When Array.prototype additions collide with MatchersUtil methods', function() {
|
||||
function keys() {
|
||||
return [
|
||||
'contains',
|
||||
'buildFailureMessage',
|
||||
'asymmetricDiff_',
|
||||
'asymmetricMatch_',
|
||||
'equals',
|
||||
'eq_'
|
||||
];
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
keys().forEach(function(k) {
|
||||
expect(Array.prototype[k])
|
||||
.withContext('Array.prototype already had ' + k)
|
||||
.toBeUndefined();
|
||||
Array.prototype[k] = function() {};
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
keys().forEach(function(k) {
|
||||
delete Array.prototype[k];
|
||||
});
|
||||
});
|
||||
|
||||
it('uses the MatchersUtil methods', function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({}),
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||
matchersUtil,
|
||||
[]
|
||||
);
|
||||
|
||||
keys().forEach(function(k) {
|
||||
expect(shim[k])
|
||||
.withContext(k + ' was overwritten')
|
||||
.toBe(jasmineUnderTest.MatchersUtil.prototype[k]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,74 +1,72 @@
|
||||
describe("Any", function() {
|
||||
it("matches a string", function() {
|
||||
describe('Any', function() {
|
||||
it('matches a string', function() {
|
||||
var any = new jasmineUnderTest.Any(String);
|
||||
|
||||
expect(any.asymmetricMatch("foo")).toBe(true);
|
||||
expect(any.asymmetricMatch('foo')).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a number", function() {
|
||||
it('matches a number', function() {
|
||||
var any = new jasmineUnderTest.Any(Number);
|
||||
|
||||
expect(any.asymmetricMatch(1)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a function", function() {
|
||||
it('matches a function', function() {
|
||||
var any = new jasmineUnderTest.Any(Function);
|
||||
|
||||
expect(any.asymmetricMatch(function(){})).toBe(true);
|
||||
expect(any.asymmetricMatch(function() {})).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an Object", function() {
|
||||
it('matches an Object', function() {
|
||||
var any = new jasmineUnderTest.Any(Object);
|
||||
|
||||
expect(any.asymmetricMatch({})).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Boolean", function() {
|
||||
it('matches a Boolean', function() {
|
||||
var any = new jasmineUnderTest.Any(Boolean);
|
||||
|
||||
expect(any.asymmetricMatch(true)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Map", function() {
|
||||
it('matches a Map', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
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() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
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() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
|
||||
it('matches a TypedArray', function() {
|
||||
var any = new jasmineUnderTest.Any(Uint32Array);
|
||||
|
||||
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();
|
||||
|
||||
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() {
|
||||
var Thing = function() {},
|
||||
any = new jasmineUnderTest.Any(Thing);
|
||||
|
||||
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
||||
});
|
||||
|
||||
it("does not treat null as an Object", function() {
|
||||
it('does not treat null as an Object', function() {
|
||||
var any = new jasmineUnderTest.Any(Object);
|
||||
|
||||
expect(any.asymmetricMatch(null)).toBe(false);
|
||||
@@ -81,8 +79,8 @@ describe("Any", function() {
|
||||
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
||||
});
|
||||
|
||||
describe("when called without an argument", function() {
|
||||
it("tells the user to pass a constructor or use jasmine.anything()", function() {
|
||||
describe('when called without an argument', function() {
|
||||
it('tells the user to pass a constructor or use jasmine.anything()', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.Any();
|
||||
}).toThrowError(TypeError, /constructor.*anything/);
|
||||
|
||||
@@ -1,58 +1,56 @@
|
||||
describe("Anything", function() {
|
||||
it("matches a string", function() {
|
||||
describe('Anything', function() {
|
||||
it('matches a string', function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch('foo')).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a number", function() {
|
||||
it('matches a number', function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(42)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an object", function() {
|
||||
it('matches an object', function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an array", function() {
|
||||
it('matches an array', function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
|
||||
expect(anything.asymmetricMatch([1, 2, 3])).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Map", function() {
|
||||
it('matches a Map', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
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() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
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() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
|
||||
it('matches a TypedArray', function() {
|
||||
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() {
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
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() {
|
||||
@@ -71,6 +69,6 @@ describe("Anything", function() {
|
||||
it("jasmineToString's itself", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.jasmineToString()).toEqual("<jasmine.anything>");
|
||||
expect(anything.jasmineToString()).toEqual('<jasmine.anything>');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,58 +1,74 @@
|
||||
describe("ArrayContaining", function() {
|
||||
it("matches any actual to an empty array", function() {
|
||||
describe('ArrayContaining', function() {
|
||||
it('matches any actual to an empty array', function() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining([]);
|
||||
|
||||
expect(containing.asymmetricMatch("foo")).toBe(true);
|
||||
expect(containing.asymmetricMatch('foo')).toBe(true);
|
||||
});
|
||||
|
||||
it("does not work when not passed an array", function() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining("foo");
|
||||
it('does not work when not passed an array', function() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining('foo');
|
||||
|
||||
expect(function() {
|
||||
containing.asymmetricMatch([]);
|
||||
}).toThrowError(/not 'foo'/);
|
||||
});
|
||||
|
||||
it("matches when the item is in the actual", function() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
it('matches when the item is in the actual', function() {
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
it('matches when additional items are in the actual', function() {
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
it('does not match when the item is not in the actual', function() {
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
it('does not match when the actual is not an array', function() {
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining([]);
|
||||
it('jasmineToStrings itself', function() {
|
||||
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() {
|
||||
var tester = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
if (
|
||||
typeof a == 'string' &&
|
||||
typeof b == 'string' &&
|
||||
a.substr(0, 3) == 'foo' &&
|
||||
b.substr(0, 3) == 'foo'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
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,47 +1,64 @@
|
||||
describe("ArrayWithExactContents", function() {
|
||||
it("matches an array with the same items in a different order", function() {
|
||||
describe('ArrayWithExactContents', function() {
|
||||
it('matches an array with the same items in a different order', function() {
|
||||
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() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents("foo");
|
||||
it('does not work when not passed an array', function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents('foo');
|
||||
|
||||
expect(function() {
|
||||
matcher.asymmetricMatch([]);
|
||||
}).toThrowError(/not 'foo'/);
|
||||
});
|
||||
|
||||
it("does not match when an item is missing", function() {
|
||||
it('does not match when an item is missing', function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
||||
expect(matcher.asymmetricMatch(['a', 2, undefined])).toBe(false);
|
||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("does not match when there is an extra item", function() {
|
||||
it('does not match when there is an extra item', function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToStrings itself", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents([]);
|
||||
it('jasmineToStrings itself', function() {
|
||||
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() {
|
||||
var tester = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
if (
|
||||
typeof a == 'string' &&
|
||||
typeof b == 'string' &&
|
||||
a.substr(0, 3) == 'foo' &&
|
||||
b.substr(0, 3) == 'foo'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,51 +1,50 @@
|
||||
describe("Empty", function () {
|
||||
it("matches an empty object", function () {
|
||||
describe('Empty', function() {
|
||||
it('matches an empty object', function() {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch({})).toBe(true);
|
||||
expect(empty.asymmetricMatch({undefined: false})).toBe(false);
|
||||
expect(empty.asymmetricMatch({ undefined: false })).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty array", function () {
|
||||
it('matches an empty array', function() {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch([])).toBe(true);
|
||||
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty string", function () {
|
||||
it('matches an empty string', function() {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch("")).toBe(true);
|
||||
expect(empty.asymmetricMatch('')).toBe(true);
|
||||
expect(empty.asymmetricMatch('')).toBe(true);
|
||||
expect(empty.asymmetricMatch('12312')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty map", function () {
|
||||
it('matches an empty map', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
var fullMap = new Map();
|
||||
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||
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);
|
||||
});
|
||||
|
||||
it("matches an empty set", function () {
|
||||
it('matches an empty set', function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
var fullSet = new Set();
|
||||
var fullSet = new Set(); // eslint-disable-line compat/compat
|
||||
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);
|
||||
});
|
||||
|
||||
it("matches an empty typed array", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
it('matches an empty typed array', function() {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
|
||||
expect(empty.asymmetricMatch(new Int16Array([1,2]))).toBe(false);
|
||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(empty.asymmetricMatch(new Int16Array([1, 2]))).toBe(false); // eslint-disable-line compat/compat
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
describe("Falsy", function() {
|
||||
it("is true for an empty string", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy();
|
||||
describe('Falsy', function() {
|
||||
it('is true for an empty string', function() {
|
||||
var falsy = new jasmineUnderTest.Falsy();
|
||||
|
||||
expect(falsy.asymmetricMatch("")).toBe(true);
|
||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||
expect(falsy.asymmetricMatch('asdasdad')).toBe(false);
|
||||
});
|
||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||
expect(falsy.asymmetricMatch('asdasdad')).toBe(false);
|
||||
});
|
||||
|
||||
it("is false for a number that is 0", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Number);
|
||||
it('is false for a number that is 0', function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Number);
|
||||
|
||||
expect(falsy.asymmetricMatch(1)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(0)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(-23)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(-3.1)).toBe(false);
|
||||
});
|
||||
expect(falsy.asymmetricMatch(1)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(0)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(-23)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(-3.1)).toBe(false);
|
||||
});
|
||||
|
||||
it("is true for a null or undefined", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Function);
|
||||
it('is true for a null or undefined', function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Function);
|
||||
|
||||
expect(falsy.asymmetricMatch(null)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(undefined )).toBe(true);
|
||||
});
|
||||
expect(falsy.asymmetricMatch(null)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for NaN", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Object);
|
||||
it('is true for NaN', function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Object);
|
||||
|
||||
expect(falsy.asymmetricMatch(NaN)).toBe(true);
|
||||
});
|
||||
expect(falsy.asymmetricMatch(NaN)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a false Boolean", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Boolean);
|
||||
it('is true for a false Boolean', function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Boolean);
|
||||
|
||||
expect(falsy.asymmetricMatch(false)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(true)).toBe(false);
|
||||
});
|
||||
expect(falsy.asymmetricMatch(false)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(true)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('MapContaining', function() {
|
||||
function MapI(iterable) { // for IE11
|
||||
function MapI(iterable) {
|
||||
// for IE11
|
||||
var map = new Map();
|
||||
iterable.forEach(function(kv) {
|
||||
map.set(kv[0], kv[1]);
|
||||
@@ -11,7 +13,6 @@ describe('MapContaining', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
});
|
||||
|
||||
|
||||
it('matches any actual map to an empty map', function() {
|
||||
var actualMap = new MapI([['foo', 'bar']]);
|
||||
var containing = new jasmineUnderTest.MapContaining(new Map());
|
||||
@@ -22,162 +23,149 @@ describe('MapContaining', function() {
|
||||
it('matches when all the key/value pairs in sample have matches in actual', function() {
|
||||
var actualMap = new MapI([
|
||||
['foo', [1, 2, 3]],
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['other', 'any'],
|
||||
[{ foo: 'bar' }, 'baz'],
|
||||
['other', 'any']
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['foo', [1, 2, 3]],
|
||||
]);
|
||||
var containingMap = new MapI([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
|
||||
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() {
|
||||
var actualMap = new MapI([
|
||||
['foo', [1, 2, 3]],
|
||||
[{'foo': 'not a bar'}, 'baz'],
|
||||
[{ foo: 'not a bar' }, 'baz']
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['foo', [1, 2, 3]],
|
||||
]);
|
||||
var containingMap = new MapI([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
|
||||
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() {
|
||||
var actualMap = new MapI([
|
||||
['foo', [1, 2, 3]],
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
]);
|
||||
var actualMap = new MapI([['foo', [1, 2, 3]], [{ foo: 'bar' }, 'baz']]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['foo', [1, 2]],
|
||||
]);
|
||||
var containingMap = new MapI([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2]]]);
|
||||
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() {
|
||||
var actualMap = new MapI([
|
||||
['foo1', 'not a bar'],
|
||||
['foo2', 'bar'],
|
||||
['baz', [1, 2, 3, 4]],
|
||||
['baz', [1, 2, 3, 4]]
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
jasmine.stringMatching(/^foo\d/),
|
||||
'bar'
|
||||
],
|
||||
[
|
||||
'baz',
|
||||
jasmine.arrayContaining([2, 3])
|
||||
],
|
||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||
]);
|
||||
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() {
|
||||
var actualMap = new MapI([
|
||||
['a-foo1', 'bar'],
|
||||
['baz', [1, 2, 3, 4]],
|
||||
]);
|
||||
var actualMap = new MapI([['a-foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
jasmine.stringMatching(/^foo\d/),
|
||||
'bar'
|
||||
],
|
||||
[
|
||||
'baz',
|
||||
jasmine.arrayContaining([2, 3])
|
||||
],
|
||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||
]);
|
||||
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() {
|
||||
var actualMap = new MapI([
|
||||
['foo1', 'bar'],
|
||||
['baz', [1, 2, 3, 4]],
|
||||
]);
|
||||
var actualMap = new MapI([['foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
jasmine.stringMatching(/^foo\d/),
|
||||
'bar'
|
||||
],
|
||||
[
|
||||
'baz',
|
||||
jasmine.arrayContaining([4, 5])
|
||||
],
|
||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||
['baz', jasmineUnderTest.arrayContaining([4, 5])]
|
||||
]);
|
||||
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() {
|
||||
var actualMap = new MapI([
|
||||
['foo', new MapI([['foo1', 1], ['foo2', 2]])],
|
||||
[new MapI([[1, 'bar1'], [2, 'bar2']]), 'bar'],
|
||||
['other', 'any'],
|
||||
['other', 'any']
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
'foo',
|
||||
new jasmineUnderTest.MapContaining(new MapI([['foo1', 1]]))
|
||||
],
|
||||
[
|
||||
new jasmineUnderTest.MapContaining(new MapI([[2, 'bar2']])),
|
||||
'bar'
|
||||
],
|
||||
['foo', new jasmineUnderTest.MapContaining(new MapI([['foo1', 1]]))],
|
||||
[new jasmineUnderTest.MapContaining(new MapI([[2, 'bar2']])), 'bar']
|
||||
]);
|
||||
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() {
|
||||
function tester(a, b) {
|
||||
// treat all negative numbers as equal
|
||||
return (typeof a == 'number' && typeof b == 'number') ? (a < 0 && b < 0) : a === b;
|
||||
return typeof a == 'number' && typeof b == 'number'
|
||||
? a < 0 && b < 0
|
||||
: a === b;
|
||||
}
|
||||
var actualMap = new MapI([['foo', -1]]);
|
||||
var 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() {
|
||||
var containingMap = new MapI([['foo', 'bar']]);
|
||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')).toBe(false);
|
||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch(-1)).toBe(false);
|
||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch({'foo': 'bar'})).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch(-1)
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch({
|
||||
foo: 'bar'
|
||||
})
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('throws an error when sample is not a map', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.MapContaining({'foo': 'bar'}).asymmetricMatch(new Map());
|
||||
new jasmineUnderTest.MapContaining({ foo: 'bar' }).asymmetricMatch(
|
||||
new Map()
|
||||
);
|
||||
}).toThrowError(/You must provide a map/);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,53 +1,52 @@
|
||||
describe("NotEmpty", function () {
|
||||
it("matches a non empty object", function () {
|
||||
describe('NotEmpty', function() {
|
||||
it('matches a non empty object', function() {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch({undefined: false})).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch({ undefined: false })).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch({})).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty array", function () {
|
||||
it('matches a non empty array', function() {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch([])).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty string", function () {
|
||||
it('matches a non empty string', function() {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch("")).toBe(false);
|
||||
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty map", function () {
|
||||
it('matches a non empty map', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
var fullMap = new Map();
|
||||
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||
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(emptyMap)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty set", function () {
|
||||
it('matches a non empty set', function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
var filledSet = new Set();
|
||||
var filledSet = new Set(); // eslint-disable-line compat/compat
|
||||
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(emptySet)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty typed array", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
it('matches a non empty typed array', function() {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array([1,2,3]))).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false);
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array([1, 2, 3]))).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false); // eslint-disable-line compat/compat
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,75 +1,115 @@
|
||||
describe("ObjectContaining", function() {
|
||||
describe('ObjectContaining', function() {
|
||||
it('matches any object actual to an empty object', function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
it("matches any actual to an empty object", function() {
|
||||
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({});
|
||||
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining("foo");
|
||||
it('does not match an empty object actual', function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining('foo');
|
||||
|
||||
expect(function() {
|
||||
containing.asymmetricMatch({})
|
||||
}).toThrowError(/not 'foo'/)
|
||||
containing.asymmetricMatch({});
|
||||
}).toThrowError(/not 'foo'/);
|
||||
});
|
||||
|
||||
it("matches when the key/value pair is present in the actual", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
||||
it('matches when the key/value pair is present in the actual', function() {
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
||||
it('does not match when the key/value pair is not present in the actual', function() {
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "other"});
|
||||
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 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() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||
var sample = {},
|
||||
matcher = new jasmineUnderTest.ObjectContaining(sample),
|
||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||
|
||||
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
|
||||
expect(matcher.jasmineToString(pp)).toEqual(
|
||||
'<jasmine.objectContaining(sample)>'
|
||||
);
|
||||
expect(pp).toHaveBeenCalledWith(sample);
|
||||
});
|
||||
|
||||
it("matches recursively", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({one: new jasmineUnderTest.ObjectContaining({two: {}})});
|
||||
it('matches recursively', function() {
|
||||
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 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 matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({})).toBe(false);
|
||||
expect(containing.asymmetricMatch({}, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches defined properties", function(){
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
||||
it('matches defined properties', function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
var definedPropertyObject = {};
|
||||
Object.defineProperty(definedPropertyObject, "foo", {
|
||||
get: function() { return "fooVal" }
|
||||
Object.defineProperty(definedPropertyObject, 'foo', {
|
||||
get: function() {
|
||||
return 'fooVal';
|
||||
}
|
||||
});
|
||||
expect(containing.asymmetricMatch(definedPropertyObject)).toBe(true);
|
||||
expect(
|
||||
containing.asymmetricMatch(definedPropertyObject, matchersUtil)
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("matches prototype properties", function(){
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
||||
it('matches prototype properties', function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
var prototypeObject = {foo: "fooVal"};
|
||||
var prototypeObject = { foo: 'fooVal' };
|
||||
var obj;
|
||||
|
||||
if (Object.create) {
|
||||
@@ -81,19 +121,96 @@ describe("ObjectContaining", function() {
|
||||
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() {
|
||||
var tester = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
if (
|
||||
typeof a == 'string' &&
|
||||
typeof b == 'string' &&
|
||||
a.substr(0, 3) == 'foo' &&
|
||||
b.substr(0, 3) == 'foo'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
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,5 +1,7 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('SetContaining', function() {
|
||||
function SetI(iterable) { // for IE11
|
||||
function SetI(iterable) {
|
||||
// for IE11
|
||||
var set = new Set();
|
||||
iterable.forEach(function(v) {
|
||||
set.add(v);
|
||||
@@ -11,7 +13,6 @@ describe('SetContaining', function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
});
|
||||
|
||||
|
||||
it('matches any actual set to an empty set', function() {
|
||||
var actualSet = new SetI(['foo', 'bar']);
|
||||
var containing = new jasmineUnderTest.SetContaining(new Set());
|
||||
@@ -20,99 +21,109 @@ describe('SetContaining', function() {
|
||||
});
|
||||
|
||||
it('matches when all the values in sample have matches in actual', function() {
|
||||
var actualSet = new SetI([
|
||||
{'foo': 'bar'}, 'baz', [1, 2, 3]
|
||||
]);
|
||||
var actualSet = new SetI([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||
|
||||
var containingSet = new SetI([
|
||||
[1, 2, 3], {'foo': 'bar'}
|
||||
]);
|
||||
var containingSet = new SetI([[1, 2, 3], { foo: 'bar' }]);
|
||||
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() {
|
||||
var actualSet = new SetI([
|
||||
{'foo': 'bar'}, 'baz', [1, 2, 3]
|
||||
]);
|
||||
var actualSet = new SetI([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||
|
||||
var containingSet = new SetI([
|
||||
[1, 2], {'foo': 'bar'}
|
||||
]);
|
||||
var containingSet = new SetI([[1, 2], { foo: 'bar' }]);
|
||||
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() {
|
||||
var actualSet = new SetI([
|
||||
[1, 2, 3, 4], 'other', 'foo1'
|
||||
]);
|
||||
var actualSet = new SetI([[1, 2, 3, 4], 'other', 'foo1']);
|
||||
|
||||
var containingSet = new SetI([
|
||||
jasmine.stringMatching(/^foo\d/),
|
||||
jasmine.arrayContaining([2, 3]),
|
||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||
jasmineUnderTest.arrayContaining([2, 3])
|
||||
]);
|
||||
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() {
|
||||
var actualSet = new SetI([
|
||||
'a-foo1', [1, 2, 3, 4], 'other'
|
||||
]);
|
||||
var actualSet = new SetI(['a-foo1', [1, 2, 3, 4], 'other']);
|
||||
|
||||
var containingSet = new SetI([
|
||||
jasmine.stringMatching(/^foo\d/),
|
||||
jasmine.arrayContaining([2, 3]),
|
||||
jasmine.arrayContaining([2, 3])
|
||||
]);
|
||||
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() {
|
||||
var actualSet = new SetI([
|
||||
'foo', new SetI([1, 'bar', 2]), 'other'
|
||||
]);
|
||||
var actualSet = new SetI(['foo', new SetI([1, 'bar', 2]), 'other']);
|
||||
|
||||
var containingSet = new SetI([
|
||||
new jasmineUnderTest.SetContaining(new SetI(['bar'])), 'foo'
|
||||
new jasmineUnderTest.SetContaining(new SetI(['bar'])),
|
||||
'foo'
|
||||
]);
|
||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet)).toBe(true);
|
||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it('uses custom equality testers', function() {
|
||||
function tester(a, b) {
|
||||
// treat all negative numbers as equal
|
||||
return (typeof a == 'number' && typeof b == 'number') ? (a < 0 && b < 0) : a === b;
|
||||
return typeof a == 'number' && typeof b == 'number'
|
||||
? a < 0 && b < 0
|
||||
: a === b;
|
||||
}
|
||||
var actualSet = new SetI(['foo', -1]);
|
||||
var 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() {
|
||||
var containingSet = new SetI(['foo']);
|
||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')).toBe(false);
|
||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(1)).toBe(false);
|
||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(['foo'])).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(1)
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(['foo'])
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('throws an error when sample is not a set', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.SetContaining({'foo': 'bar'}).asymmetricMatch(new Set());
|
||||
new jasmineUnderTest.SetContaining({ foo: 'bar' }).asymmetricMatch(
|
||||
new Set()
|
||||
);
|
||||
}).toThrowError(/You must provide a set/);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
27
spec/core/asymmetric_equality/StringContainingSpec.js
Normal file
27
spec/core/asymmetric_equality/StringContainingSpec.js
Normal file
@@ -0,0 +1,27 @@
|
||||
describe('StringContaining', function() {
|
||||
it('searches for a provided substring when the expected is a String', function() {
|
||||
var matcher = new jasmineUnderTest.StringContaining('foo');
|
||||
|
||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||
});
|
||||
|
||||
it('raises an Error when the expected is not a String', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.StringContaining(/foo/);
|
||||
}).toThrowError(/not a String/);
|
||||
});
|
||||
|
||||
it('fails when the actual is not a String', function() {
|
||||
var matcher = new jasmineUnderTest.StringContaining('x');
|
||||
expect(matcher.asymmetricMatch(['x'])).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToString's itself", function() {
|
||||
var matching = new jasmineUnderTest.StringContaining('foo');
|
||||
|
||||
expect(matching.jasmineToString()).toEqual(
|
||||
'<jasmine.stringContaining("foo")>'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,19 @@
|
||||
describe("StringMatching", function() {
|
||||
it("matches a string against a provided regexp", function() {
|
||||
describe('StringMatching', function() {
|
||||
it('matches a string against a provided regexp', function() {
|
||||
var matcher = new jasmineUnderTest.StringMatching(/foo/);
|
||||
|
||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a string against provided string", function() {
|
||||
it('matches a string against provided string', function() {
|
||||
var matcher = new jasmineUnderTest.StringMatching('foo');
|
||||
|
||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||
});
|
||||
|
||||
it("raises an Error when the expected is not a String or RegExp", function() {
|
||||
it('raises an Error when the expected is not a String or RegExp', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.StringMatching({});
|
||||
}).toThrowError(/not a String or a RegExp/);
|
||||
@@ -22,6 +22,8 @@ describe("StringMatching", function() {
|
||||
it("jasmineToString's itself", function() {
|
||||
var matching = new jasmineUnderTest.StringMatching(/^foo/);
|
||||
|
||||
expect(matching.jasmineToString()).toEqual("<jasmine.stringMatching(/^foo/)>");
|
||||
expect(matching.jasmineToString()).toEqual(
|
||||
'<jasmine.stringMatching(/^foo/)>'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
describe("Truthy", function () {
|
||||
it("is true for a non empty string", function () {
|
||||
describe('Truthy', function() {
|
||||
it('is true for a non empty string', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch("foo")).toBe(true);
|
||||
expect(truthy.asymmetricMatch("")).toBe(false);
|
||||
expect(truthy.asymmetricMatch('foo')).toBe(true);
|
||||
expect(truthy.asymmetricMatch('')).toBe(false);
|
||||
});
|
||||
|
||||
it("is true for a number that is not 0", function () {
|
||||
it('is true for a number that is not 0', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(1)).toBe(true);
|
||||
@@ -15,49 +15,47 @@ describe("Truthy", function () {
|
||||
expect(truthy.asymmetricMatch(-3.1)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a function", function () {
|
||||
it('is true for a function', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(function () {
|
||||
})).toBe(true);
|
||||
expect(truthy.asymmetricMatch(function() {})).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for an Object", function () {
|
||||
it('is true for an Object', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a truthful Boolean", function () {
|
||||
it('is true for a truthful Boolean', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(true)).toBe(true);
|
||||
expect(truthy.asymmetricMatch(false)).toBe(false);
|
||||
});
|
||||
|
||||
it("is true for an empty object", function () {
|
||||
it('is true for an empty object', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for an empty array", function () {
|
||||
it('is true for an empty array', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch([])).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a date", function () {
|
||||
it('is true for a date', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(new Date())).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a infiniti", function () {
|
||||
it('is true for a infiniti', function() {
|
||||
var truthy = new jasmineUnderTest.Truthy();
|
||||
|
||||
expect(truthy.asymmetricMatch(Infinity)).toBe(true);
|
||||
expect(truthy.asymmetricMatch(-Infinity)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -29,5 +29,161 @@ describe('base helpers', function() {
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('returns true for an Error subclass', function() {
|
||||
function MyError() {}
|
||||
MyError.prototype = new Error();
|
||||
expect(jasmineUnderTest.isError_(new MyError())).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for an un-thrown Error with no message in this environment', function() {
|
||||
expect(jasmineUnderTest.isError_(new Error())).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for an Error that originated from another frame', function() {
|
||||
var iframe, error;
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
pending('This test only runs in browsers.');
|
||||
}
|
||||
|
||||
iframe = document.createElement('iframe');
|
||||
iframe.style.display = 'none';
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
try {
|
||||
error = iframe.contentWindow.eval('new Error()');
|
||||
expect(jasmineUnderTest.isError_(error)).toBe(true);
|
||||
} finally {
|
||||
document.body.removeChild(iframe);
|
||||
}
|
||||
});
|
||||
|
||||
it('returns false for a falsy value', function() {
|
||||
expect(jasmineUnderTest.isError_(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for a non-Error object', function() {
|
||||
expect(jasmineUnderTest.isError_({})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isURL', function() {
|
||||
it('returns true when the object is a URL', function() {
|
||||
jasmine.getEnv().requireUrls();
|
||||
// eslint-disable-next-line compat/compat
|
||||
expect(jasmineUnderTest.isURL(new URL('http://localhost/'))).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false when the object is not a URL', function() {
|
||||
jasmine.getEnv().requireUrls();
|
||||
expect(jasmineUnderTest.isURL({})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPending_', function() {
|
||||
it('returns a promise that resolves to true when the promise is pending', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
// eslint-disable-next-line compat/compat
|
||||
var promise = new Promise(function() {});
|
||||
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it('returns a promise that resolves to false when the promise is resolved', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
// eslint-disable-next-line compat/compat
|
||||
var promise = Promise.resolve();
|
||||
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it('returns a promise that resolves to false when the promise is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
// eslint-disable-next-line compat/compat
|
||||
var promise = Promise.reject();
|
||||
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
||||
false
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DEFAULT_TIMEOUT_INTERVAL setter', function() {
|
||||
var max = 2147483647;
|
||||
|
||||
beforeEach(function() {
|
||||
this.initialValue = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = this.initialValue;
|
||||
});
|
||||
|
||||
it('accepts only values <= ' + max, function() {
|
||||
expect(function() {
|
||||
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = max + 1;
|
||||
}).toThrowError(
|
||||
'jasmine.DEFAULT_TIMEOUT_INTERVAL cannot be greater than ' + max
|
||||
);
|
||||
|
||||
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = max;
|
||||
expect(jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL).toEqual(max);
|
||||
});
|
||||
|
||||
it('is consistent with setTimeout in this environment', function(done) {
|
||||
var f1 = jasmine.createSpy('setTimeout callback for ' + max),
|
||||
f2 = jasmine.createSpy('setTimeout callback for ' + (max + 1)),
|
||||
id;
|
||||
|
||||
// Suppress printing of TimeoutOverflowWarning in node
|
||||
spyOn(console, 'error');
|
||||
|
||||
id = setTimeout(f1, max);
|
||||
setTimeout(function() {
|
||||
clearTimeout(id);
|
||||
expect(f1).not.toHaveBeenCalled();
|
||||
|
||||
id = setTimeout(f2, max + 1);
|
||||
setTimeout(function() {
|
||||
clearTimeout(id);
|
||||
expect(f2).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
253
spec/core/integration/AsymmetricEqualityTestersSpec.js
Normal file
253
spec/core/integration/AsymmetricEqualityTestersSpec.js
Normal file
@@ -0,0 +1,253 @@
|
||||
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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
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('stringContaining', function() {
|
||||
verifyPasses(function(env) {
|
||||
env.expect('foo').toEqual(jasmineUnderTest.stringContaining('o'));
|
||||
});
|
||||
|
||||
verifyFails(function(env) {
|
||||
env.expect('bar').toEqual(jasmineUnderTest.stringContaining('o'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('truthy', function() {
|
||||
verifyPasses(function(env) {
|
||||
env.expect(true).toEqual(jasmineUnderTest.truthy());
|
||||
});
|
||||
|
||||
verifyFails(function(env) {
|
||||
env.expect(false).toEqual(jasmineUnderTest.truthy());
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,14 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('Custom Async Matchers (Integration)', function() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.configure({random: false});
|
||||
env.configure({ random: false });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
it('passes the spec if the custom async matcher passes', function(done) {
|
||||
@@ -12,7 +17,11 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.it('spec using custom async matcher', function() {
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: function() { return Promise.resolve({ pass: true }); } };
|
||||
return {
|
||||
compare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -23,8 +32,8 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
||||
@@ -34,8 +43,12 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.addAsyncMatchers({
|
||||
toBeReal: function() {
|
||||
return {
|
||||
compare: function() { return Promise.resolve({ pass: true }); },
|
||||
negativeCompare: function() { return Promise.resolve({ pass: true }); }
|
||||
compare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
},
|
||||
negativeCompare: function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -47,8 +60,8 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
|
||||
@@ -69,10 +82,86 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
|
||||
expect(result.failedExpectations[0].message).toEqual(
|
||||
"Expected 'a' to be real."
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
// 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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,48 +1,65 @@
|
||||
describe("Custom Matchers (Integration)", function() {
|
||||
describe('Custom Matchers (Integration)', function() {
|
||||
var env;
|
||||
var fakeTimer;
|
||||
|
||||
beforeEach(function() {
|
||||
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.cleanup_();
|
||||
});
|
||||
|
||||
it('allows adding more matchers local to a spec', function(done) {
|
||||
env.it('spec defining a custom matcher', function() {
|
||||
env.addMatchers({
|
||||
matcherForSpec: function() {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
return { pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected };
|
||||
return {
|
||||
pass: false,
|
||||
message:
|
||||
'matcherForSpec: actual: ' +
|
||||
actual +
|
||||
'; expected: ' +
|
||||
expected
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
env.expect("zzz").matcherForSpec("yyy");
|
||||
env.expect('zzz').matcherForSpec('yyy');
|
||||
});
|
||||
|
||||
env.it("spec without custom matcher defined", function() {
|
||||
expect(env.expect("zzz").matcherForSpec).toBeUndefined();
|
||||
env.it('spec without custom matcher defined', function() {
|
||||
expect(env.expect('zzz').matcherForSpec).toBeUndefined();
|
||||
});
|
||||
|
||||
var specDoneSpy = jasmine.createSpy("specDoneSpy");
|
||||
var specDoneSpy = jasmine.createSpy('specDoneSpy');
|
||||
var expectations = function() {
|
||||
var firstSpecResult = specDoneSpy.calls.first().args[0];
|
||||
expect(firstSpecResult.status).toEqual("failed");
|
||||
expect(firstSpecResult.failedExpectations[0].message).toEqual("matcherForSpec: actual: zzz; expected: yyy");
|
||||
expect(firstSpecResult.status).toEqual('failed');
|
||||
expect(firstSpecResult.failedExpectations[0].message).toEqual(
|
||||
'matcherForSpec: actual: zzz; expected: yyy'
|
||||
);
|
||||
done();
|
||||
};
|
||||
env.addReporter({ specDone:specDoneSpy, jasmineDone: expectations});
|
||||
env.addReporter({ specDone: specDoneSpy });
|
||||
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
it("passes the spec if the custom matcher passes", function(done) {
|
||||
env.it("spec using custom matcher", function() {
|
||||
it('passes the spec if the custom matcher passes', function(done) {
|
||||
env.it('spec using custom matcher', function() {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: function() { return { pass: true }; } };
|
||||
return {
|
||||
compare: function() {
|
||||
return { pass: true };
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,36 +70,80 @@ describe("Custom Matchers (Integration)", function() {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it("passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers", function(done) {
|
||||
env.it("spec using custom equality matcher", function() {
|
||||
it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', function(done) {
|
||||
env.it('spec using custom equality matcher', function() {
|
||||
var customEqualityFn = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
if (
|
||||
typeof a == 'string' &&
|
||||
typeof b == 'string' &&
|
||||
a.substr(0, 3) == 'foo' &&
|
||||
b.substr(0, 3) == 'foo'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.expect({foo: 'fooValue'}).toEqual(jasmineUnderTest.objectContaining({foo: 'fooBar'}));
|
||||
env.expect(['fooValue', 'things']).toEqual(jasmineUnderTest.arrayContaining(['fooBar']));
|
||||
env.expect(['fooValue']).toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
||||
env
|
||||
.expect({ foo: 'fooValue' })
|
||||
.toEqual(jasmineUnderTest.objectContaining({ foo: 'fooBar' }));
|
||||
env
|
||||
.expect(['fooValue', 'things'])
|
||||
.toEqual(jasmineUnderTest.arrayContaining(['fooBar']));
|
||||
env
|
||||
.expect(['fooValue'])
|
||||
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it("displays an appropriate failure message if a custom equality matcher fails", function(done) {
|
||||
env.it("spec using custom equality matcher", function() {
|
||||
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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('displays an appropriate failure message if a custom equality matcher fails', function(done) {
|
||||
env.it('spec using custom equality matcher', function() {
|
||||
var customEqualityFn = function(a, b) {
|
||||
// "foo" is not equal to anything
|
||||
if (a === 'foo' || b === 'foo') {
|
||||
@@ -91,7 +152,7 @@ describe("Custom Matchers (Integration)", function() {
|
||||
};
|
||||
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.expect({foo: 'foo'}).toEqual({foo: 'foo'});
|
||||
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
@@ -101,17 +162,21 @@ describe("Custom Matchers (Integration)", function() {
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it("uses the negative compare function for a negative comparison, if provided", function(done) {
|
||||
env.it("spec with custom negative comparison matcher", function() {
|
||||
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
||||
env.it('spec with custom negative comparison matcher', function() {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return {
|
||||
compare: function() { return { pass: true }; },
|
||||
negativeCompare: function() { return { pass: true }; }
|
||||
compare: function() {
|
||||
return { pass: true };
|
||||
},
|
||||
negativeCompare: function() {
|
||||
return { pass: true };
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -123,11 +188,11 @@ describe("Custom Matchers (Integration)", function() {
|
||||
expect(result.status).toEqual('passed');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
|
||||
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
|
||||
env.it('spec with an expectation', function() {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
@@ -135,25 +200,29 @@ describe("Custom Matchers (Integration)", function() {
|
||||
compare: function() {
|
||||
return { pass: false };
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
env.expect("a").toBeReal();
|
||||
env.expect('a').toBeReal();
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
|
||||
expect(result.failedExpectations[0].message).toEqual(
|
||||
"Expected 'a' to be real."
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it("passes the expected and actual arguments to the comparison function", function(done) {
|
||||
var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
|
||||
it('passes the expected and actual arguments to the comparison function', function(done) {
|
||||
var argumentSpy = jasmine
|
||||
.createSpy('argument spy')
|
||||
.and.returnValue({ pass: true });
|
||||
|
||||
env.it('spec with an expectation', function () {
|
||||
env.it('spec with an expectation', function() {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: argumentSpy };
|
||||
@@ -161,40 +230,85 @@ describe("Custom Matchers (Integration)", function() {
|
||||
});
|
||||
|
||||
env.expect(true).toBeReal();
|
||||
env.expect(true).toBeReal("arg");
|
||||
env.expect(true).toBeReal("arg1", "arg2");
|
||||
env.expect(true).toBeReal('arg');
|
||||
env.expect(true).toBeReal('arg1', 'arg2');
|
||||
});
|
||||
|
||||
var specExpectations = function() {
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true);
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, "arg");
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, "arg1", "arg2");
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) {
|
||||
var matcherFactory = function() { return { compare: function() { return {pass: true}; }}; },
|
||||
argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
|
||||
customEqualityFn = function() { return true; };
|
||||
// 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 };
|
||||
}
|
||||
};
|
||||
},
|
||||
matcherFactorySpy = jasmine
|
||||
.createSpy('matcherFactorySpy')
|
||||
.and.callFake(matcherFactory),
|
||||
customEqualityFn = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
env.it("spec with expectation", function() {
|
||||
env.it('spec with expectation', function() {
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.addMatchers({
|
||||
toBeReal: argumentSpy
|
||||
toBeReal: matcherFactorySpy
|
||||
});
|
||||
|
||||
env.expect(true).toBeReal();
|
||||
});
|
||||
|
||||
var specExpectations = function() {
|
||||
expect(argumentSpy).toHaveBeenCalledWith(jasmineUnderTest.matchersUtil, [customEqualityFn]);
|
||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.MatchersUtil),
|
||||
[customEqualityFn]
|
||||
);
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
});
|
||||
|
||||
81
spec/core/integration/CustomObjectFormatterSpec.js
Normal file
81
spec/core/integration/CustomObjectFormatterSpec.js
Normal file
@@ -0,0 +1,81 @@
|
||||
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 });
|
||||
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
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.beforeAll(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 });
|
||||
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
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'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -3,14 +3,17 @@ describe('Custom Spy Strategies (Integration)', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.configure({random: false});
|
||||
env.configure({ random: false });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
it('allows adding more strategies local to a suite', function(done) {
|
||||
var plan = jasmine.createSpy('custom strategy plan')
|
||||
.and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue(plan);
|
||||
var plan = jasmine.createSpy('custom strategy plan').and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy').and.returnValue(plan);
|
||||
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||
|
||||
env.describe('suite defining a custom spy strategy', function() {
|
||||
env.beforeEach(function() {
|
||||
@@ -29,20 +32,20 @@ describe('Custom Spy Strategies (Integration)', function() {
|
||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
function expectations() {
|
||||
var result = jasmineDone.calls.argsFor(0)[0];
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
it('allows adding more strategies local to a spec', function(done) {
|
||||
var plan = jasmine.createSpy('custom strategy plan')
|
||||
.and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue(plan);
|
||||
var plan = jasmine.createSpy('custom strategy plan').and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy').and.returnValue(plan);
|
||||
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||
|
||||
env.it('spec defining a custom spy strategy', function() {
|
||||
env.addSpyStrategy('frobnicate', strategy);
|
||||
@@ -56,26 +59,28 @@ describe('Custom Spy Strategies (Integration)', function() {
|
||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
function expectations() {
|
||||
var result = jasmineDone.calls.argsFor(0)[0];
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
it('allows using custom strategies on a per-argument basis', function(done) {
|
||||
var plan = jasmine.createSpy('custom strategy plan')
|
||||
.and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue(plan);
|
||||
var plan = jasmine.createSpy('custom strategy plan').and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy').and.returnValue(plan);
|
||||
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||
|
||||
env.it('spec defining a custom spy strategy', function() {
|
||||
env.addSpyStrategy('frobnicate', strategy);
|
||||
var spy = env.createSpy('something')
|
||||
var spy = env
|
||||
.createSpy('something')
|
||||
.and.returnValue('no args return')
|
||||
.withArgs(1, 2, 3).and.frobnicate(17);
|
||||
.withArgs(1, 2, 3)
|
||||
.and.frobnicate(17);
|
||||
|
||||
expect(spy()).toEqual('no args return');
|
||||
expect(plan).not.toHaveBeenCalled();
|
||||
@@ -87,13 +92,14 @@ describe('Custom Spy Strategies (Integration)', function() {
|
||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
function expectations() {
|
||||
var result = jasmineDone.calls.argsFor(0)[0];
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
it('allows multiple custom strategies to be used', function(done) {
|
||||
@@ -101,7 +107,8 @@ describe('Custom Spy Strategies (Integration)', function() {
|
||||
strategy1 = jasmine.createSpy('strat 1').and.returnValue(plan1),
|
||||
plan2 = jasmine.createSpy('plan 2').and.returnValue(24),
|
||||
strategy2 = jasmine.createSpy('strat 2').and.returnValue(plan2),
|
||||
specDone = jasmine.createSpy('specDone');
|
||||
specDone = jasmine.createSpy('specDone'),
|
||||
jasmineDone = jasmine.createSpy('jasmineDone');
|
||||
|
||||
env.beforeEach(function() {
|
||||
env.addSpyStrategy('frobnicate', strategy1);
|
||||
@@ -126,13 +133,14 @@ describe('Custom Spy Strategies (Integration)', function() {
|
||||
expect(plan2).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
function expectations() {
|
||||
var result = jasmineDone.calls.argsFor(0)[0];
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
expect(specDone.calls.count()).toBe(2);
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone, specDone: specDone });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,13 +3,17 @@ describe('Default Spy Strategy (Integration)', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.configure({random: false});
|
||||
env.configure({ random: false });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
it('allows defining a default spy strategy', function(done) {
|
||||
env.describe('suite with default strategy', function() {
|
||||
env.beforeEach(function() {
|
||||
env.setDefaultSpyStrategy(function (and) {
|
||||
env.setDefaultSpyStrategy(function(and) {
|
||||
and.returnValue(42);
|
||||
});
|
||||
});
|
||||
@@ -25,21 +29,27 @@ describe('Default Spy Strategy (Integration)', function() {
|
||||
expect(spy()).toBeUndefined();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
function expectations() {
|
||||
var result = jasmineDone.calls.argsFor(0)[0];
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
it('uses the default spy strategy defined when the spy is created', function (done) {
|
||||
it('uses the default spy strategy defined when the spy is created', function(done) {
|
||||
env.it('spec', function() {
|
||||
var a = env.createSpy('a');
|
||||
env.setDefaultSpyStrategy(function (and) { and.returnValue(42); });
|
||||
env.setDefaultSpyStrategy(function(and) {
|
||||
and.returnValue(42);
|
||||
});
|
||||
var b = env.createSpy('b');
|
||||
env.setDefaultSpyStrategy(function (and) { and.stub(); });
|
||||
env.setDefaultSpyStrategy(function(and) {
|
||||
and.stub();
|
||||
});
|
||||
var c = env.createSpy('c');
|
||||
env.setDefaultSpyStrategy();
|
||||
var d = env.createSpy('d');
|
||||
@@ -57,12 +67,14 @@ describe('Default Spy Strategy (Integration)', function() {
|
||||
expect(d.and.isConfigured()).toBe(false);
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
function expectations() {
|
||||
var result = jasmineDone.calls.argsFor(0)[0];
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
var jasmineDone = jasmine.createSpy('jasmineDone');
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,16 @@
|
||||
describe('Matchers (Integration)', function() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
function verifyPasses(expectations) {
|
||||
it('passes', function(done) {
|
||||
var env = new jasmineUnderTest.Env();
|
||||
env.it('a spec', function() {
|
||||
expectations(env);
|
||||
});
|
||||
@@ -14,19 +23,20 @@ describe('Matchers (Integration)', function() {
|
||||
expect(result.failedExpectations.length)
|
||||
.withContext('Number of failed expectations')
|
||||
.toEqual(0);
|
||||
expect(result.failedExpectations[0] && result.failedExpectations[0].message)
|
||||
expect(
|
||||
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||
)
|
||||
.withContext('Failure message')
|
||||
.toBeUndefined();
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
function verifyFails(expectations) {
|
||||
it('fails', function(done) {
|
||||
var env = new jasmineUnderTest.Env();
|
||||
env.it('a spec', function() {
|
||||
expectations(env);
|
||||
});
|
||||
@@ -37,21 +47,50 @@ describe('Matchers (Integration)', function() {
|
||||
.withContext('Number of failed expectations')
|
||||
.toEqual(1);
|
||||
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: /);
|
||||
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
||||
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')
|
||||
.not.toEqual('');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
function verifyPassesAsync(expectations) {
|
||||
it('passes', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
var env = new jasmineUnderTest.Env();
|
||||
|
||||
env.it('a spec', function() {
|
||||
return expectations(env);
|
||||
@@ -65,19 +104,20 @@ describe('Matchers (Integration)', function() {
|
||||
expect(result.failedExpectations.length)
|
||||
.withContext('Number of failed expectations')
|
||||
.toEqual(0);
|
||||
expect(result.failedExpectations[0] && result.failedExpectations[0].message)
|
||||
expect(
|
||||
result.failedExpectations[0] && result.failedExpectations[0].message
|
||||
)
|
||||
.withContext('Failure message')
|
||||
.toBeUndefined();
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
function verifyFailsAsync(expectations) {
|
||||
it('fails', function(done) {
|
||||
var env = new jasmineUnderTest.Env();
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
env.it('a spec', function() {
|
||||
@@ -90,14 +130,41 @@ describe('Matchers (Integration)', function() {
|
||||
.withContext('Number of failed expectations')
|
||||
.toEqual(1);
|
||||
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: /);
|
||||
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
|
||||
expect(result.failedExpectations[0].matcherName)
|
||||
.withContext('Matcher name')
|
||||
.not.toEqual('');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations, jasmineDone: done });
|
||||
env.execute();
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
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 });
|
||||
env.execute(null, done);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,6 +284,16 @@ describe('Matchers (Integration)', function() {
|
||||
verifyFails(function(env) {
|
||||
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() {
|
||||
@@ -227,6 +304,16 @@ describe('Matchers (Integration)', function() {
|
||||
verifyFails(function(env) {
|
||||
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() {
|
||||
@@ -247,56 +334,129 @@ describe('Matchers (Integration)', function() {
|
||||
verifyFails(function(env) {
|
||||
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() {
|
||||
verifyPassesAsync(function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve()).toBeResolved();
|
||||
});
|
||||
|
||||
verifyFailsAsync(function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.reject()).toBeResolved();
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBeResolvedTo', function() {
|
||||
verifyPassesAsync(function(env) {
|
||||
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('foo');
|
||||
env.addCustomEqualityTester(function(a, b) {
|
||||
return a.toString() === b.toString();
|
||||
});
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve('5')).toBeResolvedTo(5);
|
||||
});
|
||||
|
||||
verifyFailsAsync(function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('bar');
|
||||
});
|
||||
|
||||
verifyFailsWithCustomObjectFormattersAsync({
|
||||
formatter: function(val) {
|
||||
return '|' + val + '|';
|
||||
},
|
||||
expectations: function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve('x')).toBeResolvedTo('y');
|
||||
},
|
||||
expectedMessage:
|
||||
'Expected a promise to be resolved to |y| ' +
|
||||
'but it was resolved to |x|.'
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBeRejected', function() {
|
||||
verifyPassesAsync(function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.reject('nope')).toBeRejected();
|
||||
});
|
||||
|
||||
verifyFailsAsync(function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve()).toBeRejected();
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBeRejectedWith', function() {
|
||||
verifyPassesAsync(function(env) {
|
||||
return env.expectAsync(Promise.reject('nope')).toBeRejectedWith('nope');
|
||||
env.addCustomEqualityTester(function(a, b) {
|
||||
return a.toString() === b.toString();
|
||||
});
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.reject('5')).toBeRejectedWith(5);
|
||||
});
|
||||
|
||||
verifyFailsAsync(function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve()).toBeRejectedWith('nope');
|
||||
});
|
||||
|
||||
verifyFailsWithCustomObjectFormattersAsync({
|
||||
formatter: function(val) {
|
||||
return '|' + val + '|';
|
||||
},
|
||||
expectations: function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.reject('x')).toBeRejectedWith('y');
|
||||
},
|
||||
expectedMessage:
|
||||
'Expected a promise to be rejected with |y| ' +
|
||||
'but it was rejected with |x|.'
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBeRejectedWithError', function() {
|
||||
verifyPassesAsync(function(env) {
|
||||
return env.expectAsync(Promise.reject(new Error())).toBeRejectedWithError(Error);
|
||||
return (
|
||||
env
|
||||
// eslint-disable-next-line compat/compat
|
||||
.expectAsync(Promise.reject(new Error()))
|
||||
.toBeRejectedWithError(Error)
|
||||
);
|
||||
});
|
||||
|
||||
verifyFailsAsync(function(env) {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error);
|
||||
});
|
||||
|
||||
verifyFailsWithCustomObjectFormattersAsync({
|
||||
formatter: function(val) {
|
||||
return '|' + val + '|';
|
||||
},
|
||||
expectations: function(env) {
|
||||
return (
|
||||
env
|
||||
// eslint-disable-next-line compat/compat
|
||||
.expectAsync(Promise.reject('foo'))
|
||||
.toBeRejectedWithError('foo')
|
||||
);
|
||||
},
|
||||
expectedMessage:
|
||||
'Expected a promise to be rejected with Error: |foo| ' +
|
||||
'but it was rejected with |foo|.'
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBeTrue', function() {
|
||||
@@ -331,7 +491,10 @@ describe('Matchers (Integration)', function() {
|
||||
|
||||
describe('toContain', function() {
|
||||
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) {
|
||||
@@ -341,12 +504,39 @@ describe('Matchers (Integration)', function() {
|
||||
|
||||
describe('toEqual', function() {
|
||||
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) {
|
||||
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() {
|
||||
@@ -364,14 +554,16 @@ describe('Matchers (Integration)', function() {
|
||||
|
||||
describe('toHaveBeenCalledBefore', function() {
|
||||
verifyPasses(function(env) {
|
||||
var a = env.createSpy('a'), b = env.createSpy('b');
|
||||
var a = env.createSpy('a'),
|
||||
b = env.createSpy('b');
|
||||
a();
|
||||
b();
|
||||
env.expect(a).toHaveBeenCalledBefore(b);
|
||||
});
|
||||
|
||||
verifyFails(function(env) {
|
||||
var a = env.createSpy('a'), b = env.createSpy('b');
|
||||
var a = env.createSpy('a'),
|
||||
b = env.createSpy('b');
|
||||
b();
|
||||
a();
|
||||
env.expect(a).toHaveBeenCalledBefore(b);
|
||||
@@ -394,14 +586,47 @@ describe('Matchers (Integration)', function() {
|
||||
describe('toHaveBeenCalledWith', function() {
|
||||
verifyPasses(function(env) {
|
||||
var spy = env.createSpy();
|
||||
spy('foo');
|
||||
env.expect(spy).toHaveBeenCalledWith('foo');
|
||||
spy('5');
|
||||
env.addCustomEqualityTester(function(a, b) {
|
||||
return a.toString() === b.toString();
|
||||
});
|
||||
env.expect(spy).toHaveBeenCalledWith(5);
|
||||
});
|
||||
|
||||
verifyFails(function(env) {
|
||||
var spy = env.createSpy();
|
||||
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() {
|
||||
@@ -434,21 +659,62 @@ describe('Matchers (Integration)', function() {
|
||||
|
||||
describe('toThrow', function() {
|
||||
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) {
|
||||
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() {
|
||||
verifyPasses(function(env) {
|
||||
env.expect(function() { throw new Error(); }).toThrowError();
|
||||
env
|
||||
.expect(function() {
|
||||
throw new Error();
|
||||
})
|
||||
.toThrowError();
|
||||
});
|
||||
|
||||
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|.'
|
||||
});
|
||||
});
|
||||
|
||||
@@ -458,11 +724,119 @@ describe('Matchers (Integration)', function() {
|
||||
}
|
||||
|
||||
verifyPasses(function(env) {
|
||||
env.expect(throws).toThrowMatching(function() { return true; });
|
||||
env.expect(throws).toThrowMatching(function() {
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
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|.'
|
||||
});
|
||||
});
|
||||
|
||||
describe('When an async matcher is used with .already()', function() {
|
||||
it('propagates the matcher result when the promise is resolved', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
env.it('a spec', function() {
|
||||
// eslint-disable-next-line compat/compat
|
||||
return env.expectAsync(Promise.resolve()).already.toBeRejected();
|
||||
});
|
||||
|
||||
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(
|
||||
'Expected [object Promise] to be rejected.'
|
||||
);
|
||||
expect(result.failedExpectations[0].matcherName)
|
||||
.withContext('Matcher name')
|
||||
.not.toEqual('');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('propagates the matcher result when the promise is rejected', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
env.it('a spec', function() {
|
||||
return (
|
||||
env
|
||||
// eslint-disable-next-line compat/compat
|
||||
.expectAsync(Promise.reject(new Error('nope')))
|
||||
.already.toBeResolved()
|
||||
);
|
||||
});
|
||||
|
||||
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(
|
||||
'Expected a promise to be resolved but it was ' +
|
||||
'rejected with Error: nope.'
|
||||
);
|
||||
expect(result.failedExpectations[0].matcherName)
|
||||
.withContext('Matcher name')
|
||||
.not.toEqual('');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('fails when the promise is pending', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
// eslint-disable-next-line compat/compat
|
||||
var promise = new Promise(function() {});
|
||||
|
||||
env.it('a spec', function() {
|
||||
return env.expectAsync(promise).already.toBeResolved();
|
||||
});
|
||||
|
||||
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(
|
||||
'Expected a promise to be settled ' +
|
||||
'(via expectAsync(...).already) but it was pending.'
|
||||
);
|
||||
expect(result.failedExpectations[0].matcherName)
|
||||
.withContext('Matcher name')
|
||||
.not.toEqual('');
|
||||
};
|
||||
|
||||
env.addReporter({ specDone: specExpectations });
|
||||
env.execute(null, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,47 +1,213 @@
|
||||
describe("DiffBuilder", function() {
|
||||
it("records the actual and expected objects", function() {
|
||||
describe('DiffBuilder', function() {
|
||||
it('records the actual and expected objects', function() {
|
||||
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();
|
||||
diffBuilder.setRoots({ foo: { x: 'actual' } }, { foo: { x: 'expected' } });
|
||||
|
||||
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();
|
||||
diffBuilder.setRoots({ foo: 1, bar: 3 }, { foo: 2, bar: 4 });
|
||||
|
||||
diffBuilder.withPath('foo', function() {
|
||||
diffBuilder.record(1, 2);
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
diffBuilder.withPath('bar', function() {
|
||||
diffBuilder.recordMismatch();
|
||||
});
|
||||
|
||||
var message =
|
||||
"Expected $.foo = 1 to equal 2.\n" +
|
||||
"Expected 3 to equal 4.";
|
||||
'Expected $.foo = 1 to equal 2.\n' + 'Expected $.bar = 3 to equal 4.';
|
||||
|
||||
diffBuilder.record(3, 4);
|
||||
expect(diffBuilder.getMessage()).toEqual(message);
|
||||
});
|
||||
|
||||
it("allows customization of the message", function() {
|
||||
it('allows customization of the message', function() {
|
||||
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
||||
diffBuilder.setRoots({ x: 'bar' }, { x: 'foo' });
|
||||
|
||||
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.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);
|
||||
});
|
||||
});
|
||||
|
||||
142
spec/core/matchers/MismatchTreeSpec.js
Normal file
142
spec/core/matchers/MismatchTreeSpec.js
Normal file
@@ -0,0 +1,142 @@
|
||||
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() {}
|
||||
});
|
||||
@@ -4,10 +4,4 @@ describe('NullDiffBuilder', function() {
|
||||
jasmineUnderTest.NullDiffBuilder().withPath('does not matter', spy);
|
||||
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(root.toString()).toEqual('');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
50
spec/core/matchers/async/toBePendingSpec.js
Normal file
50
spec/core/matchers/async/toBePendingSpec.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/* 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,36 +1,38 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('toBeRejected', function() {
|
||||
it('passes if the actual is rejected', function() {
|
||||
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');
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if the actual is resolved', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||
actual = Promise.resolve();
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejected(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejected(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
return matcher.compare(actual);
|
||||
}
|
||||
|
||||
expect(f).toThrowError(
|
||||
'Expected toBeRejected to be called on a promise.'
|
||||
);
|
||||
expect(f).toThrowError('Expected toBeRejected to be called on a promise.');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,161 +1,253 @@
|
||||
describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error type matches', function () {
|
||||
/* eslint-disable compat/compat */
|
||||
describe('#toBeRejectedWithError', function() {
|
||||
it('passes when Error type matches', function() {
|
||||
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'));
|
||||
|
||||
return matcher.compare(actual, TypeError).then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with TypeError, but it was.'
|
||||
}));
|
||||
return matcher.compare(actual, TypeError).then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message:
|
||||
'Expected a promise not to be rejected with TypeError, but it was.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('passes when Error type and message matches', function () {
|
||||
it('passes when Error type and message matches', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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'));
|
||||
|
||||
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with TypeError: \'foo\', but it was.'
|
||||
}));
|
||||
return matcher.compare(actual, TypeError, 'foo').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message:
|
||||
"Expected a promise not to be rejected with TypeError: 'foo', but it was."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('passes when Error matches and is exactly Error', function() {
|
||||
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());
|
||||
|
||||
return matcher.compare(actual, Error).then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with Error, but it was.'
|
||||
}));
|
||||
return matcher.compare(actual, Error).then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message:
|
||||
'Expected a promise not to be rejected with Error, but it was.'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('passes when Error message matches a string', function () {
|
||||
it('passes when Error message matches a string', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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'));
|
||||
|
||||
return matcher.compare(actual, 'foo').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with Error: \'foo\', but it was.'
|
||||
}));
|
||||
return matcher.compare(actual, 'foo').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message:
|
||||
"Expected a promise not to be rejected with Error: 'foo', but it was."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('passes when Error message matches a RegExp', function () {
|
||||
it('passes when Error message matches a RegExp', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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'));
|
||||
|
||||
return matcher.compare(actual, /foo/).then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with Error: /foo/, but it was.'
|
||||
}));
|
||||
return matcher.compare(actual, /foo/).then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message:
|
||||
'Expected a promise not to be rejected with Error: /foo/, but it was.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('passes when Error message is empty', function () {
|
||||
it('passes when Error message is empty', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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());
|
||||
|
||||
return matcher.compare(actual, '').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with Error: \'\', but it was.'
|
||||
}));
|
||||
return matcher.compare(actual, '').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message:
|
||||
"Expected a promise not to be rejected with Error: '', but it was."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('passes when no arguments', function () {
|
||||
it('passes when no arguments', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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());
|
||||
|
||||
return matcher.compare(actual, void 0).then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with Error, but it was.'
|
||||
}));
|
||||
return matcher.compare(actual, void 0).then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message:
|
||||
'Expected a promise not to be rejected with Error, but it was.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails when resolved', function () {
|
||||
it('fails when resolved', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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'));
|
||||
|
||||
return matcher.compare(actual, 'foo').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: 'Expected a promise to be rejected but it was resolved.'
|
||||
}));
|
||||
return matcher.compare(actual, 'foo').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: 'Expected a promise to be rejected but it was resolved.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails when rejected with non Error type', function () {
|
||||
it('fails when rejected with non Error type', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||
matchersUtil
|
||||
),
|
||||
actual = Promise.reject('foo');
|
||||
|
||||
return matcher.compare(actual, 'foo').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: 'Expected a promise to be rejected with Error: \'foo\' but it was rejected with \'foo\'.'
|
||||
}));
|
||||
return matcher.compare(actual, 'foo').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message:
|
||||
"Expected a promise to be rejected with Error: 'foo' but it was rejected with 'foo'."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails when Error type mismatches', function () {
|
||||
it('fails when Error type mismatches', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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'));
|
||||
|
||||
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: 'Expected a promise to be rejected with TypeError: \'foo\' but it was rejected with type Error.'
|
||||
}));
|
||||
return matcher.compare(actual, TypeError, 'foo').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message:
|
||||
"Expected a promise to be rejected with TypeError: 'foo' but it was rejected with type Error."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails when Error message mismatches', function () {
|
||||
it('fails when Error message mismatches', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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'));
|
||||
|
||||
return matcher.compare(actual, 'bar').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: 'Expected a promise to be rejected with Error: \'bar\' but it was rejected with Error: foo.'
|
||||
}));
|
||||
return matcher.compare(actual, 'bar').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message:
|
||||
"Expected a promise to be rejected with Error: 'bar' but it was rejected with Error: foo."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(
|
||||
matchersUtil
|
||||
),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
@@ -1,68 +1,92 @@
|
||||
describe('#toBeRejectedWith', function () {
|
||||
it('should return true if the promise is rejected with the expected value', function () {
|
||||
/* eslint-disable compat/compat */
|
||||
describe('#toBeRejectedWith', function() {
|
||||
it('should return true if the promise is rejected with the expected value', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
actual = Promise.reject({error: 'PEBCAK'});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject({ error: 'PEBCAK' });
|
||||
|
||||
return matcher.compare(actual, {error: 'PEBCAK'}).then(function (result) {
|
||||
return matcher.compare(actual, { error: 'PEBCAK' }).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if the promise resolves', function () {
|
||||
it('should fail if the promise resolves', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.resolve();
|
||||
|
||||
return matcher.compare(actual, '').then(function (result) {
|
||||
return matcher.compare(actual, '').then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if the promise is rejected with a different value', function () {
|
||||
it('should fail if the promise is rejected with a different value', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
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');
|
||||
|
||||
return matcher.compare(actual, 'Some Cool Thing').then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: "Expected a promise to be rejected with 'Some Cool Thing' but it was rejected with 'A Bad Apple'.",
|
||||
}));
|
||||
return matcher.compare(actual, 'Some Cool Thing').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message:
|
||||
"Expected a promise to be rejected with 'Some Cool Thing' but it was rejected with 'A Bad Apple'."
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should build its error correctly when negated', function () {
|
||||
it('should build its error correctly when negated', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject(true);
|
||||
|
||||
return matcher.compare(actual, true).then(function (result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with true.'
|
||||
}));
|
||||
return matcher.compare(actual, true).then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be rejected with true.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support custom equality testers', function () {
|
||||
it('should support custom equality testers', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var customEqualityTesters = [function() { return true; }],
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil, customEqualityTesters),
|
||||
var customEqualityTesters = [
|
||||
function() {
|
||||
return true;
|
||||
}
|
||||
],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: customEqualityTesters
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject('actual');
|
||||
|
||||
return matcher.compare(actual, 'expected').then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
@@ -1,36 +1,45 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('toBeResolved', function() {
|
||||
it('passes if the actual is resolved', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||
actual = Promise.resolve();
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if the actual is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolved(jasmineUnderTest.matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter([])
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||
actual = Promise.reject(new Error('AsyncExpectationSpec rejection'));
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({pass: false}));
|
||||
expect(result).toEqual({
|
||||
pass: false,
|
||||
message:
|
||||
'Expected a promise to be resolved but it was rejected ' +
|
||||
'with Error: AsyncExpectationSpec rejection.'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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';
|
||||
|
||||
function f() {
|
||||
return matcher.compare(actual);
|
||||
}
|
||||
|
||||
expect(f).toThrowError(
|
||||
'Expected toBeResolved to be called on a promise.'
|
||||
);
|
||||
expect(f).toThrowError('Expected toBeResolved to be called on a promise.');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,71 +1,102 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('#toBeResolvedTo', function() {
|
||||
it('passes if the promise is resolved to the expected value', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
actual = Promise.resolve({foo: 42});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve({ foo: 42 });
|
||||
|
||||
return matcher.compare(actual, {foo: 42}).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
||||
return matcher.compare(actual, { foo: 42 }).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if the promise is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec error');
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.reject(new Error('AsyncExpectationSpec error'));
|
||||
|
||||
return matcher.compare(actual, '').then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: "Expected a promise to be resolved to '' but it was rejected.",
|
||||
}));
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message:
|
||||
"Expected a promise to be resolved to '' but it was rejected " +
|
||||
'with Error: AsyncExpectationSpec error.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if the promise is resolved to a different value', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
actual = Promise.resolve({foo: 17});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve({ foo: 17 });
|
||||
|
||||
return matcher.compare(actual, {foo: 42}).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: false,
|
||||
message: 'Expected a promise to be resolved to Object({ foo: 42 }) but it was resolved to Object({ foo: 17 }).',
|
||||
}));
|
||||
return matcher.compare(actual, { foo: 42 }).then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message:
|
||||
'Expected a promise to be resolved to Object({ foo: 42 }) but it was resolved to Object({ foo: 17 }).'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('builds its message correctly when negated', function() {
|
||||
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);
|
||||
|
||||
return matcher.compare(actual, true).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be resolved to true.'
|
||||
}));
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: true,
|
||||
message: 'Expected a promise not to be resolved to true.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('supports custom equality testers', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var customEqualityTesters = [function() { return true; }],
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil, customEqualityTesters),
|
||||
var customEqualityTesters = [
|
||||
function() {
|
||||
return true;
|
||||
}
|
||||
],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: customEqualityTesters,
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve('actual');
|
||||
|
||||
return matcher.compare(actual, 'expected').then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({pass: true}));
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
|
||||
});
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(jasmineUnderTest.matchersUtil),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
function f() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
describe("toBeCloseTo", function() {
|
||||
it("passes when within two decimal places by default", function() {
|
||||
describe('toBeCloseTo', function() {
|
||||
it('passes when within two decimal places by default', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||
result;
|
||||
|
||||
@@ -13,7 +13,7 @@ describe("toBeCloseTo", function() {
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when not within two decimal places by default", function() {
|
||||
it('fails when not within two decimal places by default', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||
result;
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("toBeCloseTo", function() {
|
||||
expect(result.pass).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts an optional precision argument", function() {
|
||||
it('accepts an optional precision argument', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||
result;
|
||||
|
||||
@@ -47,23 +47,29 @@ describe("toBeCloseTo", function() {
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when one of the arguments is null", function() {
|
||||
it('fails when one of the arguments is null', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo();
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(null, null);
|
||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(null).');
|
||||
}).toThrowError(
|
||||
'Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(null).'
|
||||
);
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(0, null);
|
||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(0).toBeCloseTo(null).');
|
||||
}).toThrowError(
|
||||
'Cannot use toBeCloseTo with null. Arguments evaluated to: expect(0).toBeCloseTo(null).'
|
||||
);
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(null, 0);
|
||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(0).');
|
||||
}).toThrowError(
|
||||
'Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(0).'
|
||||
);
|
||||
});
|
||||
|
||||
it("rounds expected values", function() {
|
||||
it('rounds expected values', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||
result;
|
||||
|
||||
@@ -91,15 +97,15 @@ describe("toBeCloseTo", function() {
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("handles edge cases with rounding", function () {
|
||||
it('handles edge cases with rounding', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
|
||||
result;
|
||||
|
||||
// these cases resulted in false negatives in version of V8
|
||||
// these cases resulted in false negatives in version of V8
|
||||
// included in Node.js 12 and Chrome 74 (and Edge Chromium)
|
||||
result = matcher.compare(4.030904708957288, 4.0309, 5);
|
||||
expect(result.pass).toBe(true);
|
||||
result = matcher.compare(4.82665525779431,4.82666, 5);
|
||||
result = matcher.compare(4.82665525779431, 4.82666, 5);
|
||||
expect(result.pass).toBe(true);
|
||||
result = matcher.compare(-2.82665525779431, -2.82666, 5);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
describe("toBeDefined", function() {
|
||||
it("matches for defined values", function() {
|
||||
describe('toBeDefined', function() {
|
||||
it('matches for defined values', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeDefined(),
|
||||
result;
|
||||
|
||||
|
||||
result = matcher.compare('foo');
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when matching undefined values", function() {
|
||||
it('fails when matching undefined values', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeDefined(),
|
||||
result;
|
||||
|
||||
result = matcher.compare(void 0);
|
||||
expect(result.pass).toBe(false);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe("toBeFalse", function() {
|
||||
it("passes for false", function() {
|
||||
describe('toBeFalse', function() {
|
||||
it('passes for false', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
||||
result;
|
||||
|
||||
@@ -7,7 +7,7 @@ describe("toBeFalse", function() {
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for non-false", function() {
|
||||
it('fails for non-false', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
||||
result;
|
||||
|
||||
@@ -15,7 +15,7 @@ describe("toBeFalse", function() {
|
||||
expect(result.pass).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for falsy", function() {
|
||||
it('fails for falsy', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeFalse(),
|
||||
result;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
describe("toBeFalsy", function() {
|
||||
describe('toBeFalsy', function() {
|
||||
it("passes for 'falsy' values", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeFalsy(),
|
||||
result;
|
||||
@@ -15,6 +15,9 @@ describe("toBeFalsy", function() {
|
||||
result = matcher.compare(null);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(undefined);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(void 0);
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
@@ -29,10 +32,16 @@ describe("toBeFalsy", function() {
|
||||
result = matcher.compare(1);
|
||||
expect(result.pass).toBe(false);
|
||||
|
||||
result = matcher.compare("foo");
|
||||
result = matcher.compare('foo');
|
||||
expect(result.pass).toBe(false);
|
||||
|
||||
result = matcher.compare({});
|
||||
expect(result.pass).toBe(false);
|
||||
|
||||
result = matcher.compare([]);
|
||||
expect(result.pass).toBe(false);
|
||||
|
||||
result = matcher.compare(function() {});
|
||||
expect(result.pass).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user