Compare commits
214 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d06dce4614 | ||
|
|
03098e81f8 | ||
|
|
726c152f6e | ||
|
|
409d2e29e5 | ||
|
|
01e2bd5050 | ||
|
|
96033e38ea | ||
|
|
ed75290ef7 | ||
|
|
a14dbf012a | ||
|
|
17c11ba7b9 | ||
|
|
2a1daca1ca | ||
|
|
f0db5ce350 | ||
|
|
39f9c2e1a0 | ||
|
|
bff612a169 | ||
|
|
4ba42f3746 | ||
|
|
58bee05c36 | ||
|
|
c1871b0f0c | ||
|
|
c16974b091 | ||
|
|
bfedda9764 | ||
|
|
a67b7276be | ||
|
|
47f3105ef0 | ||
|
|
aeb56539c9 | ||
|
|
75d45efa16 | ||
|
|
59d1c5bebb | ||
|
|
040983c979 | ||
|
|
2ddb344bac | ||
|
|
e56bd3918b | ||
|
|
59600a1c29 | ||
|
|
f8e4ea868f | ||
|
|
0ff56c53b1 | ||
|
|
b617d983de | ||
|
|
8e0f0e8e8c | ||
|
|
d745d6b5f0 | ||
|
|
fc2c2a477d | ||
|
|
ff93277c0f | ||
|
|
90741b3cee | ||
|
|
d1de59f0ed | ||
|
|
73f8e001ad | ||
|
|
390cc45af2 | ||
|
|
33118ac6e2 | ||
|
|
31ff9a300c | ||
|
|
5cc739d879 | ||
|
|
1e7f07259e | ||
|
|
c36a5cfd96 | ||
|
|
299fd1f770 | ||
|
|
656427d328 | ||
|
|
621522fdd4 | ||
|
|
6e3589bf52 | ||
|
|
df2d9b282e | ||
|
|
726d35c5c5 | ||
|
|
f509078020 | ||
|
|
8308515210 | ||
|
|
ed838b3cbf | ||
|
|
04fac300e8 | ||
|
|
ff237f4b66 | ||
|
|
e42e3d9e00 | ||
|
|
61505f4c59 | ||
|
|
86eddb05b4 | ||
|
|
8af5509581 | ||
|
|
166e5f4d6c | ||
|
|
6ad8d20694 | ||
|
|
cbc03feb52 | ||
|
|
bc3a495160 | ||
|
|
b323631611 | ||
|
|
e8767ba660 | ||
|
|
af9a4114f4 | ||
|
|
75f97961f5 | ||
|
|
25a7168286 | ||
|
|
494e81f436 | ||
|
|
169a2a8ad2 | ||
|
|
b267029301 | ||
|
|
cf574634b8 | ||
|
|
f8c01574e6 | ||
|
|
481f1e7c5c | ||
|
|
5e650953cd | ||
|
|
ed5e902106 | ||
|
|
87f9ab29df | ||
|
|
47c64a86d5 | ||
|
|
bb497beeff | ||
|
|
e14d9c4be3 | ||
|
|
89e0b35c53 | ||
|
|
1e7b68236b | ||
|
|
394068f863 | ||
|
|
b831e81074 | ||
|
|
4c13c2b00b | ||
|
|
dd98a45003 | ||
|
|
fe6762b470 | ||
|
|
fa16b74500 | ||
|
|
4cd190b232 | ||
|
|
6ada55ff77 | ||
|
|
735ce6f758 | ||
|
|
430324885b | ||
|
|
7c2e8ce7ca | ||
|
|
d4025999b7 | ||
|
|
871111424d | ||
|
|
44f331f43d | ||
|
|
213144413f | ||
|
|
2272f9aead | ||
|
|
59848ca151 | ||
|
|
c14bfe3e5f | ||
|
|
26c48ab324 | ||
|
|
4c8d57e14c | ||
|
|
543689e206 | ||
|
|
ee524831f4 | ||
|
|
cfecab9f79 | ||
|
|
b3d9435dbb | ||
|
|
fec8dd37b0 | ||
|
|
0690500a0d | ||
|
|
0bfbda720d | ||
|
|
4fcdbd39fb | ||
|
|
f934e6d816 | ||
|
|
79c6bbc189 | ||
|
|
2e80ec0c22 | ||
|
|
588283cfe5 | ||
|
|
3a43871901 | ||
|
|
fcbab02b2d | ||
|
|
5f3475342e | ||
|
|
e022e6199c | ||
|
|
140c12e8fc | ||
|
|
21f25972bb | ||
|
|
d0e1bd96fb | ||
|
|
6c56ebc984 | ||
|
|
d0a9931ae6 | ||
|
|
93c5f654d9 | ||
|
|
d8b65028a1 | ||
|
|
d6cdc1841c | ||
|
|
72b39220e5 | ||
|
|
55dce7d119 | ||
|
|
789736dd02 | ||
|
|
c7ca3b0101 | ||
|
|
96000220b1 | ||
|
|
e2e2275d41 | ||
|
|
135ff20123 | ||
|
|
4af86f5398 | ||
|
|
e5e0e6481d | ||
|
|
bcf69b86b4 | ||
|
|
a5f79fac81 | ||
|
|
18a00822c5 | ||
|
|
4cc8437f79 | ||
|
|
8e58305b0a | ||
|
|
bd368aceee | ||
|
|
8f16021887 | ||
|
|
bbb1b69b2e | ||
|
|
9ea8a2096f | ||
|
|
66340e2b19 | ||
|
|
fe29dfa89c | ||
|
|
41f7fabe2f | ||
|
|
856a040a2d | ||
|
|
f7eaa5ec29 | ||
|
|
0c87d47318 | ||
|
|
c24b2f5a73 | ||
|
|
774c83a36e | ||
|
|
751cf6ab5b | ||
|
|
2fd76c954c | ||
|
|
bb4d18f959 | ||
|
|
68eaa64c31 | ||
|
|
81f6eb45ea | ||
|
|
841b212c66 | ||
|
|
9a27407d35 | ||
|
|
468e9577cd | ||
|
|
9d80377fe3 | ||
|
|
270344bd38 | ||
|
|
dfa94c70c1 | ||
|
|
694375e4ea | ||
|
|
1166d10e43 | ||
|
|
482dc883eb | ||
|
|
364cf35474 | ||
|
|
2e8732f30f | ||
|
|
04133264e0 | ||
|
|
d2bf6062cb | ||
|
|
fb639d0f55 | ||
|
|
52b1a3a7f8 | ||
|
|
1f7880ee8c | ||
|
|
a6e1aef8d7 | ||
|
|
d2815982ce | ||
|
|
aa979277fb | ||
|
|
1e0c312f9f | ||
|
|
c5db939886 | ||
|
|
e470fb56d7 | ||
|
|
a8a6577cd7 | ||
|
|
1660015c12 | ||
|
|
faf210ab4c | ||
|
|
00fd4a819f | ||
|
|
091cd8c3b6 | ||
|
|
aba0c98eb9 | ||
|
|
a7eff79db0 | ||
|
|
2a5673e6ab | ||
|
|
c13dd26c4b | ||
|
|
2e8b477489 | ||
|
|
b2c2e08641 | ||
|
|
d7d75abc42 | ||
|
|
0b71d0a2a0 | ||
|
|
dfa5b6a53d | ||
|
|
7f75f23e5b | ||
|
|
502cb24bb8 | ||
|
|
0ae234dc6e | ||
|
|
38d102f1d1 | ||
|
|
906f37fe52 | ||
|
|
4a2b10998a | ||
|
|
d8b2efe4d6 | ||
|
|
9d9e8f0c17 | ||
|
|
4059ab7ba6 | ||
|
|
7b01003d0b | ||
|
|
8e85f3df74 | ||
|
|
b0034797fe | ||
|
|
83e9f88952 | ||
|
|
de13b47809 | ||
|
|
9e10743a1c | ||
|
|
5327157832 | ||
|
|
6e3128c792 | ||
|
|
bd2e877f4e | ||
|
|
5b23ffe174 | ||
|
|
384e0859c7 | ||
|
|
616682e487 | ||
|
|
3234d475cd |
@@ -3,25 +3,14 @@
|
|||||||
|
|
||||||
version: 2.1
|
version: 2.1
|
||||||
|
|
||||||
orbs:
|
|
||||||
node: circleci/node@3.0.0
|
|
||||||
|
|
||||||
executors:
|
executors:
|
||||||
node16:
|
node20:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/node:16.1.0-browsers
|
- image: cimg/node:20.0.0
|
||||||
working_directory: ~/workspace
|
working_directory: ~/workspace
|
||||||
node14:
|
node18:
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/node:14
|
- image: cimg/node:18.0.0
|
||||||
working_directory: ~/workspace
|
|
||||||
node12_latest:
|
|
||||||
docker:
|
|
||||||
- image: circleci/node:12
|
|
||||||
working_directory: ~/workspace
|
|
||||||
node12_17:
|
|
||||||
docker:
|
|
||||||
- image: circleci/node:12.17
|
|
||||||
working_directory: ~/workspace
|
working_directory: ~/workspace
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -58,10 +47,20 @@ jobs:
|
|||||||
name: Run tests
|
name: Run tests
|
||||||
command: npm test
|
command: npm test
|
||||||
|
|
||||||
|
test_parallel: &test_parallel
|
||||||
|
parameters:
|
||||||
|
executor:
|
||||||
|
type: executor
|
||||||
|
executor: << parameters.executor >>
|
||||||
|
steps:
|
||||||
|
- attach_workspace:
|
||||||
|
at: .
|
||||||
|
- run:
|
||||||
|
name: Run tests in parallel
|
||||||
|
command: npx grunt execSpecsInParallel
|
||||||
|
|
||||||
test_browsers: &test_browsers
|
test_browsers: &test_browsers
|
||||||
executor: node14
|
executor: node18
|
||||||
environment:
|
|
||||||
SKIP_JASMINE_BROWSER_FLAKES: "true"
|
|
||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: .
|
at: .
|
||||||
@@ -69,10 +68,10 @@ jobs:
|
|||||||
name: Install Sauce Connect
|
name: Install Sauce Connect
|
||||||
command: |
|
command: |
|
||||||
cd /tmp
|
cd /tmp
|
||||||
curl https://saucelabs.com/downloads/sc-4.6.4-linux.tar.gz | tar zxf -
|
curl https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz | tar zxf -
|
||||||
chmod +x sc-4.6.4-linux/bin/sc
|
chmod +x sc-4.7.1-linux/bin/sc
|
||||||
mkdir ~/workspace/bin
|
mkdir ~/workspace/bin
|
||||||
cp sc-4.6.4-linux/bin/sc ~/workspace/bin
|
cp sc-4.7.1-linux/bin/sc ~/workspace/bin
|
||||||
~/workspace/bin/sc --version
|
~/workspace/bin/sc --version
|
||||||
- run:
|
- run:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
@@ -81,7 +80,7 @@ jobs:
|
|||||||
# cleanly if we kill it from a different step than it started in.
|
# cleanly if we kill it from a different step than it started in.
|
||||||
|
|
||||||
export PATH=$PATH:$HOME/workspace/bin
|
export PATH=$PATH:$HOME/workspace/bin
|
||||||
export SAUCE_TUNNEL_IDENTIFIER=$CIRCLE_BUILD_NUM
|
export SAUCE_TUNNEL_IDENTIFIER=$CIRCLE_WORKFLOW_JOB_ID
|
||||||
scripts/start-sauce-connect sauce-pidfile
|
scripts/start-sauce-connect sauce-pidfile
|
||||||
set +o errexit
|
set +o errexit
|
||||||
scripts/run-all-browsers
|
scripts/run-all-browsers
|
||||||
@@ -90,116 +89,40 @@ jobs:
|
|||||||
scripts/stop-sauce-connect $(cat sauce-pidfile)
|
scripts/stop-sauce-connect $(cat sauce-pidfile)
|
||||||
exit $exitcode
|
exit $exitcode
|
||||||
|
|
||||||
test_browser_flakes:
|
|
||||||
<<: *test_browsers
|
|
||||||
environment:
|
|
||||||
SKIP_JASMINE_BROWSER_FLAKES: "false"
|
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
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_latest
|
|
||||||
name: build_node_12_latest
|
|
||||||
- build:
|
|
||||||
executor: node12_17
|
|
||||||
name: build_node_12_17
|
|
||||||
- test_node:
|
|
||||||
executor: node16
|
|
||||||
name: test_node_16
|
|
||||||
requires:
|
|
||||||
- build_node_16
|
|
||||||
- test_node:
|
|
||||||
executor: node12_latest
|
|
||||||
name: test_node_12_latest
|
|
||||||
requires:
|
|
||||||
- build_node_12_latest
|
|
||||||
- test_node:
|
|
||||||
executor: node12_17
|
|
||||||
name: test_node_12_17
|
|
||||||
requires:
|
|
||||||
- build_node_12_17
|
|
||||||
- test_browsers:
|
|
||||||
requires:
|
|
||||||
- build_node_14
|
|
||||||
filters:
|
|
||||||
branches:
|
|
||||||
ignore: /pull\/.*/ # Don't run on pull requests.
|
|
||||||
|
|
||||||
push:
|
push:
|
||||||
jobs:
|
jobs:
|
||||||
- build:
|
- build:
|
||||||
executor: node16
|
executor: node20
|
||||||
name: build_node_16
|
name: build_node_20
|
||||||
- build:
|
- build:
|
||||||
executor: node14
|
executor: node18
|
||||||
name: build_node_14
|
name: build_node_18
|
||||||
- build:
|
|
||||||
executor: node12_latest
|
|
||||||
name: build_node_12_latest
|
|
||||||
- build:
|
|
||||||
executor: node12_17
|
|
||||||
name: build_node_12_17
|
|
||||||
- test_node:
|
- test_node:
|
||||||
executor: node16
|
executor: node20
|
||||||
name: test_node_16
|
name: test_node_20
|
||||||
requires:
|
requires:
|
||||||
- build_node_16
|
- build_node_20
|
||||||
- test_node:
|
- test_node:
|
||||||
executor: node14
|
executor: node18
|
||||||
name: test_node_14
|
name: test_node_18
|
||||||
requires:
|
requires:
|
||||||
- build_node_14
|
- build_node_18
|
||||||
- test_node:
|
- test_parallel:
|
||||||
executor: node12_latest
|
executor: node18
|
||||||
name: test_node_12_latest
|
name: test_parallel_node_18
|
||||||
requires:
|
requires:
|
||||||
- build_node_12_latest
|
- build_node_18
|
||||||
- test_node:
|
- test_parallel:
|
||||||
executor: node12_17
|
executor: node20
|
||||||
name: test_node_12_17
|
name: test_parallel_node_20
|
||||||
requires:
|
requires:
|
||||||
- build_node_12_17
|
- build_node_20
|
||||||
- test_browsers:
|
- test_browsers:
|
||||||
requires:
|
requires:
|
||||||
- build_node_14
|
- build_node_18
|
||||||
filters:
|
filters:
|
||||||
branches:
|
branches:
|
||||||
ignore: /pull\/.*/ # Don't run on pull requests.
|
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.
|
|
||||||
|
|||||||
31
.github/CONTRIBUTING.md
vendored
31
.github/CONTRIBUTING.md
vendored
@@ -1,19 +1,10 @@
|
|||||||
# Developing for Jasmine Core
|
# Contributing to Jasmine
|
||||||
|
|
||||||
We welcome your contributions! Thanks for helping make Jasmine a better project
|
We welcome your contributions! Thanks for helping make Jasmine a better project
|
||||||
for everyone. Please review the backlog and discussion lists before starting
|
for everyone. If you want to contribute but don't know what to work on,
|
||||||
work. What you're looking for may already have been done. If it hasn't, the
|
[issues tagged help needed](https://github.com/issues?q=is%3Aopen+is%3Aissue+org%3Ajasmine+label%3A%22help+needed%22+)
|
||||||
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.
|
should have enough detail to get started.
|
||||||
|
|
||||||
## Links
|
|
||||||
|
|
||||||
- [Jasmine Google Group](http://groups.google.com/group/jasmine-js)
|
|
||||||
- [Jasmine-dev Google Group](http://groups.google.com/group/jasmine-js-dev)
|
|
||||||
- [Jasmine backlog](https://www.pivotaltracker.com/n/projects/10606)
|
|
||||||
|
|
||||||
## Before Submitting a Pull Request
|
## Before Submitting a Pull Request
|
||||||
|
|
||||||
1. Ensure all specs are green in browsers *and* node.
|
1. Ensure all specs are green in browsers *and* node.
|
||||||
@@ -94,14 +85,7 @@ Or, How to make a successful pull request
|
|||||||
* _Write specs_ - Jasmine's a testing framework. Don't add functionality
|
* _Write specs_ - Jasmine's a testing framework. Don't add functionality
|
||||||
without test-driving it.
|
without test-driving it.
|
||||||
* _Write code in the style of the rest of the repo_ - Jasmine should look like
|
* _Write code in the style of the rest of the repo_ - Jasmine should look like
|
||||||
a cohesive whole.
|
a cohesive whole.
|
||||||
|
|
||||||
Key exceptions:
|
|
||||||
* Use `const` or `let` for new variable declarations, even if nearby code
|
|
||||||
uses `var`.
|
|
||||||
* New async specs should usually be async/await or promise-returning, not
|
|
||||||
callback based.
|
|
||||||
|
|
||||||
* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and
|
* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and
|
||||||
ESLint/Prettier. Your contribution shouldn't break Jasmine for other users.
|
ESLint/Prettier. Your contribution shouldn't break Jasmine for other users.
|
||||||
|
|
||||||
@@ -119,3 +103,10 @@ chromedriver), you can also use Jasmine's CI tooling:
|
|||||||
|
|
||||||
$ JASMINE_BROWSER=<name of browser> npm run ci
|
$ JASMINE_BROWSER=<name of browser> npm run ci
|
||||||
|
|
||||||
|
### Submitting a Pull Requeset
|
||||||
|
|
||||||
|
Once you've done the steps listed under "Before Submitting a Pull Request"
|
||||||
|
above, you can submit a pull request via the
|
||||||
|
[standard GitHub process](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
|
||||||
|
TL;DR: Fork the repository, push your work up to your fork, and create a PR from
|
||||||
|
there.
|
||||||
|
|||||||
47
.github/ISSUE_TEMPLATE.md
vendored
47
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,47 +0,0 @@
|
|||||||
## Are you creating an issue in the correct repository?
|
|
||||||
|
|
||||||
- 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)
|
|
||||||
- [Karma](https://github.com/karma-runner/karma/issues)
|
|
||||||
- [Grunt Contrib Jasmine](https://github.com/gruntjs/grunt-contrib-jasmine/issues)
|
|
||||||
|
|
||||||
<!--- Provide a general summary of the issue in the Title above -->
|
|
||||||
|
|
||||||
## Expected Behavior
|
|
||||||
<!--- If you're describing a bug, tell us what should happen -->
|
|
||||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
|
||||||
|
|
||||||
## Current Behavior
|
|
||||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
|
||||||
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
|
||||||
|
|
||||||
## Possible Solution
|
|
||||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
|
||||||
<!--- or ideas how to implement the addition or change -->
|
|
||||||
|
|
||||||
## Suite that reproduces the behavior (for bugs)
|
|
||||||
<!--- Provide a sample suite that reproduces the bug. -->
|
|
||||||
```javascript
|
|
||||||
describe("sample", function() {
|
|
||||||
});
|
|
||||||
```
|
|
||||||
## Context
|
|
||||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
|
||||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
|
||||||
|
|
||||||
## Your Environment
|
|
||||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
|
||||||
* Version used:
|
|
||||||
* Environment name and version (e.g. Chrome 39, node.js 5.4):
|
|
||||||
* Operating System and version (desktop or mobile):
|
|
||||||
* Link to your project:
|
|
||||||
98
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
98
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: I think I've found a bug in Jasmine
|
||||||
|
labels: ["bug report"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to report a bug. Please follow these steps first.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
Please take the time to rule out issues with your code or third party libraries before filing a bug report. If you are reporting an error, try to determine whether the error is coming from Jasmine, another library, or your own code.
|
||||||
|
|
||||||
|
Check the [FAQ](https://jasmine.github.io/pages/faq.html) and any other relevant [documentation](https://jasmine.github.io/pages/docs_home.html) to see if your issue has already been addressed.
|
||||||
|
|
||||||
|
## Special troubleshooting steps for asynchronous scenarios
|
||||||
|
If the issue has to do with testing asynchronous code, please read the [async tutorial](https://jasmine.github.io/tutorials/async) and the async section of the FAQ. In particular, check for the following common errors:
|
||||||
|
|
||||||
|
* Are you trying to write a synchronous test for asynchronous code?
|
||||||
|
* Does the test signal completion before the code under test finishes?
|
||||||
|
* Do expectations run before the code that they're trying to verify?
|
||||||
|
|
||||||
|
## Try the latest version of Jasmine
|
||||||
|
If at all possible, upgrade to the latest versions of `jasmine-core` and any other relevant packages (e.g. `jasmine`, `jasmine-browser-runner`). If you can't do that, please check the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes) for all newer versions to make sure that the bug hasn't already been fixed.
|
||||||
|
|
||||||
|
## Put together a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)
|
||||||
|
Please help us help you by creating a minimal but complete setup that demonstrates the problem. Remove any code and libraries that aren't absolutely necessary, but make sure it doesn't depend on any code you haven't included. In many cases a simple code snippet is enough. In cases involving external libraries, *especially* Karma or Angular, we're likely to need a runable Git repository or jsbin/stackblitz/etc.
|
||||||
|
|
||||||
|
**If we can't reproduce it, we can't fix it. Bug reports without a minimal, reproducible example are very likely to be closed.**
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: steps-to-reproduce
|
||||||
|
attributes:
|
||||||
|
label: Steps to Reproduce
|
||||||
|
placeholder: |
|
||||||
|
Example steps:
|
||||||
|
1. Paste the example code below into `mySpec.js`.
|
||||||
|
2. Run `npx jasmine@<some version> mySpec.js`
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: expected-behavior
|
||||||
|
attributes:
|
||||||
|
label: Expected Behavior
|
||||||
|
description: What do you think should have happened?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: actual-behavior
|
||||||
|
attributes:
|
||||||
|
label: Actual Behavior
|
||||||
|
description: What happened instead?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: code-sample
|
||||||
|
attributes:
|
||||||
|
label: Example code that reproduces the problem
|
||||||
|
description: Please include either a code snippet that reproduces the problem or a link to a repository or jsbin/stackblitz/etc containing a minimal, reproducible example as described above.
|
||||||
|
render: JavaScript
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: possible-solution
|
||||||
|
attributes:
|
||||||
|
label: Possible Solution
|
||||||
|
description: This is optional, but if you have an idea for how to fix the bug we'd like to hear it.
|
||||||
|
- type: textarea
|
||||||
|
id: context
|
||||||
|
attributes:
|
||||||
|
label: Context
|
||||||
|
description: How has this issue affected you? What are you trying to accomplish? By providing context, you can help us come up with a solution that is most useful in the real world.
|
||||||
|
- type: input
|
||||||
|
id: jasmine-core-version
|
||||||
|
attributes:
|
||||||
|
label: jasmine-core version
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: other-versions
|
||||||
|
attributes:
|
||||||
|
label: Versions of other relevant packages
|
||||||
|
placeholder: |
|
||||||
|
jasmine-browser-runner 1.2.0
|
||||||
|
fancy-reporter 132.4.8
|
||||||
|
- type: input
|
||||||
|
id: browser-or-node-version
|
||||||
|
attributes:
|
||||||
|
label: Node.js or browser version
|
||||||
|
placeholder: E.g. "node 16.2.0" or "Safari 15"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: os
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
placeholder: E.g. "Windows 10", "MacOS 12.5", "MCC Interim Linux 0.99.p8"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
14
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
14
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Issues with the `jasmine` CLI
|
||||||
|
url: https://github.com/jasmine/jasmine-npm/issues
|
||||||
|
about: Please create issues related to the `jasmine` package in its repository.
|
||||||
|
- name: Issues with jasmine-browser-runner
|
||||||
|
url: https://github.com/jasmine/jasmine-browser-runner/issues
|
||||||
|
about: Please create issues related to the `jasmine-browser-runner` package in its repository.
|
||||||
|
- name: Documentation issues
|
||||||
|
url: https://github.com/jasmine/jasmine.github.io/issues
|
||||||
|
about: Please create documentation issues in the docs repository.
|
||||||
|
- name: TypeScript issues
|
||||||
|
url: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions
|
||||||
|
about: Please create issues related to TypeScript compilation errors or other problems with type definitions at DefinitelyTyped.
|
||||||
31
.github/ISSUE_TEMPLATE/feature_proposal.yml
vendored
Normal file
31
.github/ISSUE_TEMPLATE/feature_proposal.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: Feature Proposal
|
||||||
|
description: I'd like to propose a new feature
|
||||||
|
labels: ["feature request"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: Thanks for taking the time to propose a new feature. Although Jasmine is mostly feature complete, we're always open to hearing new ideas.
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Feature Proposal
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: context
|
||||||
|
attributes:
|
||||||
|
label: Context
|
||||||
|
description: How would this feature be useful to you? What are you trying to accomplish? By providing context, you can help us come up with a solution that is most useful in the real world.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: example
|
||||||
|
attributes:
|
||||||
|
label: Example
|
||||||
|
description: If you're proposing a new API or something similar, please show an example of how it would be used.
|
||||||
|
render: JavaScript
|
||||||
|
- type: textarea
|
||||||
|
id: other-info
|
||||||
|
attributes:
|
||||||
|
label: Other Information
|
||||||
|
description: Anything else that you think would be helpful.
|
||||||
73
.github/ISSUE_TEMPLATE/support_request.yml
vendored
Normal file
73
.github/ISSUE_TEMPLATE/support_request.yml
vendored
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
name: Question or Support Request
|
||||||
|
description: I need help using Jasmine
|
||||||
|
labels: ["question"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Jasmine is supported by volunteers working in their free time. Although we're generally willing to help, we're going to ask you to put in some effort first to help us help you.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
Please take the time to rule out problems with your code or third party libraries before opening an issue. If you're running into an error, try to determine whether the error is coming from Jasmine, another library, or your own code.
|
||||||
|
|
||||||
|
Check the [FAQ](https://jasmine.github.io/pages/faq.html) and any other relevant [documentation](https://jasmine.github.io/pages/docs_home.html) to see if your question has already been answered. Consider searching [Stack Overflow](https://stackoverflow.com/questions/tagged/jasmine) and past issues in this repository for related questions as well.
|
||||||
|
|
||||||
|
## Special troubleshooting steps for asynchronous scenarios
|
||||||
|
If the issue has to do with testing asynchronous code, please read the [async tutorial](https://jasmine.github.io/tutorials/async) and the async section of the FAQ. In particular, check for the following common errors:
|
||||||
|
|
||||||
|
* Are you trying to write a synchronous test for asynchronous code?
|
||||||
|
* Does the test signal completion before the code under test finishes?
|
||||||
|
* Do expectations run before the code that they're trying to verify?
|
||||||
|
|
||||||
|
## Consider asking Angular questions in an Angular forum
|
||||||
|
|
||||||
|
Questions like "how do I test this Angular service" are mostly about Angular, not Jasmine. You'll likely get better responses in an Angular forum. Here's a rule of thumb: If you can't demonstrate the problem without Angular, you probably have an Angular question.
|
||||||
|
|
||||||
|
## Try the latest version of Jasmine
|
||||||
|
If at all possible, upgrade to the latest versions of `jasmine-core` and any other relevant packages (e.g. `jasmine`, `jasmine-browser-runner`).
|
||||||
|
|
||||||
|
## Put together a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)
|
||||||
|
Please help us help you by creating a minimal but complete setup that demonstrates the problem. Remove any code and libraries that aren't absolutely necessary, but make sure it doesn't depend on any code you haven't included. In many cases a simple code snippet is enough. In cases involving external libraries, *especially* Karma or Angular, we're likely to need a runable Git repository or jsbin/stackblitz/etc.
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: question
|
||||||
|
attributes:
|
||||||
|
label: Your question
|
||||||
|
description: Clearly describe what you'd like help with.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: code-sample
|
||||||
|
attributes:
|
||||||
|
label: Example code that demonstrates the problem
|
||||||
|
description: Please include either a code snippet that demonstrates the problem or a link to a repository or jsbin/stackblitz/etc containing a minimal, reproducible example as described above.
|
||||||
|
render: JavaScript
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: jasmine-core-version
|
||||||
|
attributes:
|
||||||
|
label: jasmine-core version
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: other-versions
|
||||||
|
attributes:
|
||||||
|
label: Versions of other relevant packages
|
||||||
|
placeholder: |
|
||||||
|
jasmine-browser-runner 1.2.0
|
||||||
|
fancy-reporter 132.4.8
|
||||||
|
- type: input
|
||||||
|
id: browser-or-node-version
|
||||||
|
attributes:
|
||||||
|
label: Node.js or browser version
|
||||||
|
placeholder: E.g. "node 16.2.0" or "Safari 15"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: os
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
placeholder: E.g. "Windows 10", "MacOS 12.5", "MCC Interim Linux 0.99.p8"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
46
Gruntfile.js
46
Gruntfile.js
@@ -30,9 +30,9 @@ module.exports = function(grunt) {
|
|||||||
function() {
|
function() {
|
||||||
verifyNoGlobals(() => require('./lib/jasmine-core.js').noGlobals());
|
verifyNoGlobals(() => require('./lib/jasmine-core.js').noGlobals());
|
||||||
const done = this.async(),
|
const done = this.async(),
|
||||||
Jasmine = require('jasmine'),
|
Jasmine = require('jasmine'),
|
||||||
jasmineCore = require('./lib/jasmine-core.js'),
|
jasmineCore = require('./lib/jasmine-core.js'),
|
||||||
jasmine = new Jasmine({jasmineCore: jasmineCore});
|
jasmine = new Jasmine({jasmineCore: jasmineCore});
|
||||||
|
|
||||||
jasmine.loadConfigFile('./spec/support/jasmine.json');
|
jasmine.loadConfigFile('./spec/support/jasmine.json');
|
||||||
jasmine.exitOnCompletion = false;
|
jasmine.exitOnCompletion = false;
|
||||||
@@ -40,12 +40,50 @@ module.exports = function(grunt) {
|
|||||||
result => done(result.overallStatus === 'passed'),
|
result => done(result.overallStatus === 'passed'),
|
||||||
err => {
|
err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
exit(1);
|
done(false);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
grunt.registerTask("execSpecsInParallel",
|
||||||
|
"Run Jasmine core specs in parallel in Node.js",
|
||||||
|
function() {
|
||||||
|
// Need to require this here rather than at the top of the file
|
||||||
|
// so that we don't break verifyNoGlobals above by loading jasmine-core
|
||||||
|
// too early
|
||||||
|
const ParallelRunner = require('jasmine/parallel');
|
||||||
|
let numWorkers = require('os').cpus().length;
|
||||||
|
|
||||||
|
if (process.env['CIRCLECI']) {
|
||||||
|
// On Circle CI, the above gives the number of CPU cores on the host
|
||||||
|
// computer, which is unrelated to the resources actually available
|
||||||
|
// to the container. 2 workers gives peak performance with our current
|
||||||
|
// configuration, but 4 might increase the odds of discovering any
|
||||||
|
// parallel-specific bugs.
|
||||||
|
numWorkers = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
const done = this.async();
|
||||||
|
const runner = new ParallelRunner({
|
||||||
|
jasmineCore: require('./lib/jasmine-core.js'),
|
||||||
|
numWorkers
|
||||||
|
});
|
||||||
|
|
||||||
|
runner.loadConfigFile('./spec/support/jasmine.json')
|
||||||
|
.then(() => {
|
||||||
|
runner.exitOnCompletion = false;
|
||||||
|
return runner.execute();
|
||||||
|
}).then(
|
||||||
|
jasmineDoneInfo => done(jasmineDoneInfo.overallStatus === 'passed'),
|
||||||
|
err => {
|
||||||
|
console.error(err);
|
||||||
|
done(false);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
grunt.registerTask("execSpecsInNode:performance",
|
grunt.registerTask("execSpecsInNode:performance",
|
||||||
"Run Jasmine performance specs in Node.js",
|
"Run Jasmine performance specs in Node.js",
|
||||||
function() {
|
function() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
Copyright (c) 2008-2019 Pivotal Labs
|
Copyright (c) 2008-2019 Pivotal Labs
|
||||||
|
Copyright (c) 2008-2023 The Jasmine developers
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
86
README.md
86
README.md
@@ -1,18 +1,10 @@
|
|||||||
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/main/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
|
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/main/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
|
||||||
|
|
||||||
[](https://circleci.com/gh/jasmine/jasmine)
|
|
||||||
[](https://www.codetriage.com/jasmine/jasmine)
|
|
||||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_shield)
|
|
||||||
|
|
||||||
# A JavaScript Testing Framework
|
# A JavaScript Testing Framework
|
||||||
|
|
||||||
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
||||||
|
|
||||||
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
|
Upgrading from Jasmine 4.x? Check out the [upgrade guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_5.0).
|
||||||
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 3.x? Check out the 4.0 release notes for a list of
|
|
||||||
what's new (including breaking changes). You can also read the [upgrade guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0).
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
@@ -20,73 +12,49 @@ Please read the [contributors' guide](https://github.com/jasmine/jasmine/blob/ma
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
For the Jasmine NPM module:<br>
|
There are several different ways to install Jasmine, depending on your
|
||||||
[https://github.com/jasmine/jasmine-npm](https://github.com/jasmine/jasmine-npm).
|
environment and how you'd like to use it. See the [Getting Started page](https://jasmine.github.io/pages/getting_started.html)
|
||||||
|
for details.
|
||||||
|
|
||||||
For the Jasmine browser runner:<br>
|
## Usage
|
||||||
[https://github.com/jasmine/jasmine-browser](https://github.com/jasmine/jasmine-browser).
|
|
||||||
|
|
||||||
To install Jasmine standalone on your local box (where **_{#.#.#}_** below is substituted by the release number downloaded):
|
See the [documentation site](https://jasmine.github.io/pages/docs_home.html),
|
||||||
|
particularly the [Your First Suite tutorial](https://jasmine.github.io/tutorials/your_first_suite)
|
||||||
* Download the standalone distribution for your desired release from the [releases page](https://github.com/jasmine/jasmine/releases).
|
for information on writing specs, and [the FAQ](https://jasmine.github.io/pages/faq.html).
|
||||||
* 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="lib/jasmine-{#.#.#}/jasmine_favicon.png">
|
|
||||||
<link rel="stylesheet" type="text/css" href="lib/jasmine-{#.#.#}/jasmine.css">
|
|
||||||
|
|
||||||
<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
|
## Supported environments
|
||||||
|
|
||||||
Jasmine tests itself across popular browsers (Safari, Chrome, Firefox, and
|
Jasmine tests itself across popular browsers (Safari, Chrome, Firefox, and
|
||||||
Microsoft Edge) as well as nodejs.
|
Microsoft Edge) as well as Node.
|
||||||
|
|
||||||
| Environment | Supported versions |
|
| Environment | Supported versions |
|
||||||
|-------------------|--------------------|
|
|-------------------|---------------------|
|
||||||
| Node | 12.17+, 14, 16 |
|
| Node | 18, 20 |
|
||||||
| Safari | 14-15 |
|
| Safari | 15-17 |
|
||||||
| Chrome | Evergreen |
|
| Chrome | Evergreen |
|
||||||
| Firefox | Evergreen, 91 |
|
| Firefox | Evergreen, 102, 115 |
|
||||||
| Edge | Evergreen |
|
| Edge | Evergreen |
|
||||||
|
|
||||||
For evergreen browsers, each version of Jasmine is tested against the version of the browser that is available to us
|
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.
|
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.
|
However, Jasmine isn't tested against them and they aren't actively supported.
|
||||||
|
|
||||||
See the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes)
|
To find out what environments work with a particular Jasmine release, see the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes).
|
||||||
for the supported environments for each Jasmine release.
|
|
||||||
|
|
||||||
## 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).
|
|
||||||
|
|
||||||
## Maintainers
|
## Maintainers
|
||||||
|
|
||||||
* [Gregg Van Hove](mailto:gvanhove@pivotal.io), Pivotal Labs
|
* [Gwendolyn Van Hove](mailto:gwen@slackersoft.net)
|
||||||
|
* [Steve Gravrock](mailto:sdg@panix.com)
|
||||||
|
|
||||||
### Maintainers Emeritus
|
### Maintainers Emeritus
|
||||||
|
|
||||||
* [Davis W. Frank](mailto:dwfrank@pivotal.io), Pivotal Labs
|
* [Davis W. Frank](mailto:dwfrank@pivotal.io)
|
||||||
* [Rajan Agaskar](mailto:rajan@pivotal.io), Pivotal Labs
|
* [Rajan Agaskar](mailto:rajan@pivotal.io)
|
||||||
* [Greg Cobb](mailto:gcobb@pivotal.io), Pivotal Labs
|
* [Greg Cobb](mailto:gcobb@pivotal.io)
|
||||||
* [Chris Amavisca](mailto:camavisca@pivotal.io), Pivotal Labs
|
* [Chris Amavisca](mailto:camavisca@pivotal.io)
|
||||||
* [Christian Williams](mailto:antixian666@gmail.com), Cloud Foundry
|
* [Christian Williams](mailto:antixian666@gmail.com)
|
||||||
* Sheel Choksi
|
* Sheel Choksi
|
||||||
|
|
||||||
Copyright (c) 2008-2018 Pivotal Labs. This software is licensed under the MIT License.
|
Copyright (c) 2008-2019 Pivotal Labs<br>
|
||||||
|
Copyright (c) 2008-2023 The Jasmine developers<br>
|
||||||
|
This software is licensed under the [MIT License](https://github.com/jasmine/jasmine/blob/main/LICENSE).
|
||||||
## License
|
|
||||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_large)
|
|
||||||
|
|||||||
42
RELEASE.md
42
RELEASE.md
@@ -18,12 +18,11 @@ copied to `jasmine.js` when the distribution is built. When releasing a new
|
|||||||
version, update `package.json` with the new version and `npm run build` to
|
version, update `package.json` with the new version and `npm run build` to
|
||||||
update the gem version number.
|
update the gem version number.
|
||||||
|
|
||||||
Note that Jasmine should only use the "patch" version number in the following cases:
|
Note that Jasmine should only use the "patch" version number if the new release
|
||||||
|
contains only bug fixes.
|
||||||
|
|
||||||
* Changes related to packaging for a specific binding library (npm or browser-runner)
|
When `jasmine-core` revs its major or minor version, the `jasmine` NPM package
|
||||||
* Fixes for regressions.
|
should also rev to that version.
|
||||||
|
|
||||||
When jasmine-core revs its major or minor version, the binding libraries should also rev to that version.
|
|
||||||
|
|
||||||
## Release
|
## Release
|
||||||
|
|
||||||
@@ -35,10 +34,10 @@ When ready to release - specs are all green and the stories are done:
|
|||||||
|
|
||||||
### Commit and push core changes
|
### Commit and push core changes
|
||||||
|
|
||||||
1. Run the browser tests using `scripts/run-all-browsers`.
|
1. Commit release notes and version changes (jasmine.js, package.json)
|
||||||
1. Commit release notes and version changes (jasmine.js, version.rb, package.json)
|
2. Push
|
||||||
1. Push
|
3. Tag the release and push the tag.
|
||||||
1. Wait for Circle CI to go green
|
4. Wait for Circle CI to go green
|
||||||
|
|
||||||
### Build standalone distribution
|
### Build standalone distribution
|
||||||
|
|
||||||
@@ -47,34 +46,27 @@ When ready to release - specs are all green and the stories are done:
|
|||||||
|
|
||||||
### Release the core NPM module
|
### 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 adduser` to save your credentials locally
|
||||||
1. `npm publish .` to publish what's in `package.json`
|
1. `npm publish .` to publish what's in `package.json`
|
||||||
|
|
||||||
### Release the docs
|
### Release the docs
|
||||||
|
|
||||||
Probably only need to do this when releasing a minor version, and not a patch version.
|
Probably only need to do this when releasing a minor version, and not a patch
|
||||||
|
version. See [the README file in the docs repo](https://github.com/jasmine/jasmine.github.io/blob/master/README.md)
|
||||||
|
for instructions.
|
||||||
|
|
||||||
1. `rake update_edge_jasmine`
|
1. `rake update_edge_jasmine`
|
||||||
1. `npm run jsdoc`
|
1. `npm run jsdoc`
|
||||||
1. `rake release[${version}]` to copy the current edge docs to the new version
|
1. `rake release[${version}]` to copy the current edge docs to the new version
|
||||||
1. Commit and push.
|
1. Commit and push.
|
||||||
|
|
||||||
### Release the binding libraries
|
### Release the `jasmine` NPM package
|
||||||
|
|
||||||
#### NPM
|
See <https://github.com/jasmine/jasmine-npm/blob/main/RELEASE.md>.
|
||||||
|
|
||||||
1. Create release notes using Anchorman as above
|
### Publish the GitHub release
|
||||||
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`.)
|
|
||||||
|
|
||||||
### Finally
|
|
||||||
|
|
||||||
For each of the above GitHub repos:
|
|
||||||
1. Visit the releases page and find the tag just published.
|
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.
|
2. Paste in a link to the correct release notes for this release.
|
||||||
1. If it is a pre-release, mark it as such.
|
3. If it is a pre-release, mark it as such.
|
||||||
1. For core, attach the standalone zipfile.
|
4. Attach the standalone zipfile.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
files: [
|
files: [
|
||||||
{ src: [ root("MIT.LICENSE") ] },
|
{ src: [ root("LICENSE") ] },
|
||||||
{
|
{
|
||||||
src: [ "jasmine_favicon.png"],
|
src: [ "jasmine_favicon.png"],
|
||||||
dest: standaloneLibDir,
|
dest: standaloneLibDir,
|
||||||
|
|||||||
@@ -45,10 +45,6 @@ module.exports = {
|
|||||||
src: ['src/boot/boot1.js'],
|
src: ['src/boot/boot1.js'],
|
||||||
dest: 'lib/jasmine-core/boot1.js'
|
dest: 'lib/jasmine-core/boot1.js'
|
||||||
},
|
},
|
||||||
nodeBoot: {
|
|
||||||
src: ['src/boot/node_boot.js'],
|
|
||||||
dest: 'lib/jasmine-core/node_boot.js'
|
|
||||||
},
|
|
||||||
options: {
|
options: {
|
||||||
banner: license(),
|
banner: license(),
|
||||||
process: {
|
process: {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-<%= currentYear %> Pivotal Labs
|
Copyright (c) 2008-2019 Pivotal Labs
|
||||||
|
Copyright (c) 2008-<%= currentYear %> The Jasmine developers
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
@@ -6,47 +6,61 @@
|
|||||||
const jasmineRequire = require('./jasmine-core/jasmine.js');
|
const jasmineRequire = require('./jasmine-core/jasmine.js');
|
||||||
module.exports = jasmineRequire;
|
module.exports = jasmineRequire;
|
||||||
|
|
||||||
/**
|
const boot = (function() {
|
||||||
* Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
|
let jasmine, jasmineInterface;
|
||||||
* @type {function}
|
|
||||||
* @return {jasmine}
|
|
||||||
*/
|
|
||||||
module.exports.boot = require('./jasmine-core/node_boot.js');
|
|
||||||
|
|
||||||
/**
|
return function bootWithoutGlobals(reinitialize) {
|
||||||
* Boots a copy of Jasmine and returns an object containing the properties
|
if (!jasmineInterface || reinitialize === true) {
|
||||||
* that would normally be added to the global object. If noGlobals is called
|
jasmine = jasmineRequire.core(jasmineRequire);
|
||||||
* multiple times, the same object is returned every time.
|
|
||||||
*
|
|
||||||
* Do not call boot() if you also call noGlobals().
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
|
|
||||||
*/
|
|
||||||
module.exports.noGlobals = (function() {
|
|
||||||
let jasmineInterface;
|
|
||||||
|
|
||||||
return function bootWithoutGlobals() {
|
|
||||||
if (!jasmineInterface) {
|
|
||||||
const jasmine = jasmineRequire.core(jasmineRequire);
|
|
||||||
const env = jasmine.getEnv({ suppressLoadErrors: true });
|
const env = jasmine.getEnv({ suppressLoadErrors: true });
|
||||||
jasmineInterface = jasmineRequire.interface(jasmine, env);
|
jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jasmineInterface;
|
return {jasmine, jasmineInterface};
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
var path = require('path'),
|
/**
|
||||||
fs = require('fs');
|
* Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
|
||||||
|
* If boot is called multiple times, the same object is returned every time
|
||||||
|
* unless true is passed.
|
||||||
|
* @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
|
||||||
|
* @type {function}
|
||||||
|
* @return {jasmine}
|
||||||
|
*/
|
||||||
|
module.exports.boot = function(reinitialize) {
|
||||||
|
const {jasmine, jasmineInterface} = boot(reinitialize);
|
||||||
|
|
||||||
var rootPath = path.join(__dirname, "jasmine-core"),
|
for (const k in jasmineInterface) {
|
||||||
bootFiles = ['boot0.js', 'boot1.js'],
|
global[k] = jasmineInterface[k];
|
||||||
legacyBootFiles = ['boot.js'],
|
}
|
||||||
nodeBootFiles = ['node_boot.js'],
|
|
||||||
cssFiles = [],
|
return jasmine;
|
||||||
jsFiles = [],
|
};
|
||||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles, nodeBootFiles);
|
|
||||||
|
/**
|
||||||
|
* Boots a copy of Jasmine and returns an object containing the properties
|
||||||
|
* that would normally be added to the global object. If noGlobals is called
|
||||||
|
* multiple times, the same object is returned every time unless true is passed.
|
||||||
|
*
|
||||||
|
* @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
|
||||||
|
* @example
|
||||||
|
* const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
|
||||||
|
*/
|
||||||
|
module.exports.noGlobals = function(reinitialize) {
|
||||||
|
const {jasmineInterface} = boot(reinitialize);
|
||||||
|
return jasmineInterface;
|
||||||
|
};
|
||||||
|
|
||||||
|
const path = require('path'),
|
||||||
|
fs = require('fs');
|
||||||
|
|
||||||
|
const rootPath = path.join(__dirname, 'jasmine-core'),
|
||||||
|
bootFiles = ['boot0.js', 'boot1.js'],
|
||||||
|
legacyBootFiles = ['boot.js'],
|
||||||
|
cssFiles = [],
|
||||||
|
jsFiles = [],
|
||||||
|
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles);
|
||||||
|
|
||||||
fs.readdirSync(rootPath).forEach(function(file) {
|
fs.readdirSync(rootPath).forEach(function(file) {
|
||||||
if(fs.statSync(path.join(rootPath, file)).isFile()) {
|
if(fs.statSync(path.join(rootPath, file)).isFile()) {
|
||||||
@@ -56,18 +70,18 @@ fs.readdirSync(rootPath).forEach(function(file) {
|
|||||||
break;
|
break;
|
||||||
case '.js':
|
case '.js':
|
||||||
if (jsFilesToSkip.indexOf(file) < 0) {
|
if (jsFilesToSkip.indexOf(file) < 0) {
|
||||||
jsFiles.push(file);
|
jsFiles.push(file);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports.files = {
|
module.exports.files = {
|
||||||
|
self: __filename,
|
||||||
path: rootPath,
|
path: rootPath,
|
||||||
bootDir: rootPath,
|
bootDir: rootPath,
|
||||||
bootFiles: bootFiles,
|
bootFiles: bootFiles,
|
||||||
nodeBootFiles: nodeBootFiles,
|
|
||||||
cssFiles: cssFiles,
|
cssFiles: cssFiles,
|
||||||
jsFiles: ['jasmine.js'].concat(jsFiles),
|
jsFiles: ['jasmine.js'].concat(jsFiles),
|
||||||
imagesDir: path.join(__dirname, '../images')
|
imagesDir: path.join(__dirname, '../images')
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2022 Pivotal Labs
|
Copyright (c) 2008-2019 Pivotal Labs
|
||||||
|
Copyright (c) 2008-2024 The Jasmine developers
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
@@ -27,14 +28,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
source files or spec files are loaded.
|
source files or spec files are loaded.
|
||||||
*/
|
*/
|
||||||
(function() {
|
(function() {
|
||||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
const jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Require & Instantiate
|
* ## Require & Instantiate
|
||||||
*
|
*
|
||||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||||
*/
|
*/
|
||||||
var jasmine = jasmineRequire.core(jasmineRequire),
|
const jasmine = jasmineRequire.core(jasmineRequire),
|
||||||
global = jasmine.getGlobal();
|
global = jasmine.getGlobal();
|
||||||
global.jasmine = jasmine;
|
global.jasmine = jasmine;
|
||||||
|
|
||||||
@@ -46,19 +47,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
/**
|
/**
|
||||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||||
*/
|
*/
|
||||||
var env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## The Global Interface
|
* ## 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.
|
* 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);
|
const 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`.
|
* 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) {
|
for (const property in jasmineInterface) {
|
||||||
global[property] = jasmineInterface[property];
|
global[property] = jasmineInterface[property];
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2022 Pivotal Labs
|
Copyright (c) 2008-2019 Pivotal Labs
|
||||||
|
Copyright (c) 2008-2024 The Jasmine developers
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
@@ -34,7 +35,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Runner Parameters
|
* ## Runner Parameters
|
||||||
@@ -42,15 +43,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
* 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({
|
const queryString = new jasmine.QueryString({
|
||||||
getWindowLocation: function() {
|
getWindowLocation: function() {
|
||||||
return window.location;
|
return window.location;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var filterSpecs = !!queryString.getParam('spec');
|
const filterSpecs = !!queryString.getParam('spec');
|
||||||
|
|
||||||
var config = {
|
const config = {
|
||||||
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
||||||
stopSpecOnExpectationFailure: queryString.getParam(
|
stopSpecOnExpectationFailure: queryString.getParam(
|
||||||
'stopSpecOnExpectationFailure'
|
'stopSpecOnExpectationFailure'
|
||||||
@@ -58,13 +59,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
hideDisabled: queryString.getParam('hideDisabled')
|
hideDisabled: queryString.getParam('hideDisabled')
|
||||||
};
|
};
|
||||||
|
|
||||||
var random = queryString.getParam('random');
|
const random = queryString.getParam('random');
|
||||||
|
|
||||||
if (random !== undefined && random !== '') {
|
if (random !== undefined && random !== '') {
|
||||||
config.random = random;
|
config.random = random;
|
||||||
}
|
}
|
||||||
|
|
||||||
var seed = queryString.getParam('seed');
|
const seed = queryString.getParam('seed');
|
||||||
if (seed) {
|
if (seed) {
|
||||||
config.seed = seed;
|
config.seed = seed;
|
||||||
}
|
}
|
||||||
@@ -73,7 +74,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
* ## Reporters
|
* ## 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).
|
* 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({
|
const htmlReporter = new jasmine.HtmlReporter({
|
||||||
env: env,
|
env: env,
|
||||||
navigateWithNewParam: function(key, value) {
|
navigateWithNewParam: function(key, value) {
|
||||||
return queryString.navigateWithNewParam(key, value);
|
return queryString.navigateWithNewParam(key, value);
|
||||||
@@ -103,7 +104,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
/**
|
/**
|
||||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||||
*/
|
*/
|
||||||
var specFilter = new jasmine.HtmlSpecFilter({
|
const specFilter = new jasmine.HtmlSpecFilter({
|
||||||
filterString: function() {
|
filterString: function() {
|
||||||
return queryString.getParam('spec');
|
return queryString.getParam('spec');
|
||||||
}
|
}
|
||||||
@@ -120,7 +121,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
*
|
*
|
||||||
* 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.
|
* 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;
|
const currentWindowOnload = window.onload;
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (currentWindowOnload) {
|
if (currentWindowOnload) {
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
function Player() {
|
class Player {
|
||||||
}
|
play(song) {
|
||||||
Player.prototype.play = function(song) {
|
this.currentlyPlayingSong = song;
|
||||||
this.currentlyPlayingSong = song;
|
this.isPlaying = true;
|
||||||
this.isPlaying = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
Player.prototype.pause = function() {
|
|
||||||
this.isPlaying = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
Player.prototype.resume = function() {
|
|
||||||
if (this.isPlaying) {
|
|
||||||
throw new Error("song is already playing");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isPlaying = true;
|
pause() {
|
||||||
};
|
this.isPlaying = false;
|
||||||
|
}
|
||||||
|
|
||||||
Player.prototype.makeFavorite = function() {
|
resume() {
|
||||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
if (this.isPlaying) {
|
||||||
};
|
throw new Error('song is already playing');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isPlaying = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
makeFavorite() {
|
||||||
|
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Player;
|
module.exports = Player;
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
function Song() {
|
class Song {
|
||||||
|
persistFavoriteStatus(value) {
|
||||||
|
// something complicated
|
||||||
|
throw new Error('not yet implemented');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Song.prototype.persistFavoriteStatus = function(value) {
|
|
||||||
// something complicated
|
|
||||||
throw new Error("not yet implemented");
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Song;
|
module.exports = Song;
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ beforeEach(function () {
|
|||||||
toBePlaying: function () {
|
toBePlaying: function () {
|
||||||
return {
|
return {
|
||||||
compare: function (actual, expected) {
|
compare: function (actual, expected) {
|
||||||
var player = actual;
|
const player = actual;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pass: player.currentlyPlayingSong === expected && player.isPlaying
|
pass: player.currentlyPlayingSong === expected && player.isPlaying
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,37 @@
|
|||||||
describe("Player", function() {
|
const Player = require('../../lib/jasmine_examples/Player');
|
||||||
var Player = require('../../lib/jasmine_examples/Player');
|
const Song = require('../../lib/jasmine_examples/Song');
|
||||||
var Song = require('../../lib/jasmine_examples/Song');
|
|
||||||
var player;
|
describe('Player', function() {
|
||||||
var song;
|
let player;
|
||||||
|
let song;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
player = new Player();
|
player = new Player();
|
||||||
song = new Song();
|
song = new Song();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be able to play a Song", function() {
|
it('should be able to play a Song', function() {
|
||||||
player.play(song);
|
player.play(song);
|
||||||
expect(player.currentlyPlayingSong).toEqual(song);
|
expect(player.currentlyPlayingSong).toEqual(song);
|
||||||
|
|
||||||
//demonstrates use of custom matcher
|
// demonstrates use of custom matcher
|
||||||
expect(player).toBePlaying(song);
|
expect(player).toBePlaying(song);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when song has been paused", function() {
|
describe('when song has been paused', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
player.play(song);
|
player.play(song);
|
||||||
player.pause();
|
player.pause();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should indicate that the song is currently paused", function() {
|
it('should indicate that the song is currently paused', function() {
|
||||||
expect(player.isPlaying).toBeFalsy();
|
expect(player.isPlaying).toBeFalsy();
|
||||||
|
|
||||||
// demonstrates use of 'not' with a custom matcher
|
// demonstrates use of 'not' with a custom matcher
|
||||||
expect(player).not.toBePlaying(song);
|
expect(player).not.toBePlaying(song);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be possible to resume", function() {
|
it('should be possible to resume', function() {
|
||||||
player.resume();
|
player.resume();
|
||||||
expect(player.isPlaying).toBeTruthy();
|
expect(player.isPlaying).toBeTruthy();
|
||||||
expect(player.currentlyPlayingSong).toEqual(song);
|
expect(player.currentlyPlayingSong).toEqual(song);
|
||||||
@@ -38,7 +39,7 @@ describe("Player", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// demonstrates use of spies to intercept and test method calls
|
// demonstrates use of spies to intercept and test method calls
|
||||||
it("tells the current song if the user has made it a favorite", function() {
|
it('tells the current song if the user has made it a favorite', function() {
|
||||||
spyOn(song, 'persistFavoriteStatus');
|
spyOn(song, 'persistFavoriteStatus');
|
||||||
|
|
||||||
player.play(song);
|
player.play(song);
|
||||||
@@ -48,13 +49,13 @@ describe("Player", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//demonstrates use of expected exceptions
|
//demonstrates use of expected exceptions
|
||||||
describe("#resume", function() {
|
describe('#resume', function() {
|
||||||
it("should throw an exception if song is already playing", function() {
|
it('should throw an exception if song is already playing', function() {
|
||||||
player.play(song);
|
player.play(song);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
player.resume();
|
player.resume();
|
||||||
}).toThrowError("song is already playing");
|
}).toThrowError('song is already playing');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
describe("Player", function() {
|
describe('Player', function() {
|
||||||
var player;
|
let player;
|
||||||
var song;
|
let song;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
player = new Player();
|
player = new Player();
|
||||||
song = new Song();
|
song = new Song();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be able to play a Song", function() {
|
it('should be able to play a Song', function() {
|
||||||
player.play(song);
|
player.play(song);
|
||||||
expect(player.currentlyPlayingSong).toEqual(song);
|
expect(player.currentlyPlayingSong).toEqual(song);
|
||||||
|
|
||||||
//demonstrates use of custom matcher
|
// demonstrates use of custom matcher
|
||||||
expect(player).toBePlaying(song);
|
expect(player).toBePlaying(song);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when song has been paused", function() {
|
describe('when song has been paused', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
player.play(song);
|
player.play(song);
|
||||||
player.pause();
|
player.pause();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should indicate that the song is currently paused", function() {
|
it('should indicate that the song is currently paused', function() {
|
||||||
expect(player.isPlaying).toBeFalsy();
|
expect(player.isPlaying).toBeFalsy();
|
||||||
|
|
||||||
// demonstrates use of 'not' with a custom matcher
|
// demonstrates use of 'not' with a custom matcher
|
||||||
expect(player).not.toBePlaying(song);
|
expect(player).not.toBePlaying(song);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be possible to resume", function() {
|
it('should be possible to resume', function() {
|
||||||
player.resume();
|
player.resume();
|
||||||
expect(player.isPlaying).toBeTruthy();
|
expect(player.isPlaying).toBeTruthy();
|
||||||
expect(player.currentlyPlayingSong).toEqual(song);
|
expect(player.currentlyPlayingSong).toEqual(song);
|
||||||
@@ -36,7 +36,7 @@ describe("Player", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// demonstrates use of spies to intercept and test method calls
|
// demonstrates use of spies to intercept and test method calls
|
||||||
it("tells the current song if the user has made it a favorite", function() {
|
it('tells the current song if the user has made it a favorite', function() {
|
||||||
spyOn(song, 'persistFavoriteStatus');
|
spyOn(song, 'persistFavoriteStatus');
|
||||||
|
|
||||||
player.play(song);
|
player.play(song);
|
||||||
@@ -46,13 +46,13 @@ describe("Player", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//demonstrates use of expected exceptions
|
//demonstrates use of expected exceptions
|
||||||
describe("#resume", function() {
|
describe('#resume', function() {
|
||||||
it("should throw an exception if song is already playing", function() {
|
it('should throw an exception if song is already playing', function() {
|
||||||
player.play(song);
|
player.play(song);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
player.resume();
|
player.resume();
|
||||||
}).toThrowError("song is already playing");
|
}).toThrowError('song is already playing');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ beforeEach(function () {
|
|||||||
toBePlaying: function () {
|
toBePlaying: function () {
|
||||||
return {
|
return {
|
||||||
compare: function (actual, expected) {
|
compare: function (actual, expected) {
|
||||||
var player = actual;
|
const player = actual;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pass: player.currentlyPlayingSong === expected && player.isPlaying
|
pass: player.currentlyPlayingSong === expected && player.isPlaying
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
function Player() {
|
class Player {
|
||||||
}
|
play(song) {
|
||||||
Player.prototype.play = function(song) {
|
this.currentlyPlayingSong = song;
|
||||||
this.currentlyPlayingSong = song;
|
this.isPlaying = true;
|
||||||
this.isPlaying = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
Player.prototype.pause = function() {
|
|
||||||
this.isPlaying = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
Player.prototype.resume = function() {
|
|
||||||
if (this.isPlaying) {
|
|
||||||
throw new Error("song is already playing");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isPlaying = true;
|
pause() {
|
||||||
};
|
this.isPlaying = false;
|
||||||
|
}
|
||||||
|
|
||||||
Player.prototype.makeFavorite = function() {
|
resume() {
|
||||||
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
if (this.isPlaying) {
|
||||||
};
|
throw new Error('song is already playing');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isPlaying = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
makeFavorite() {
|
||||||
|
this.currentlyPlayingSong.persistFavoriteStatus(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
function Song() {
|
class Song {
|
||||||
|
persistFavoriteStatus(value) {
|
||||||
|
// something complicated
|
||||||
|
throw new Error('not yet implemented');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Song.prototype.persistFavoriteStatus = function(value) {
|
|
||||||
// something complicated
|
|
||||||
throw new Error("not yet implemented");
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2008-2022 Pivotal Labs
|
Copyright (c) 2008-2019 Pivotal Labs
|
||||||
|
Copyright (c) 2008-2024 The Jasmine developers
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
@@ -20,6 +21,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line no-var
|
||||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||||
|
|
||||||
jasmineRequire.html = function(j$) {
|
jasmineRequire.html = function(j$) {
|
||||||
@@ -79,19 +81,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function HtmlReporter(options) {
|
function HtmlReporter(options) {
|
||||||
var config = function() {
|
function config() {
|
||||||
return (options.env && options.env.configuration()) || {};
|
return (options.env && options.env.configuration()) || {};
|
||||||
},
|
}
|
||||||
getContainer = options.getContainer,
|
|
||||||
createElement = options.createElement,
|
const getContainer = options.getContainer;
|
||||||
createTextNode = options.createTextNode,
|
const createElement = options.createElement;
|
||||||
navigateWithNewParam = options.navigateWithNewParam || function() {},
|
const createTextNode = options.createTextNode;
|
||||||
addToExistingQueryString =
|
const navigateWithNewParam = options.navigateWithNewParam || function() {};
|
||||||
options.addToExistingQueryString || defaultQueryString,
|
const addToExistingQueryString =
|
||||||
filterSpecs = options.filterSpecs,
|
options.addToExistingQueryString || defaultQueryString;
|
||||||
htmlReporterMain,
|
const filterSpecs = options.filterSpecs;
|
||||||
symbols,
|
let htmlReporterMain;
|
||||||
deprecationWarnings = [];
|
let symbols;
|
||||||
|
const deprecationWarnings = [];
|
||||||
|
const failures = [];
|
||||||
|
|
||||||
this.initialize = function() {
|
this.initialize = function() {
|
||||||
clearPrior();
|
clearPrior();
|
||||||
@@ -119,14 +123,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
getContainer().appendChild(htmlReporterMain);
|
getContainer().appendChild(htmlReporterMain);
|
||||||
};
|
};
|
||||||
|
|
||||||
var totalSpecsDefined;
|
let totalSpecsDefined;
|
||||||
this.jasmineStarted = function(options) {
|
this.jasmineStarted = function(options) {
|
||||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
var summary = createDom('div', { className: 'jasmine-summary' });
|
const summary = createDom('div', { className: 'jasmine-summary' });
|
||||||
|
|
||||||
var stateBuilder = new ResultsStateBuilder();
|
const stateBuilder = new ResultsStateBuilder();
|
||||||
|
|
||||||
this.suiteStarted = function(result) {
|
this.suiteStarted = function(result) {
|
||||||
stateBuilder.suiteStarted(result);
|
stateBuilder.suiteStarted(result);
|
||||||
@@ -145,12 +149,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
stateBuilder.specStarted(result);
|
stateBuilder.specStarted(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
var failures = [];
|
|
||||||
this.specDone = function(result) {
|
this.specDone = function(result) {
|
||||||
stateBuilder.specDone(result);
|
stateBuilder.specDone(result);
|
||||||
|
|
||||||
if (noExpectations(result)) {
|
if (noExpectations(result)) {
|
||||||
var noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
const noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
console.error(noSpecMsg);
|
console.error(noSpecMsg);
|
||||||
} else {
|
} else {
|
||||||
@@ -194,10 +197,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
this.jasmineDone = function(doneResult) {
|
this.jasmineDone = function(doneResult) {
|
||||||
stateBuilder.jasmineDone(doneResult);
|
stateBuilder.jasmineDone(doneResult);
|
||||||
var banner = find('.jasmine-banner');
|
const banner = find('.jasmine-banner');
|
||||||
var alert = find('.jasmine-alert');
|
const alert = find('.jasmine-alert');
|
||||||
var order = doneResult && doneResult.order;
|
const order = doneResult && doneResult.order;
|
||||||
var i;
|
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
'span',
|
'span',
|
||||||
@@ -209,14 +212,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
banner.appendChild(optionsMenu(config()));
|
banner.appendChild(optionsMenu(config()));
|
||||||
|
|
||||||
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
||||||
var skippedMessage =
|
const skippedMessage =
|
||||||
'Ran ' +
|
'Ran ' +
|
||||||
stateBuilder.specsExecuted +
|
stateBuilder.specsExecuted +
|
||||||
' of ' +
|
' of ' +
|
||||||
totalSpecsDefined +
|
totalSpecsDefined +
|
||||||
' specs - run all';
|
' specs - run all';
|
||||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||||
var skippedLink =
|
const skippedLink =
|
||||||
(window.location.pathname || '') +
|
(window.location.pathname || '') +
|
||||||
addToExistingQueryString('spec', '');
|
addToExistingQueryString('spec', '');
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
@@ -231,10 +234,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var statusBarMessage = '';
|
let statusBarMessage = '';
|
||||||
var statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
let statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
||||||
var globalFailures = (doneResult && doneResult.failedExpectations) || [];
|
const globalFailures =
|
||||||
var failed = stateBuilder.failureCount + globalFailures.length > 0;
|
(doneResult && doneResult.failedExpectations) || [];
|
||||||
|
const failed = stateBuilder.failureCount + globalFailures.length > 0;
|
||||||
|
|
||||||
if (totalSpecsDefined > 0 || failed) {
|
if (totalSpecsDefined > 0 || failed) {
|
||||||
statusBarMessage +=
|
statusBarMessage +=
|
||||||
@@ -260,7 +264,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
statusBarClassName += ' jasmine-failed ';
|
statusBarClassName += ' jasmine-failed ';
|
||||||
}
|
}
|
||||||
|
|
||||||
var seedBar;
|
let seedBar;
|
||||||
if (order && order.random) {
|
if (order && order.random) {
|
||||||
seedBar = createDom(
|
seedBar = createDom(
|
||||||
'span',
|
'span',
|
||||||
@@ -286,10 +290,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
var errorBarClassName = 'jasmine-bar jasmine-errored';
|
const errorBarClassName = 'jasmine-bar jasmine-errored';
|
||||||
var afterAllMessagePrefix = 'AfterAll ';
|
const afterAllMessagePrefix = 'AfterAll ';
|
||||||
|
|
||||||
for (i = 0; i < globalFailures.length; i++) {
|
for (let i = 0; i < globalFailures.length; i++) {
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
'span',
|
'span',
|
||||||
@@ -301,7 +305,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
function globalFailureMessage(failure) {
|
function globalFailureMessage(failure) {
|
||||||
if (failure.globalErrorType === 'load') {
|
if (failure.globalErrorType === 'load') {
|
||||||
var prefix = 'Error during loading: ' + failure.message;
|
const prefix = 'Error during loading: ' + failure.message;
|
||||||
|
|
||||||
if (failure.filename) {
|
if (failure.filename) {
|
||||||
return (
|
return (
|
||||||
@@ -319,9 +323,9 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
addDeprecationWarnings(doneResult);
|
addDeprecationWarnings(doneResult);
|
||||||
|
|
||||||
for (i = 0; i < deprecationWarnings.length; i++) {
|
for (let i = 0; i < deprecationWarnings.length; i++) {
|
||||||
var children = [],
|
const children = [];
|
||||||
context;
|
let context;
|
||||||
|
|
||||||
switch (deprecationWarnings[i].runnableType) {
|
switch (deprecationWarnings[i].runnableType) {
|
||||||
case 'spec':
|
case 'spec':
|
||||||
@@ -355,7 +359,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = find('.jasmine-results');
|
const results = find('.jasmine-results');
|
||||||
results.appendChild(summary);
|
results.appendChild(summary);
|
||||||
|
|
||||||
summaryList(stateBuilder.topResults, summary);
|
summaryList(stateBuilder.topResults, summary);
|
||||||
@@ -397,8 +401,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
setMenuModeTo('jasmine-failure-list');
|
setMenuModeTo('jasmine-failure-list');
|
||||||
|
|
||||||
var failureNode = find('.jasmine-failures');
|
const failureNode = find('.jasmine-failures');
|
||||||
for (i = 0; i < failures.length; i++) {
|
for (let i = 0; i < failures.length; i++) {
|
||||||
failureNode.appendChild(failures[i]);
|
failureNode.appendChild(failures[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,16 +411,16 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
function failureDom(result) {
|
function failureDom(result) {
|
||||||
var failure = createDom(
|
const failure = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-spec-detail jasmine-failed' },
|
{ className: 'jasmine-spec-detail jasmine-failed' },
|
||||||
failureDescription(result, stateBuilder.currentParent),
|
failureDescription(result, stateBuilder.currentParent),
|
||||||
createDom('div', { className: 'jasmine-messages' })
|
createDom('div', { className: 'jasmine-messages' })
|
||||||
);
|
);
|
||||||
var messages = failure.childNodes[1];
|
const messages = failure.childNodes[1];
|
||||||
|
|
||||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
for (let i = 0; i < result.failedExpectations.length; i++) {
|
||||||
var expectation = result.failedExpectations[i];
|
const expectation = result.failedExpectations[i];
|
||||||
messages.appendChild(
|
messages.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
'div',
|
'div',
|
||||||
@@ -451,7 +455,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function debugLogTable(debugLogs) {
|
function debugLogTable(debugLogs) {
|
||||||
var tbody = createDom('tbody');
|
const tbody = createDom('tbody');
|
||||||
|
|
||||||
debugLogs.forEach(function(entry) {
|
debugLogs.forEach(function(entry) {
|
||||||
tbody.appendChild(
|
tbody.appendChild(
|
||||||
@@ -491,14 +495,14 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function summaryList(resultsTree, domParent) {
|
function summaryList(resultsTree, domParent) {
|
||||||
var specListNode;
|
let specListNode;
|
||||||
for (var i = 0; i < resultsTree.children.length; i++) {
|
for (let i = 0; i < resultsTree.children.length; i++) {
|
||||||
var resultNode = resultsTree.children[i];
|
const resultNode = resultsTree.children[i];
|
||||||
if (filterSpecs && !hasActiveSpec(resultNode)) {
|
if (filterSpecs && !hasActiveSpec(resultNode)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (resultNode.type === 'suite') {
|
if (resultNode.type === 'suite') {
|
||||||
var suiteListNode = createDom(
|
const suiteListNode = createDom(
|
||||||
'ul',
|
'ul',
|
||||||
{ className: 'jasmine-suite', id: 'suite-' + resultNode.result.id },
|
{ className: 'jasmine-suite', id: 'suite-' + resultNode.result.id },
|
||||||
createDom(
|
createDom(
|
||||||
@@ -523,18 +527,17 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
specListNode = createDom('ul', { className: 'jasmine-specs' });
|
specListNode = createDom('ul', { className: 'jasmine-specs' });
|
||||||
domParent.appendChild(specListNode);
|
domParent.appendChild(specListNode);
|
||||||
}
|
}
|
||||||
var specDescription = resultNode.result.description;
|
let specDescription = resultNode.result.description;
|
||||||
if (noExpectations(resultNode.result)) {
|
if (noExpectations(resultNode.result)) {
|
||||||
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
||||||
}
|
}
|
||||||
if (
|
if (resultNode.result.status === 'pending') {
|
||||||
resultNode.result.status === 'pending' &&
|
if (resultNode.result.pendingReason !== '') {
|
||||||
resultNode.result.pendingReason !== ''
|
specDescription +=
|
||||||
) {
|
' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
|
||||||
specDescription =
|
} else {
|
||||||
specDescription +
|
specDescription += ' PENDING';
|
||||||
' PENDING WITH MESSAGE: ' +
|
}
|
||||||
resultNode.result.pendingReason;
|
|
||||||
}
|
}
|
||||||
specListNode.appendChild(
|
specListNode.appendChild(
|
||||||
createDom(
|
createDom(
|
||||||
@@ -555,7 +558,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function optionsMenu(config) {
|
function optionsMenu(config) {
|
||||||
var optionsMenuDom = createDom(
|
const optionsMenuDom = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-run-options' },
|
{ className: 'jasmine-run-options' },
|
||||||
createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
||||||
@@ -621,13 +624,15 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast');
|
const failFastCheckbox = optionsMenuDom.querySelector(
|
||||||
|
'#jasmine-fail-fast'
|
||||||
|
);
|
||||||
failFastCheckbox.checked = config.stopOnSpecFailure;
|
failFastCheckbox.checked = config.stopOnSpecFailure;
|
||||||
failFastCheckbox.onclick = function() {
|
failFastCheckbox.onclick = function() {
|
||||||
navigateWithNewParam('stopOnSpecFailure', !config.stopOnSpecFailure);
|
navigateWithNewParam('stopOnSpecFailure', !config.stopOnSpecFailure);
|
||||||
};
|
};
|
||||||
|
|
||||||
var throwCheckbox = optionsMenuDom.querySelector(
|
const throwCheckbox = optionsMenuDom.querySelector(
|
||||||
'#jasmine-throw-failures'
|
'#jasmine-throw-failures'
|
||||||
);
|
);
|
||||||
throwCheckbox.checked = config.stopSpecOnExpectationFailure;
|
throwCheckbox.checked = config.stopSpecOnExpectationFailure;
|
||||||
@@ -638,7 +643,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
var randomCheckbox = optionsMenuDom.querySelector(
|
const randomCheckbox = optionsMenuDom.querySelector(
|
||||||
'#jasmine-random-order'
|
'#jasmine-random-order'
|
||||||
);
|
);
|
||||||
randomCheckbox.checked = config.random;
|
randomCheckbox.checked = config.random;
|
||||||
@@ -646,13 +651,15 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
navigateWithNewParam('random', !config.random);
|
navigateWithNewParam('random', !config.random);
|
||||||
};
|
};
|
||||||
|
|
||||||
var hideDisabled = optionsMenuDom.querySelector('#jasmine-hide-disabled');
|
const hideDisabled = optionsMenuDom.querySelector(
|
||||||
|
'#jasmine-hide-disabled'
|
||||||
|
);
|
||||||
hideDisabled.checked = config.hideDisabled;
|
hideDisabled.checked = config.hideDisabled;
|
||||||
hideDisabled.onclick = function() {
|
hideDisabled.onclick = function() {
|
||||||
navigateWithNewParam('hideDisabled', !config.hideDisabled);
|
navigateWithNewParam('hideDisabled', !config.hideDisabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
var optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
const optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
||||||
optionsPayload = optionsMenuDom.querySelector('.jasmine-payload'),
|
optionsPayload = optionsMenuDom.querySelector('.jasmine-payload'),
|
||||||
isOpen = /\bjasmine-open\b/;
|
isOpen = /\bjasmine-open\b/;
|
||||||
|
|
||||||
@@ -671,7 +678,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function failureDescription(result, suite) {
|
function failureDescription(result, suite) {
|
||||||
var wrapper = createDom(
|
const wrapper = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-description' },
|
{ className: 'jasmine-description' },
|
||||||
createDom(
|
createDom(
|
||||||
@@ -680,7 +687,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
result.description
|
result.description
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
var suiteLink;
|
let suiteLink;
|
||||||
|
|
||||||
while (suite && suite.parent) {
|
while (suite && suite.parent) {
|
||||||
wrapper.insertBefore(createTextNode(' > '), wrapper.firstChild);
|
wrapper.insertBefore(createTextNode(' > '), wrapper.firstChild);
|
||||||
@@ -698,7 +705,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function suiteHref(suite) {
|
function suiteHref(suite) {
|
||||||
var els = [];
|
const els = [];
|
||||||
|
|
||||||
while (suite && suite.parent) {
|
while (suite && suite.parent) {
|
||||||
els.unshift(suite.result.description);
|
els.unshift(suite.result.description);
|
||||||
@@ -714,8 +721,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
function addDeprecationWarnings(result, runnableType) {
|
function addDeprecationWarnings(result, runnableType) {
|
||||||
if (result && result.deprecationWarnings) {
|
if (result && result.deprecationWarnings) {
|
||||||
for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
for (let i = 0; i < result.deprecationWarnings.length; i++) {
|
||||||
var warning = result.deprecationWarnings[i].message;
|
const warning = result.deprecationWarnings[i].message;
|
||||||
deprecationWarnings.push({
|
deprecationWarnings.push({
|
||||||
message: warning,
|
message: warning,
|
||||||
stack: result.deprecationWarnings[i].stack,
|
stack: result.deprecationWarnings[i].stack,
|
||||||
@@ -727,8 +734,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createExpander(stackTrace) {
|
function createExpander(stackTrace) {
|
||||||
var expandLink = createDom('a', { href: '#' }, 'Show stack trace');
|
const expandLink = createDom('a', { href: '#' }, 'Show stack trace');
|
||||||
var root = createDom(
|
const root = createDom(
|
||||||
'div',
|
'div',
|
||||||
{ className: 'jasmine-expander' },
|
{ className: 'jasmine-expander' },
|
||||||
expandLink,
|
expandLink,
|
||||||
@@ -759,8 +766,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearPrior() {
|
function clearPrior() {
|
||||||
// return the reporter
|
const oldReporter = find('');
|
||||||
var oldReporter = find('');
|
|
||||||
|
|
||||||
if (oldReporter) {
|
if (oldReporter) {
|
||||||
getContainer().removeChild(oldReporter);
|
getContainer().removeChild(oldReporter);
|
||||||
@@ -768,22 +774,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createDom(type, attrs, childrenArrayOrVarArgs) {
|
function createDom(type, attrs, childrenArrayOrVarArgs) {
|
||||||
var el = createElement(type),
|
const el = createElement(type);
|
||||||
children,
|
let children;
|
||||||
i;
|
|
||||||
|
|
||||||
if (j$.isArray_(childrenArrayOrVarArgs)) {
|
if (j$.isArray_(childrenArrayOrVarArgs)) {
|
||||||
children = childrenArrayOrVarArgs;
|
children = childrenArrayOrVarArgs;
|
||||||
} else {
|
} else {
|
||||||
children = [];
|
children = [];
|
||||||
|
|
||||||
for (i = 2; i < arguments.length; i++) {
|
for (let i = 2; i < arguments.length; i++) {
|
||||||
children.push(arguments[i]);
|
children.push(arguments[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
var child = children[i];
|
const child = children[i];
|
||||||
|
|
||||||
if (typeof child === 'string') {
|
if (typeof child === 'string') {
|
||||||
el.appendChild(createTextNode(child));
|
el.appendChild(createTextNode(child));
|
||||||
@@ -794,7 +799,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var attr in attrs) {
|
for (const attr in attrs) {
|
||||||
if (attr == 'className') {
|
if (attr == 'className') {
|
||||||
el[attr] = attrs[attr];
|
el[attr] = attrs[attr];
|
||||||
} else {
|
} else {
|
||||||
@@ -806,7 +811,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pluralize(singular, count) {
|
function pluralize(singular, count) {
|
||||||
var word = count == 1 ? singular : singular + 's';
|
const word = count == 1 ? singular : singular + 's';
|
||||||
|
|
||||||
return '' + count + ' ' + word;
|
return '' + count + ' ' + word;
|
||||||
}
|
}
|
||||||
@@ -836,7 +841,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function noExpectations(result) {
|
function noExpectations(result) {
|
||||||
var allExpectations =
|
const allExpectations =
|
||||||
result.failedExpectations.length + result.passedExpectations.length;
|
result.failedExpectations.length + result.passedExpectations.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -851,7 +856,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resultNode.type == 'suite') {
|
if (resultNode.type == 'suite') {
|
||||||
for (var i = 0, j = resultNode.children.length; i < j; i++) {
|
for (let i = 0, j = resultNode.children.length; i < j; i++) {
|
||||||
if (hasActiveSpec(resultNode.children[i])) {
|
if (hasActiveSpec(resultNode.children[i])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -865,11 +870,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
jasmineRequire.HtmlSpecFilter = function() {
|
jasmineRequire.HtmlSpecFilter = function() {
|
||||||
function HtmlSpecFilter(options) {
|
function HtmlSpecFilter(options) {
|
||||||
var filterString =
|
const filterString =
|
||||||
options &&
|
options &&
|
||||||
options.filterString() &&
|
options.filterString() &&
|
||||||
options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
||||||
var filterPattern = new RegExp(filterString);
|
const filterPattern = new RegExp(filterString);
|
||||||
|
|
||||||
this.matches = function(specName) {
|
this.matches = function(specName) {
|
||||||
return filterPattern.test(specName);
|
return filterPattern.test(specName);
|
||||||
@@ -913,7 +918,7 @@ jasmineRequire.QueryString = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.fullStringWithNewParam = function(key, value) {
|
this.fullStringWithNewParam = function(key, value) {
|
||||||
var paramMap = queryStringToParamMap();
|
const paramMap = queryStringToParamMap();
|
||||||
paramMap[key] = value;
|
paramMap[key] = value;
|
||||||
return toQueryString(paramMap);
|
return toQueryString(paramMap);
|
||||||
};
|
};
|
||||||
@@ -925,8 +930,8 @@ jasmineRequire.QueryString = function() {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
function toQueryString(paramMap) {
|
function toQueryString(paramMap) {
|
||||||
var qStrPairs = [];
|
const qStrPairs = [];
|
||||||
for (var prop in paramMap) {
|
for (const prop in paramMap) {
|
||||||
qStrPairs.push(
|
qStrPairs.push(
|
||||||
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
||||||
);
|
);
|
||||||
@@ -935,15 +940,15 @@ jasmineRequire.QueryString = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function queryStringToParamMap() {
|
function queryStringToParamMap() {
|
||||||
var paramStr = options.getWindowLocation().search.substring(1),
|
const paramStr = options.getWindowLocation().search.substring(1);
|
||||||
params = [],
|
let params = [];
|
||||||
paramMap = {};
|
const paramMap = {};
|
||||||
|
|
||||||
if (paramStr.length > 0) {
|
if (paramStr.length > 0) {
|
||||||
params = paramStr.split('&');
|
params = paramStr.split('&');
|
||||||
for (var i = 0; i < params.length; i++) {
|
for (let i = 0; i < params.length; i++) {
|
||||||
var p = params[i].split('=');
|
const p = params[i].split('=');
|
||||||
var value = decodeURIComponent(p[1]);
|
let value = decodeURIComponent(p[1]);
|
||||||
if (value === 'true' || value === 'false') {
|
if (value === 'true' || value === 'false') {
|
||||||
value = JSON.parse(value);
|
value = JSON.parse(value);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2008-2022 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.
|
|
||||||
*/
|
|
||||||
module.exports = function(jasmineRequire) {
|
|
||||||
var jasmine = jasmineRequire.core(jasmineRequire);
|
|
||||||
|
|
||||||
var env = jasmine.getEnv({ suppressLoadErrors: true });
|
|
||||||
|
|
||||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
|
||||||
|
|
||||||
extend(global, jasmineInterface);
|
|
||||||
|
|
||||||
function extend(destination, source) {
|
|
||||||
for (var property in source) destination[property] = source[property];
|
|
||||||
return destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
return jasmine;
|
|
||||||
};
|
|
||||||
26
package.json
26
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "jasmine-core",
|
"name": "jasmine-core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "4.0.0",
|
"version": "5.1.2",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/jasmine/jasmine.git"
|
"url": "https://github.com/jasmine/jasmine.git"
|
||||||
@@ -27,28 +27,28 @@
|
|||||||
"homepage": "https://jasmine.github.io",
|
"homepage": "https://jasmine.github.io",
|
||||||
"main": "./lib/jasmine-core.js",
|
"main": "./lib/jasmine-core.js",
|
||||||
"files": [
|
"files": [
|
||||||
"MIT.LICENSE",
|
"LICENSE",
|
||||||
"README.md",
|
"README.md",
|
||||||
"images/*.{png,svg}",
|
"images/*.{png,svg}",
|
||||||
"lib/**/*.{js,css}",
|
"lib/**/*.{js,css}",
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.32.0",
|
"eslint": "^8.36.0",
|
||||||
"eslint-plugin-compat": "^4.0.0",
|
"eslint-plugin-compat": "^4.0.0",
|
||||||
"glob": "^7.2.0",
|
"glob": "^10.2.3",
|
||||||
"grunt": "^1.0.4",
|
"grunt": "^1.0.4",
|
||||||
"grunt-cli": "^1.3.2",
|
"grunt-cli": "^1.3.2",
|
||||||
"grunt-contrib-compress": "^2.0.0",
|
"grunt-contrib-compress": "^2.0.0",
|
||||||
"grunt-contrib-concat": "^2.0.0",
|
"grunt-contrib-concat": "^2.0.0",
|
||||||
"grunt-css-url-embed": "^1.11.1",
|
"grunt-css-url-embed": "^1.11.1",
|
||||||
"grunt-sass": "^3.0.2",
|
"grunt-sass": "^3.0.2",
|
||||||
"jasmine": "github:jasmine/jasmine-npm#main",
|
"jasmine": "^5.0.0",
|
||||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser#main",
|
"jasmine-browser-runner": "github:jasmine/jasmine-browser-runner",
|
||||||
"jsdom": "^19.0.0",
|
"jsdom": "^22.0.0",
|
||||||
"load-grunt-tasks": "^5.1.0",
|
"load-grunt-tasks": "^5.1.0",
|
||||||
"prettier": "1.17.1",
|
"prettier": "1.17.1",
|
||||||
"sass": "^1.45.1",
|
"sass": "^1.58.3",
|
||||||
"shelljs": "^0.8.3",
|
"shelljs": "^0.8.3",
|
||||||
"temp": "^0.9.0"
|
"temp": "^0.9.0"
|
||||||
},
|
},
|
||||||
@@ -95,14 +95,16 @@
|
|||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
],
|
],
|
||||||
"space-before-blocks": "error"
|
"space-before-blocks": "error",
|
||||||
|
"no-eval": "error",
|
||||||
|
"no-var": "error",
|
||||||
|
"no-debugger": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"Safari >= 13",
|
"Safari >= 15",
|
||||||
|
"Firefox >= 102",
|
||||||
"last 2 Chrome versions",
|
"last 2 Chrome versions",
|
||||||
"last 2 Firefox versions",
|
|
||||||
"Firefox >= 68",
|
|
||||||
"last 2 Edge versions"
|
"last 2 Edge versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
22
release_notes/3.99.1.md
Normal file
22
release_notes/3.99.1.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Jasmine Core 3.99.1 Release Notes
|
||||||
|
|
||||||
|
This release fixes a bug in 3.99.0, which incorrectly reported a deprecation
|
||||||
|
warning when a promise returned from a function passed to `it`, `beforeEach`,
|
||||||
|
etc was resolved to a value.
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 3.99.1 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 10, 12, 14, 16 |
|
||||||
|
| Safari | 10-14 |
|
||||||
|
| Chrome | 98 |
|
||||||
|
| Firefox | 97, 78, 68 |
|
||||||
|
| Edge | 98 |
|
||||||
|
| Internet Explorer | 10, 11 |
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
21
release_notes/4.0.1.md
Normal file
21
release_notes/4.0.1.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Jasmine Core 4.0.1 Release Notes
|
||||||
|
|
||||||
|
This release fixes a bug in 4.0.0, which incorrectly reported a failure
|
||||||
|
when a promise returned from a function passed to `it`, `beforeEach`,
|
||||||
|
etc was resolved to a value.
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.0.1 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16 |
|
||||||
|
| Safari | 14-15 |
|
||||||
|
| Chrome | 98 |
|
||||||
|
| Firefox | 91, 97 |
|
||||||
|
| Edge | 98 |
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
50
release_notes/4.1.0.md
Normal file
50
release_notes/4.1.0.md
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Jasmine 4.1.0 Release Notes
|
||||||
|
|
||||||
|
## New Features and Bug Fixes
|
||||||
|
|
||||||
|
* toBeCloseTo treats Infinity and -Infinity as close to themselves
|
||||||
|
* Fixes [#1957](https://github.com/jasmine/jasmine/issues/1957)
|
||||||
|
|
||||||
|
* Replaced uses of deprecated String.prototype.substr()
|
||||||
|
* Merges [#1962](https://github.com/jasmine/jasmine/pull/1962) from @CommanderRoot
|
||||||
|
|
||||||
|
* Removed obsolete vendor-specific background-size CSS rules
|
||||||
|
* Fixes [#1961](https://github.com/jasmine/jasmine/issues/1961)
|
||||||
|
|
||||||
|
* Added toHaveSpyInteractions matcher
|
||||||
|
* Merges [#1959](https://github.com/jasmine/jasmine/pull/1959) from @nitobuenida
|
||||||
|
* Fixes [#1568](https://github.com/jasmine/jasmine/issues/1568)
|
||||||
|
|
||||||
|
* Pretty-print [new String("")] as "[ '' ]", not "[]"
|
||||||
|
|
||||||
|
* Fixed cloning of Date objects in Spy#calls#saveArgumentsByValue
|
||||||
|
* Merges [#1955](https://github.com/jasmine/jasmine/pull/1955) from @coyoteecd
|
||||||
|
* Fixes [#1885](https://github.com/jasmine/jasmine/issues/1885)
|
||||||
|
|
||||||
|
* Include the name of the suite in the empty suite error message
|
||||||
|
|
||||||
|
* toEqual checks keys that are Symbols
|
||||||
|
* Merges [#1879](https://github.com/jasmine/jasmine/pull/1879) from @laeleoni
|
||||||
|
* Fixes [#1811](https://github.com/jasmine/jasmine/issues/1811)
|
||||||
|
|
||||||
|
## Documentation Updates
|
||||||
|
|
||||||
|
* Replaced redundant installation instructions in README with link to docs
|
||||||
|
|
||||||
|
* Added links to usage instructions to README
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.1.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16 |
|
||||||
|
| Safari | 14-15 |
|
||||||
|
| Chrome | 100 |
|
||||||
|
| Firefox | 91, 99 |
|
||||||
|
| Edge | 100 |
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
35
release_notes/4.1.1.md
Normal file
35
release_notes/4.1.1.md
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Jasmine 4.1.1 Release Notes
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This release fixes several bugs involving equality comparison of properties
|
||||||
|
with Symbol keys.
|
||||||
|
|
||||||
|
## Bug fixes
|
||||||
|
|
||||||
|
* Fixes for crash bugs and output problems when comparing objects with Symbol keys
|
||||||
|
* Include symbol properties in matcher diffs
|
||||||
|
* Fixed exception when comparing arrays with Symbol keys
|
||||||
|
* Include symbol properties in matcher diffs
|
||||||
|
* Include symbol keys when pretty-printing objects
|
||||||
|
* Fixes [#1966](https://github.com/jasmine/jasmine/issues/1966)
|
||||||
|
|
||||||
|
* Exclude non-enumerable symbol properties from equality comparison
|
||||||
|
* Merges [#1963](https://github.com/jasmine/jasmine/pull/1963) from @suke
|
||||||
|
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.1.1 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16, 18 |
|
||||||
|
| Safari | 14, 15 |
|
||||||
|
| Chrome | 101 |
|
||||||
|
| Firefox | 91, 100 |
|
||||||
|
| Edge | 101 |
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
41
release_notes/4.2.0.md
Normal file
41
release_notes/4.2.0.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Jasmine 4.2.0 Release Notes
|
||||||
|
|
||||||
|
## New Features
|
||||||
|
|
||||||
|
* Added a jasmine.is asymmetric equality tester
|
||||||
|
* Allows the use of === comparisons for specific fields of an object that
|
||||||
|
should otherwise be compared with the default deep value equality logic.
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
* More reliably report errors that occur late in the suite/spec lifecycle
|
||||||
|
* Previously, an error that occurred after Jasmine started to report the
|
||||||
|
suiteDone or specDone event for the current runable would not be reliably
|
||||||
|
reported. Now such an error is reported on the nearest ancestor suite whose
|
||||||
|
suiteDone event has not yet been reported.
|
||||||
|
|
||||||
|
* Don't report a deprecation when a runnable uses two forms of async
|
||||||
|
* This was made into an error in 4.0, so the deprecation is redundant.
|
||||||
|
|
||||||
|
* Include property getter values in pretty-printed objects
|
||||||
|
|
||||||
|
## Documentation Updates
|
||||||
|
|
||||||
|
* Removed duplicate Suite and Spec jsdocs
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.2.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16, 18 |
|
||||||
|
| Safari | 14-15 |
|
||||||
|
| Chrome | 102 |
|
||||||
|
| Firefox | 91, 101 |
|
||||||
|
| Edge | 101 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
40
release_notes/4.3.0.md
Normal file
40
release_notes/4.3.0.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Jasmine 4.3.0 Release Notes
|
||||||
|
|
||||||
|
## New Features
|
||||||
|
|
||||||
|
* Added [`jasmine.spyOnGlobalErrorsAsync`](https://jasmine.github.io/api/4.3/jasmine.html#.spyOnGlobalErrorsAsync),
|
||||||
|
to better support testing code that's
|
||||||
|
expected to produce unhandled exceptions or unhandled promise rejections
|
||||||
|
* Fixes [#1843](https://github.com/jasmine/jasmine/issues/1843)
|
||||||
|
* Fixes [#1453](https://github.com/jasmine/jasmine/issues/1453)
|
||||||
|
|
||||||
|
## Documentation updates
|
||||||
|
|
||||||
|
* Updated the README to reduce redundancy and update support links
|
||||||
|
|
||||||
|
## Internal improvements
|
||||||
|
|
||||||
|
* Split `Env` into several smaller classes
|
||||||
|
* Replaced uses of `var` with `const`/`let`
|
||||||
|
* Replaced most uses of `self = this` with arrow fns
|
||||||
|
* Removed obsolete and unused utility fns
|
||||||
|
* Separated reporter- and runable-specific queue runner configuration
|
||||||
|
* Added more test coverage for default spy strategies
|
||||||
|
* Converted integration specs to `async`/`await`
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.3.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16, 18 |
|
||||||
|
| Safari | 14-15 |
|
||||||
|
| Chrome | 103 |
|
||||||
|
| Firefox | 91, 102 |
|
||||||
|
| Edge | 103 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
28
release_notes/4.4.0.md
Normal file
28
release_notes/4.4.0.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Jasmine 4.4.0 Release Notes
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
* Optimized the process of transitioning between specs in Node, Safari, and
|
||||||
|
Edge. This change reduces the run time of jasmine-core's own test suite by
|
||||||
|
50-70% in Node, about 20% in Edge, and 75-90% in Safari. Your results may
|
||||||
|
vary. In general, suites with many fast specs will see the greatest
|
||||||
|
performance improvement.
|
||||||
|
|
||||||
|
* Removed old code to support browsers that don't provide
|
||||||
|
addEventListener/removeEventListener.
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.4.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16, 18 |
|
||||||
|
| Safari | 14-15 |
|
||||||
|
| Chrome | 105 |
|
||||||
|
| Firefox | 91, 102, 104 |
|
||||||
|
| Edge | 104 |
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
40
release_notes/4.5.0.md
Normal file
40
release_notes/4.5.0.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Jasmine 4.5.0 Release Notes
|
||||||
|
|
||||||
|
## New Features
|
||||||
|
|
||||||
|
* Added Safari 16 to supported browsers
|
||||||
|
* Include inner exceptions in stack traces
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
* Report exceptions thrown by a describe before any it calls
|
||||||
|
* Coerce the random string to a seed before sending it to reporters
|
||||||
|
* This fixes an error in HTMLReporter when the configured seed is a
|
||||||
|
number rather than a string, which has been allowed since 3.8.0
|
||||||
|
|
||||||
|
## Documentation updates
|
||||||
|
|
||||||
|
* Fixed the jsdoc types of SuiteResult and SpecResult ids
|
||||||
|
* Replaced var with const in API doc examples
|
||||||
|
* Updated the style of the examples that are included in jasmine-core
|
||||||
|
|
||||||
|
## Internal improvements
|
||||||
|
|
||||||
|
* Converted TreeProcessor to async/await
|
||||||
|
* Converted ReportDispatcher to promises
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 4.5.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 12.17+, 14, 16, 18 |
|
||||||
|
| Safari | 14-16 |
|
||||||
|
| Chrome | 107 |
|
||||||
|
| Firefox | 91, 102, 106 |
|
||||||
|
| Edge | 106 |
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
19
release_notes/4.6.0.md
Normal file
19
release_notes/4.6.0.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Jasmine Core 4.6.0 Release Notes
|
||||||
|
|
||||||
|
## New Features
|
||||||
|
|
||||||
|
* Report the ID of each suite/spec's parent
|
||||||
|
* Report the path/url of the file that the spec/suite was defined in
|
||||||
|
* Fixes [#1884](https://github.com/jasmine/jasmine/issues/1884)
|
||||||
|
* Added Firefox 102 (current ESR) to supported browsers
|
||||||
|
|
||||||
|
|
||||||
|
## Internal improvements
|
||||||
|
|
||||||
|
* Pinned sass to 1.58.3 for compatibility with Node 12
|
||||||
|
* Pinned eslint-plugin-compat to <4.1.0 for compatibility with Node 12
|
||||||
|
* Pinned Grunt to <1.6.0 for compatibility with Node 12
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
68
release_notes/5.0.0-alpha.0.md
Normal file
68
release_notes/5.0.0-alpha.0.md
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# Jasmine Core 5.0.0-alpha.0 Release Notes
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This release primarily adds support for parallel execution via the `jasmine`
|
||||||
|
package. Please see its release notes and the
|
||||||
|
[parallel documentation](https://jasmine.github.io/tutorials/running_specs_in_parallel)
|
||||||
|
for more information. Additionally, this release cleans up a few outdated
|
||||||
|
interfaces.
|
||||||
|
|
||||||
|
This is a pre-release for a major version. It contains breaking changes, and
|
||||||
|
there may be further breaking changes between this release and the final 5.0.0
|
||||||
|
release.
|
||||||
|
|
||||||
|
## Breaking changes
|
||||||
|
|
||||||
|
* Use addEventListener in browsers rather than setting window.onerror
|
||||||
|
|
||||||
|
This simplifies error handling in browsers, makes Jasmine's own integration
|
||||||
|
tests easier to debug, and provides stack traces for more unhandled
|
||||||
|
exceptions. However, some browsers will provide less error information when
|
||||||
|
the error comes from a file:// URL. Additionally, Jasmine will no longer
|
||||||
|
override existing onerror handlers, and setting window.onerror will no longer
|
||||||
|
override Jasmine's global error handling. (Use `jasmine.spyOnGlobalErrors`
|
||||||
|
instead.)
|
||||||
|
|
||||||
|
* Made Env#execute async
|
||||||
|
* Env#execute no longer takes a callback
|
||||||
|
* The `boot` function exported by the core module returns the same object
|
||||||
|
every time it's called.
|
||||||
|
* Removed node_boot.js. Use the exported `boot` function instead.
|
||||||
|
|
||||||
|
### Changes to supported environments
|
||||||
|
|
||||||
|
The following previously supported environments are no longer supported:
|
||||||
|
|
||||||
|
* Node <16.14
|
||||||
|
* Safari 14
|
||||||
|
* Firefox 91
|
||||||
|
|
||||||
|
Although this release may still work in some of those environments, we no
|
||||||
|
longer test against them and won't try to maintain compatibility with them in
|
||||||
|
future releases.
|
||||||
|
|
||||||
|
## New features
|
||||||
|
|
||||||
|
* Support for parallel execution in Node.js using the `jasmine` package
|
||||||
|
|
||||||
|
## Bug fixes
|
||||||
|
|
||||||
|
* The global error handler is uninstalled at the end of env execution.
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 5.0.0-alpha.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 16.14+, 18 |
|
||||||
|
| Safari | 15-16 |
|
||||||
|
| Chrome | 111 |
|
||||||
|
| Firefox | 102, 111 |
|
||||||
|
| Edge | 111 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
39
release_notes/5.0.0-alpha.1.md
Normal file
39
release_notes/5.0.0-alpha.1.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Jasmine Core 5.0.0-alpha.1 Release Notes
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This release provides improved support for parallel execution via the `jasmine`
|
||||||
|
package. Please see its release notes and the
|
||||||
|
[parallel documentation](https://jasmine.github.io/tutorials/running_specs_in_parallel)
|
||||||
|
for more information.
|
||||||
|
|
||||||
|
## New features and bug fixes
|
||||||
|
|
||||||
|
* Parallel: Cleaner interface for reporter dispatching
|
||||||
|
* When Env#config is called from spec and helper files in parallel mode, throw
|
||||||
|
an error rather than behaving unpredictably.
|
||||||
|
|
||||||
|
## Documentation improvements
|
||||||
|
|
||||||
|
* API reference docs for parallel support APIs that jasmine-npm uses
|
||||||
|
|
||||||
|
## Internal improvements
|
||||||
|
|
||||||
|
* Updated dev dependencies
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 5.0.0-alpha.1 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 16.14+, 18 |
|
||||||
|
| Safari | 15-16 |
|
||||||
|
| Chrome | 112 |
|
||||||
|
| Firefox | 102, 111 |
|
||||||
|
| Edge | 111 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
28
release_notes/5.0.0-beta.0.md
Normal file
28
release_notes/5.0.0-beta.0.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Jasmine Core 5.0.0-beta.0 Release Notes
|
||||||
|
|
||||||
|
This release supports the 5.0.0-beta-0 release of the `jasmine` package.
|
||||||
|
|
||||||
|
## Breaking changes
|
||||||
|
|
||||||
|
* Dropped support for Node 16
|
||||||
|
|
||||||
|
## New features
|
||||||
|
|
||||||
|
* Added support for Node 20
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 5.0.0-beta.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 18, 20 |
|
||||||
|
| Safari | 15-16 |
|
||||||
|
| Chrome | 112 |
|
||||||
|
| Firefox | 102, 112 |
|
||||||
|
| Edge | 112 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
55
release_notes/5.0.0.md
Normal file
55
release_notes/5.0.0.md
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# Jasmine Core 5.0.0 Release Notes
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This is a major release that includes breaking changes. It primarily adds
|
||||||
|
support for parallel execution in Node via the `jasmine` package. Most users
|
||||||
|
should be able to upgrade without changes, but please read the list of breaking
|
||||||
|
changes below and see the [migration guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_5.0)
|
||||||
|
for more information.
|
||||||
|
|
||||||
|
## Breaking changes
|
||||||
|
|
||||||
|
* Dropped support for Node 12, 14, and 16
|
||||||
|
* Dropped support for Safari 14 and Firefox 91
|
||||||
|
* Made Env#execute async and removed the callback parameter
|
||||||
|
* Global errors are detected via addEventListener rather than setting window.onerror
|
||||||
|
* The `boot` function exported by the core module returns the same object
|
||||||
|
every time it's called.
|
||||||
|
* Removed node_boot.js. Use the exported `boot` function instead.
|
||||||
|
|
||||||
|
## New features
|
||||||
|
|
||||||
|
* Support for parallel execution in Node via the `jasmine` package
|
||||||
|
See the [parallel guide](https://jasmine.github.io/tutorials/running_specs_in_parallel)
|
||||||
|
for more information.
|
||||||
|
* Added Node 20 to supported environments
|
||||||
|
|
||||||
|
## Bug fixes
|
||||||
|
|
||||||
|
* Accessibility: Always provide a non-color indication that a spec is pending
|
||||||
|
* Accessibility: Improved contrast of version number and inactive tab links
|
||||||
|
* Uninstall the global error handler at the end of env execution
|
||||||
|
|
||||||
|
## Internal improvements
|
||||||
|
|
||||||
|
* Updated dev dependencies
|
||||||
|
* Dogfood parallel execution feature in CI
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 5.0.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 18, 20 |
|
||||||
|
| Safari | 15-16 |
|
||||||
|
| Chrome | 113 |
|
||||||
|
| Firefox | 102, 113 |
|
||||||
|
| Edge | 113 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
25
release_notes/5.0.1.md
Normal file
25
release_notes/5.0.1.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Jasmine Core 5.0.1 Release Notes
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
* Optionally restore the pre-5.0 behavior of boot() always creating a new instance
|
||||||
|
|
||||||
|
This is needed by jasmine-npm (and likely other tools like it) that may
|
||||||
|
need to create and use multiple envs in sequence.
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 5.0.1 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 18, 20 |
|
||||||
|
| Safari | 15-16 |
|
||||||
|
| Chrome | 114 |
|
||||||
|
| Firefox | 102, 113 |
|
||||||
|
| Edge | 113 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
39
release_notes/5.1.0.md
Normal file
39
release_notes/5.1.0.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Jasmine Core 5.1.0 Release Notes
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
* Exclude inherited Error properties from stack trace
|
||||||
|
|
||||||
|
* Fixed error when formatting Error object with non-Error cause property
|
||||||
|
|
||||||
|
Merges [#2013](https://github.com/jasmine/jasmine/pull/2013) from @angrycat9000.
|
||||||
|
|
||||||
|
Fixes [#2011](https://github.com/jasmine/jasmine/issues/2011).
|
||||||
|
|
||||||
|
* Added `throwUnless` and `throwUnlessAsync`
|
||||||
|
|
||||||
|
These are similar to `expect` and `expectAsync` except that they throw
|
||||||
|
exceptions rather than recording matcher failures as spec/suite failures.
|
||||||
|
They're intended to support using Jasmine matchers in [testing-library's](https://testing-library.com/)
|
||||||
|
`waitFor`, and also provide a way to integration-test custom matchers.
|
||||||
|
|
||||||
|
Fixes [#2003](https://github.com/jasmine/jasmine/issues/2003).
|
||||||
|
|
||||||
|
Fixes [#1980](https://github.com/jasmine/jasmine/issues/1980).
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 5.1.0 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 18, 20 |
|
||||||
|
| Safari | 15-16 |
|
||||||
|
| Chrome | 114 |
|
||||||
|
| Firefox | 102, 113 |
|
||||||
|
| Edge | 113 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
28
release_notes/5.1.1.md
Normal file
28
release_notes/5.1.1.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Jasmine Core 5.1.1 Release Notes
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
* Fixed global variable leak in the main process when running in parallel mode
|
||||||
|
* Removed unnecessary throw when building expectation results
|
||||||
|
|
||||||
|
## Documentation Improvements
|
||||||
|
|
||||||
|
* Improved jsdocs for originalFn argument to createSpy
|
||||||
|
* Link to 5.0 upgrade guide in README, not 4.0
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
jasmine-core 5.1.1 has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 18, 20 |
|
||||||
|
| Safari | 15-16 |
|
||||||
|
| Chrome | 116 |
|
||||||
|
| Firefox | 102, 116 |
|
||||||
|
| Edge | 115 |
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
27
release_notes/5.1.2.md
Normal file
27
release_notes/5.1.2.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Jasmine Core 5.1.2 Release Notes
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
* Fixed `throwUnlessAsync`
|
||||||
|
* Fixes [#2026](https://github.com/jasmine/jasmine/issues/2026)
|
||||||
|
|
||||||
|
# Documentation improvements
|
||||||
|
|
||||||
|
* Added Safari 17 to supported browsers
|
||||||
|
* Added Firefox 115 (current ESR) to supported browsers
|
||||||
|
|
||||||
|
## Supported environments
|
||||||
|
|
||||||
|
This version has been tested in the following environments.
|
||||||
|
|
||||||
|
| Environment | Supported versions |
|
||||||
|
|-------------------|--------------------|
|
||||||
|
| Node | 18, 20 |
|
||||||
|
| Safari | 15-17 |
|
||||||
|
| Chrome | 121 |
|
||||||
|
| Firefox | 102, 115, 122 |
|
||||||
|
| Edge | 121 |
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
run_browser() {
|
run_browser() {
|
||||||
browser=$1
|
browser=$1
|
||||||
version=$2
|
version=$2
|
||||||
|
os="$3"
|
||||||
description="$browser $version"
|
description="$browser $version"
|
||||||
if [ $version = "latest" ]; then
|
if [ $version = "latest" ]; then
|
||||||
version=""
|
version=""
|
||||||
@@ -12,7 +13,7 @@ run_browser() {
|
|||||||
echo
|
echo
|
||||||
echo "Running $description"
|
echo "Running $description"
|
||||||
echo
|
echo
|
||||||
USE_SAUCE=true JASMINE_BROWSER=$browser SAUCE_BROWSER_VERSION=$version npm run ci
|
USE_SAUCE=true JASMINE_BROWSER=$browser SAUCE_BROWSER_VERSION=$version SAUCE_OS="$os" npm run ci
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "PASS: $description" >> "$passfile"
|
echo "PASS: $description" >> "$passfile"
|
||||||
@@ -23,11 +24,23 @@ run_browser() {
|
|||||||
|
|
||||||
passfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
passfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||||
failfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
failfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||||
run_browser chrome latest
|
|
||||||
|
# As of 2023-09-30, Sauce Connect doesn't work with the latest Chrome version
|
||||||
|
# on the default Linux. Run on Mac OS instead. The OS specification may need to
|
||||||
|
# be updated or removed when new Chrome versions stop being available on Mac OS
|
||||||
|
# 12, although historically this has taken several major OS versions.
|
||||||
|
# See <https://saucelabs.com/products/supported-browsers-devices>.
|
||||||
|
# On Saucelabs, the test suite frequently runs ~30s slower on Mac OS than it
|
||||||
|
# does on Linux, so it's probably worth removing the OS specification once Sauce
|
||||||
|
# Connect works with Chrome latest on Linux again.
|
||||||
|
run_browser chrome latest "macOS 12"
|
||||||
|
|
||||||
run_browser firefox latest
|
run_browser firefox latest
|
||||||
run_browser firefox 91
|
run_browser firefox 115
|
||||||
|
run_browser firefox 102
|
||||||
|
run_browser safari 17
|
||||||
|
run_browser safari 16
|
||||||
run_browser safari 15
|
run_browser safari 15
|
||||||
run_browser safari 14
|
|
||||||
run_browser MicrosoftEdge latest
|
run_browser MicrosoftEdge latest
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ module.exports = {
|
|||||||
semi: 'off',
|
semi: 'off',
|
||||||
'key-spacing': 'off',
|
'key-spacing': 'off',
|
||||||
'space-before-blocks': 'off',
|
'space-before-blocks': 'off',
|
||||||
'no-unused-vars': 'off',
|
|
||||||
'no-trailing-spaces': 'off',
|
'no-trailing-spaces': 'off',
|
||||||
'block-spacing': 'off',
|
'block-spacing': 'off',
|
||||||
|
|
||||||
|
// Additionally, check for unused fn args
|
||||||
|
// TODO: consider doing this in src files as well as specs
|
||||||
|
'no-unused-vars': ['error', { args: 'after-used' }],
|
||||||
|
|
||||||
// Since linting is done at the end of the process and doesn't stop us
|
// 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
|
// from running tests, it makes sense to fail if debugger statements
|
||||||
// or console references are present.
|
// or console references are present.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
describe('#not', function() {
|
describe('#not', function() {
|
||||||
it('converts a pass to a fail', function() {
|
it('converts a pass to a fail', function() {
|
||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.resolve(),
|
actual = Promise.resolve(),
|
||||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
@@ -28,8 +28,8 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('converts a fail to a pass', function() {
|
it('converts a fail to a pass', function() {
|
||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.reject(),
|
actual = Promise.reject(new Error('nope')),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
||||||
pp: function() {}
|
pp: function() {}
|
||||||
@@ -51,9 +51,9 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('propagates rejections from the comparison function', function() {
|
it('propagates rejections from the comparison function', function() {
|
||||||
var error = new Error('ExpectationSpec failure');
|
const error = new Error('ExpectationSpec failure');
|
||||||
|
|
||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = dummyPromise(),
|
actual = dummyPromise(),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: actual,
|
actual: actual,
|
||||||
@@ -74,7 +74,7 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
describe('#withContext', function() {
|
describe('#withContext', function() {
|
||||||
it('prepends the context to the generated failure message', function() {
|
it('prepends the context to the generated failure message', function() {
|
||||||
var matchersUtil = {
|
const matchersUtil = {
|
||||||
pp: function(val) {
|
pp: function(val) {
|
||||||
return val.toString();
|
return val.toString();
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prepends the context to a custom failure message', function() {
|
it('prepends the context to a custom failure message', function() {
|
||||||
var matchersUtil = {
|
const matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'failure message';
|
return 'failure message';
|
||||||
},
|
},
|
||||||
@@ -132,13 +132,13 @@ describe('AsyncExpectation', function() {
|
|||||||
it('prepends the context to a custom failure message from a function', function() {
|
it('prepends the context to a custom failure message from a function', function() {
|
||||||
pending('should actually work, but no custom matchers for async yet');
|
pending('should actually work, but no custom matchers for async yet');
|
||||||
|
|
||||||
var matchersUtil = {
|
const matchersUtil = {
|
||||||
buildFailureMessage: function() {
|
buildFailureMessage: function() {
|
||||||
return 'failure message';
|
return 'failure message';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.reject(),
|
actual = Promise.reject(new Error('nope')),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult,
|
addExpectationResult: addExpectationResult,
|
||||||
@@ -159,7 +159,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('works with #not', function() {
|
it('works with #not', function() {
|
||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.resolve(),
|
actual = Promise.resolve(),
|
||||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
@@ -183,7 +183,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('works with #not and a custom message', function() {
|
it('works with #not and a custom message', function() {
|
||||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = Promise.resolve('a'),
|
actual = Promise.resolve('a'),
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: actual,
|
actual: actual,
|
||||||
@@ -210,22 +210,20 @@ describe('AsyncExpectation', function() {
|
|||||||
|
|
||||||
describe('async matchers', function() {
|
describe('async matchers', function() {
|
||||||
it('makes custom matchers available to this expectation', function() {
|
it('makes custom matchers available to this expectation', function() {
|
||||||
var asyncMatchers = {
|
const asyncMatchers = {
|
||||||
toFoo: function() {},
|
toFoo: function() {},
|
||||||
toBar: function() {}
|
toBar: function() {}
|
||||||
},
|
},
|
||||||
expectation;
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
|
customAsyncMatchers: asyncMatchers
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
});
|
||||||
customAsyncMatchers: asyncMatchers
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(expectation.toFoo).toBeDefined();
|
expect(expectation.toFoo).toBeDefined();
|
||||||
expect(expectation.toBar).toBeDefined();
|
expect(expectation.toBar).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("wraps matchers's compare functions, passing in matcher dependencies", function() {
|
it("wraps matchers's compare functions, passing in matcher dependencies", function() {
|
||||||
var fakeCompare = function() {
|
const fakeCompare = function() {
|
||||||
return Promise.resolve({ pass: true });
|
return Promise.resolve({ pass: true });
|
||||||
},
|
},
|
||||||
matcherFactory = jasmine
|
matcherFactory = jasmine
|
||||||
@@ -238,14 +236,12 @@ describe('AsyncExpectation', function() {
|
|||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
expectation;
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
|
matchersUtil: matchersUtil,
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
customAsyncMatchers: matchers,
|
||||||
matchersUtil: matchersUtil,
|
actual: 'an actual',
|
||||||
customAsyncMatchers: matchers,
|
addExpectationResult: addExpectationResult
|
||||||
actual: 'an actual',
|
});
|
||||||
addExpectationResult: addExpectationResult
|
|
||||||
});
|
|
||||||
|
|
||||||
return expectation.toFoo('hello').then(function() {
|
return expectation.toFoo('hello').then(function() {
|
||||||
expect(matcherFactory).toHaveBeenCalledWith(matchersUtil);
|
expect(matcherFactory).toHaveBeenCalledWith(matchersUtil);
|
||||||
@@ -253,7 +249,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
||||||
var fakeCompare = jasmine
|
const fakeCompare = jasmine
|
||||||
.createSpy('fake-compare')
|
.createSpy('fake-compare')
|
||||||
.and.returnValue(Promise.resolve({ pass: true })),
|
.and.returnValue(Promise.resolve({ pass: true })),
|
||||||
matchers = {
|
matchers = {
|
||||||
@@ -267,14 +263,12 @@ describe('AsyncExpectation', function() {
|
|||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
expectation;
|
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
|
matchersUtil: matchersUtil,
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
customAsyncMatchers: matchers,
|
||||||
matchersUtil: matchersUtil,
|
actual: 'an actual',
|
||||||
customAsyncMatchers: matchers,
|
addExpectationResult: addExpectationResult
|
||||||
actual: 'an actual',
|
});
|
||||||
addExpectationResult: addExpectationResult
|
|
||||||
});
|
|
||||||
|
|
||||||
return expectation.toFoo('hello').then(function() {
|
return expectation.toFoo('hello').then(function() {
|
||||||
expect(fakeCompare).toHaveBeenCalledWith('an actual', 'hello');
|
expect(fakeCompare).toHaveBeenCalledWith('an actual', 'hello');
|
||||||
@@ -282,7 +276,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a passing result to the spec when the comparison passes', function() {
|
it('reports a passing result to the spec when the comparison passes', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -295,14 +289,13 @@ describe('AsyncExpectation', function() {
|
|||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -323,7 +316,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result to the spec when the comparison fails', function() {
|
it('reports a failing result to the spec when the comparison fails', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -338,14 +331,13 @@ describe('AsyncExpectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -366,7 +358,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result and a custom fail message to the spec when the comparison fails', function() {
|
it('reports a failing result and a custom fail message to the spec when the comparison fails', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -379,14 +371,13 @@ describe('AsyncExpectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -406,7 +397,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result with a custom fail message function to the spec when the comparison fails', function() {
|
it('reports a failing result with a custom fail message function to the spec when the comparison fails', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -421,14 +412,13 @@ describe('AsyncExpectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -448,7 +438,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a passing result to the spec when the comparison fails for a negative expectation', function() {
|
it('reports a passing result to the spec when the comparison fails for a negative expectation', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -459,14 +449,13 @@ describe('AsyncExpectation', function() {
|
|||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual',
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -486,7 +475,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result to the spec when the comparison passes for a negative expectation', function() {
|
it('reports a failing result to the spec when the comparison passes for a negative expectation', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -502,14 +491,13 @@ describe('AsyncExpectation', function() {
|
|||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual',
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
@@ -530,7 +518,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result and a custom fail message to the spec when the comparison passes for a negative expectation', function() {
|
it('reports a failing result and a custom fail message to the spec when the comparison passes for a negative expectation', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -544,14 +532,13 @@ describe('AsyncExpectation', function() {
|
|||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual',
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -571,7 +558,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a passing result to the spec when the 'not' comparison passes, given a negativeCompare", function() {
|
it("reports a passing result to the spec when the 'not' comparison passes, given a negativeCompare", function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -585,14 +572,13 @@ describe('AsyncExpectation', function() {
|
|||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual',
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -612,7 +598,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a failing result and a custom fail message to the spec when the 'not' comparison fails, given a negativeCompare", function() {
|
it("reports a failing result and a custom fail message to the spec when the 'not' comparison fails, given a negativeCompare", function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -629,14 +615,13 @@ describe('AsyncExpectation', function() {
|
|||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual',
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -656,8 +641,8 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports errorWithStack when a custom error message is returned', function() {
|
it('reports errorWithStack when a custom error message is returned', function() {
|
||||||
var customError = new Error('I am a custom error');
|
const customError = new Error('I am a custom error');
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -671,14 +656,13 @@ describe('AsyncExpectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -698,7 +682,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a custom message to the spec when a 'not' comparison fails", function() {
|
it("reports a custom message to the spec when a 'not' comparison fails", function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -711,14 +695,13 @@ describe('AsyncExpectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -738,7 +721,7 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a custom message func to the spec when a 'not' comparison fails", function() {
|
it("reports a custom message func to the spec when a 'not' comparison fails", function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -753,14 +736,13 @@ describe('AsyncExpectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
errorWithStack = new Error('errorWithStack'),
|
errorWithStack = new Error('errorWithStack');
|
||||||
expectation;
|
|
||||||
|
|
||||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||||
errorWithStack
|
errorWithStack
|
||||||
);
|
);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
let expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customAsyncMatchers: matchers,
|
customAsyncMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -781,6 +763,6 @@ describe('AsyncExpectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function dummyPromise() {
|
function dummyPromise() {
|
||||||
return new Promise(function(resolve, reject) {});
|
return new Promise(function() {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('CallTracker', function() {
|
describe('CallTracker', function() {
|
||||||
it('tracks that it was called when executed', function() {
|
it('tracks that it was called when executed', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
expect(callTracker.any()).toBe(false);
|
expect(callTracker.any()).toBe(false);
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('tracks that number of times that it is executed', function() {
|
it('tracks that number of times that it is executed', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
expect(callTracker.count()).toEqual(0);
|
expect(callTracker.count()).toEqual(0);
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the params from each execution', function() {
|
it('tracks the params from each execution', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
callTracker.track({ object: void 0, args: [] });
|
callTracker.track({ object: void 0, args: [] });
|
||||||
callTracker.track({ object: {}, args: [0, 'foo'] });
|
callTracker.track({ object: {}, args: [0, 'foo'] });
|
||||||
@@ -31,9 +31,9 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("tracks the 'this' object from each execution", function() {
|
it("tracks the 'this' object from each execution", function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
var this0 = {},
|
const this0 = {},
|
||||||
this1 = {};
|
this1 = {};
|
||||||
callTracker.track({ object: this0, args: [] });
|
callTracker.track({ object: this0, args: [] });
|
||||||
callTracker.track({ object: this1, args: [] });
|
callTracker.track({ object: this1, args: [] });
|
||||||
@@ -45,13 +45,13 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns any empty array when there was no call', function() {
|
it('returns any empty array when there was no call', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
expect(callTracker.argsFor(0)).toEqual([]);
|
expect(callTracker.argsFor(0)).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows access for the arguments for all calls', function() {
|
it('allows access for the arguments for all calls', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
callTracker.track({ object: {}, args: [] });
|
callTracker.track({ object: {}, args: [] });
|
||||||
callTracker.track({ object: {}, args: [0, 'foo'] });
|
callTracker.track({ object: {}, args: [0, 'foo'] });
|
||||||
@@ -60,7 +60,7 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the context and arguments for each call', function() {
|
it('tracks the context and arguments for each call', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
callTracker.track({ object: {}, args: [] });
|
callTracker.track({ object: {}, args: [] });
|
||||||
callTracker.track({ object: {}, args: [0, 'foo'] });
|
callTracker.track({ object: {}, args: [0, 'foo'] });
|
||||||
@@ -71,7 +71,7 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('simplifies access to the arguments for the last (most recent) call', function() {
|
it('simplifies access to the arguments for the last (most recent) call', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
callTracker.track();
|
callTracker.track();
|
||||||
callTracker.track({ object: {}, args: [0, 'foo'] });
|
callTracker.track({ object: {}, args: [0, 'foo'] });
|
||||||
@@ -83,13 +83,13 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns a useful falsy value when there isn't a last (most recent) call", function() {
|
it("returns a useful falsy value when there isn't a last (most recent) call", function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
expect(callTracker.mostRecent()).toBeFalsy();
|
expect(callTracker.mostRecent()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('simplifies access to the arguments for the first (oldest) call', function() {
|
it('simplifies access to the arguments for the first (oldest) call', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
callTracker.track({ object: {}, args: [0, 'foo'] });
|
callTracker.track({ object: {}, args: [0, 'foo'] });
|
||||||
|
|
||||||
@@ -97,13 +97,13 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns a useful falsy value when there isn't a first (oldest) call", function() {
|
it("returns a useful falsy value when there isn't a first (oldest) call", function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
expect(callTracker.first()).toBeFalsy();
|
expect(callTracker.first()).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows the tracking to be reset', function() {
|
it('allows the tracking to be reset', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
|
|
||||||
callTracker.track();
|
callTracker.track();
|
||||||
callTracker.track({ object: {}, args: [0, 'foo'] });
|
callTracker.track({ object: {}, args: [0, 'foo'] });
|
||||||
@@ -117,10 +117,10 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows object arguments to be shallow cloned', function() {
|
it('allows object arguments to be shallow cloned', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker();
|
const callTracker = new jasmineUnderTest.CallTracker();
|
||||||
callTracker.saveArgumentsByValue();
|
callTracker.saveArgumentsByValue();
|
||||||
|
|
||||||
var objectArg = { foo: 'bar' },
|
const objectArg = { foo: 'bar' },
|
||||||
arrayArg = ['foo', 'bar'];
|
arrayArg = ['foo', 'bar'];
|
||||||
|
|
||||||
callTracker.track({
|
callTracker.track({
|
||||||
@@ -135,7 +135,7 @@ describe('CallTracker', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('saves primitive arguments by value', function() {
|
it('saves primitive arguments by value', function() {
|
||||||
var callTracker = new jasmineUnderTest.CallTracker(),
|
const callTracker = new jasmineUnderTest.CallTracker(),
|
||||||
args = [undefined, null, false, '', /\s/, 0, 1.2, NaN];
|
args = [undefined, null, false, '', /\s/, 0, 1.2, NaN];
|
||||||
|
|
||||||
callTracker.saveArgumentsByValue();
|
callTracker.saveArgumentsByValue();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('ClearStack', function() {
|
describe('ClearStack', function() {
|
||||||
it('works in an integrationy way', function(done) {
|
it('works in an integrationy way', function(done) {
|
||||||
var clearStack = jasmineUnderTest.getClearStack(
|
const clearStack = jasmineUnderTest.getClearStack(
|
||||||
jasmineUnderTest.getGlobal()
|
jasmineUnderTest.getGlobal()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -9,158 +9,216 @@ describe('ClearStack', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses setImmediate when available', function() {
|
describe('in Safari', function() {
|
||||||
var setImmediate = jasmine
|
usesQueueMicrotaskWithSetTimeout(function() {
|
||||||
.createSpy('setImmediate')
|
return {
|
||||||
.and.callFake(function(fn) {
|
navigator: {
|
||||||
|
userAgent:
|
||||||
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.0.8 (KHTML, like Gecko) Version/15.1 Safari/605.0.8'
|
||||||
|
},
|
||||||
|
// queueMicrotask should be used even though MessageChannel is present
|
||||||
|
MessageChannel: fakeMessageChannel
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('in browsers other than Safari', function() {
|
||||||
|
usesMessageChannel(function() {
|
||||||
|
return {
|
||||||
|
navigator: {
|
||||||
|
// Chrome's user agent string contains "Safari" so it's a good test case
|
||||||
|
userAgent:
|
||||||
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when MessageChannel is unavailable', function() {
|
||||||
|
usesQueueMicrotaskWithSetTimeout(function() {
|
||||||
|
return {
|
||||||
|
navigator: {
|
||||||
|
userAgent: 'CERN-LineMode/2.15 libwww/2.17b3',
|
||||||
|
MessageChannel: undefined
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('in Node', function() {
|
||||||
|
usesQueueMicrotaskWithoutSetTimeout(function() {
|
||||||
|
return {
|
||||||
|
process: {
|
||||||
|
versions: {
|
||||||
|
node: '3.1415927'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function usesMessageChannel(makeGlobal) {
|
||||||
|
it('uses MessageChannel', function() {
|
||||||
|
const global = {
|
||||||
|
...makeGlobal(),
|
||||||
|
MessageChannel: fakeMessageChannel
|
||||||
|
};
|
||||||
|
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||||
|
let called = false;
|
||||||
|
|
||||||
|
clearStack(function() {
|
||||||
|
called = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(called).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses setTimeout instead of MessageChannel every 10 calls to make sure we release the CPU', function() {
|
||||||
|
const fakeChannel = fakeMessageChannel();
|
||||||
|
spyOn(fakeChannel.port2, 'postMessage');
|
||||||
|
const setTimeout = jasmine.createSpy('setTimeout');
|
||||||
|
const global = {
|
||||||
|
...makeGlobal(),
|
||||||
|
setTimeout,
|
||||||
|
MessageChannel: function() {
|
||||||
|
return fakeChannel;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||||
|
|
||||||
|
for (let i = 0; i < 9; i++) {
|
||||||
|
clearStack(function() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(fakeChannel.port2.postMessage).toHaveBeenCalled();
|
||||||
|
expect(setTimeout).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
clearStack(function() {});
|
||||||
|
expect(fakeChannel.port2.postMessage).toHaveBeenCalledTimes(9);
|
||||||
|
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
clearStack(function() {});
|
||||||
|
expect(fakeChannel.port2.postMessage).toHaveBeenCalledTimes(10);
|
||||||
|
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calls setTimeout when onmessage is called recursively', function() {
|
||||||
|
const setTimeout = jasmine.createSpy('setTimeout');
|
||||||
|
const global = {
|
||||||
|
...makeGlobal(),
|
||||||
|
setTimeout,
|
||||||
|
MessageChannel: fakeMessageChannel
|
||||||
|
};
|
||||||
|
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||||
|
const fn = jasmine.createSpy('second clearStack function');
|
||||||
|
|
||||||
|
clearStack(function() {
|
||||||
|
clearStack(fn);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fn).not.toHaveBeenCalled();
|
||||||
|
expect(setTimeout).toHaveBeenCalledWith(fn, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function usesQueueMicrotaskWithSetTimeout(makeGlobal) {
|
||||||
|
it('uses queueMicrotask', function() {
|
||||||
|
const global = {
|
||||||
|
...makeGlobal(),
|
||||||
|
queueMicrotask: function(fn) {
|
||||||
fn();
|
fn();
|
||||||
}),
|
}
|
||||||
global = { setImmediate: setImmediate },
|
};
|
||||||
clearStack = jasmineUnderTest.getClearStack(global),
|
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||||
called = false;
|
let called = false;
|
||||||
|
|
||||||
clearStack(function() {
|
clearStack(function() {
|
||||||
called = true;
|
called = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(called).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(called).toBe(true);
|
it('uses setTimeout instead of queueMicrotask every 10 calls to make sure we release the CPU', function() {
|
||||||
expect(setImmediate).toHaveBeenCalled();
|
const queueMicrotask = jasmine.createSpy('queueMicrotask');
|
||||||
});
|
const setTimeout = jasmine.createSpy('setTimeout');
|
||||||
|
const global = {
|
||||||
|
...makeGlobal(),
|
||||||
|
queueMicrotask,
|
||||||
|
setTimeout
|
||||||
|
};
|
||||||
|
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||||
|
|
||||||
it('uses setTimeout instead of setImmediate every 10 calls to make sure we release the CPU', function() {
|
for (let i = 0; i < 9; i++) {
|
||||||
var setImmediate = jasmine.createSpy('setImmediate'),
|
clearStack(function() {});
|
||||||
setTimeout = jasmine.createSpy('setTimeout'),
|
}
|
||||||
global = { setImmediate: setImmediate, setTimeout: setTimeout },
|
|
||||||
clearStack = jasmineUnderTest.getClearStack(global);
|
|
||||||
|
|
||||||
clearStack(function() {});
|
expect(queueMicrotask).toHaveBeenCalled();
|
||||||
clearStack(function() {});
|
expect(setTimeout).not.toHaveBeenCalled();
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
|
|
||||||
expect(setImmediate).toHaveBeenCalled();
|
clearStack(function() {});
|
||||||
expect(setTimeout).not.toHaveBeenCalled();
|
expect(queueMicrotask).toHaveBeenCalledTimes(9);
|
||||||
|
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
clearStack(function() {});
|
clearStack(function() {});
|
||||||
expect(setImmediate.calls.count()).toEqual(9);
|
expect(queueMicrotask).toHaveBeenCalledTimes(10);
|
||||||
expect(setTimeout.calls.count()).toEqual(1);
|
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
clearStack(function() {});
|
function usesQueueMicrotaskWithoutSetTimeout(makeGlobal) {
|
||||||
expect(setImmediate.calls.count()).toEqual(10);
|
it('uses queueMicrotask', function() {
|
||||||
expect(setTimeout.calls.count()).toEqual(1);
|
const global = {
|
||||||
});
|
...makeGlobal(),
|
||||||
|
queueMicrotask: function(fn) {
|
||||||
it('uses MessageChannels when available', function() {
|
fn();
|
||||||
var fakeChannel = {
|
|
||||||
port1: {},
|
|
||||||
port2: {
|
|
||||||
postMessage: function() {
|
|
||||||
fakeChannel.port1.onmessage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
global = {
|
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||||
MessageChannel: function() {
|
let called = false;
|
||||||
return fakeChannel;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
clearStack = jasmineUnderTest.getClearStack(global),
|
|
||||||
called = false;
|
|
||||||
|
|
||||||
clearStack(function() {
|
clearStack(function() {
|
||||||
called = true;
|
called = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(called).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(called).toBe(true);
|
it('does not use setTimeout', function() {
|
||||||
});
|
const queueMicrotask = jasmine.createSpy('queueMicrotask');
|
||||||
|
const setTimeout = jasmine.createSpy('setTimeout');
|
||||||
|
const global = {
|
||||||
|
...makeGlobal(),
|
||||||
|
queueMicrotask,
|
||||||
|
setTimeout
|
||||||
|
};
|
||||||
|
const clearStack = jasmineUnderTest.getClearStack(global);
|
||||||
|
|
||||||
it('uses setTimeout instead of MessageChannel every 10 calls to make sure we release the CPU', function() {
|
clearStack(function() {});
|
||||||
var fakeChannel = {
|
clearStack(function() {});
|
||||||
port1: {},
|
clearStack(function() {});
|
||||||
port2: {
|
clearStack(function() {});
|
||||||
postMessage: jasmine
|
clearStack(function() {});
|
||||||
.createSpy('postMessage')
|
clearStack(function() {});
|
||||||
.and.callFake(function() {
|
clearStack(function() {});
|
||||||
fakeChannel.port1.onmessage();
|
clearStack(function() {});
|
||||||
})
|
clearStack(function() {});
|
||||||
}
|
clearStack(function() {});
|
||||||
},
|
|
||||||
setTimeout = jasmine.createSpy('setTimeout'),
|
|
||||||
global = {
|
|
||||||
MessageChannel: function() {
|
|
||||||
return fakeChannel;
|
|
||||||
},
|
|
||||||
setTimeout: setTimeout
|
|
||||||
},
|
|
||||||
clearStack = jasmineUnderTest.getClearStack(global);
|
|
||||||
|
|
||||||
clearStack(function() {});
|
expect(queueMicrotask).toHaveBeenCalledTimes(10);
|
||||||
clearStack(function() {});
|
expect(setTimeout).not.toHaveBeenCalled();
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
clearStack(function() {});
|
|
||||||
|
|
||||||
expect(fakeChannel.port2.postMessage).toHaveBeenCalled();
|
|
||||||
expect(setTimeout).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
clearStack(function() {});
|
|
||||||
expect(fakeChannel.port2.postMessage.calls.count()).toEqual(9);
|
|
||||||
expect(setTimeout.calls.count()).toEqual(1);
|
|
||||||
|
|
||||||
clearStack(function() {});
|
|
||||||
expect(fakeChannel.port2.postMessage.calls.count()).toEqual(10);
|
|
||||||
expect(setTimeout.calls.count()).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls setTimeout when onmessage is called recursively', function() {
|
|
||||||
var fakeChannel = {
|
|
||||||
port1: {},
|
|
||||||
port2: {
|
|
||||||
postMessage: function() {
|
|
||||||
fakeChannel.port1.onmessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setTimeout = jasmine.createSpy('setTimeout'),
|
|
||||||
global = {
|
|
||||||
MessageChannel: function() {
|
|
||||||
return fakeChannel;
|
|
||||||
},
|
|
||||||
setTimeout: setTimeout
|
|
||||||
},
|
|
||||||
clearStack = jasmineUnderTest.getClearStack(global),
|
|
||||||
fn = jasmine.createSpy('second clearStack function');
|
|
||||||
|
|
||||||
clearStack(function() {
|
|
||||||
clearStack(fn);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
expect(fn).not.toHaveBeenCalled();
|
function fakeMessageChannel() {
|
||||||
expect(setTimeout).toHaveBeenCalledWith(fn, 0);
|
const channel = {
|
||||||
});
|
port1: {},
|
||||||
|
port2: {
|
||||||
it('falls back to setTimeout', function() {
|
postMessage: function() {
|
||||||
var setTimeout = jasmine.createSpy('setTimeout').and.callFake(function(fn) {
|
channel.port1.onmessage();
|
||||||
fn();
|
}
|
||||||
}),
|
}
|
||||||
global = { setTimeout: setTimeout },
|
};
|
||||||
clearStack = jasmineUnderTest.getClearStack(global),
|
return channel;
|
||||||
called = false;
|
}
|
||||||
|
|
||||||
clearStack(function() {
|
|
||||||
called = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(called).toBe(true);
|
|
||||||
expect(setTimeout).toHaveBeenCalledWith(jasmine.any(Function), 0);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
describe('Clock', function() {
|
describe('Clock', function() {
|
||||||
var NODE_JS =
|
const NODE_JS =
|
||||||
typeof process !== 'undefined' &&
|
typeof process !== 'undefined' &&
|
||||||
process.versions &&
|
process.versions &&
|
||||||
typeof process.versions.node === 'string';
|
typeof process.versions.node === 'string';
|
||||||
|
|
||||||
it('does not replace setTimeout until it is installed', function() {
|
it('does not replace setTimeout until it is installed', function() {
|
||||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||||
'delayedFunctionScheduler',
|
'delayedFunctionScheduler',
|
||||||
@@ -40,7 +40,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not replace clearTimeout until it is installed', function() {
|
it('does not replace clearTimeout until it is installed', function() {
|
||||||
var fakeClearTimeout = jasmine.createSpy('global cleartimeout'),
|
const fakeClearTimeout = jasmine.createSpy('global cleartimeout'),
|
||||||
fakeGlobal = { clearTimeout: fakeClearTimeout },
|
fakeGlobal = { clearTimeout: fakeClearTimeout },
|
||||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||||
'delayedFunctionScheduler',
|
'delayedFunctionScheduler',
|
||||||
@@ -76,7 +76,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not replace setInterval until it is installed', function() {
|
it('does not replace setInterval until it is installed', function() {
|
||||||
var fakeSetInterval = jasmine.createSpy('global setInterval'),
|
const fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||||
fakeGlobal = { setInterval: fakeSetInterval },
|
fakeGlobal = { setInterval: fakeSetInterval },
|
||||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||||
'delayedFunctionScheduler',
|
'delayedFunctionScheduler',
|
||||||
@@ -111,7 +111,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not replace clearInterval until it is installed', function() {
|
it('does not replace clearInterval until it is installed', function() {
|
||||||
var fakeClearInterval = jasmine.createSpy('global clearinterval'),
|
const fakeClearInterval = jasmine.createSpy('global clearinterval'),
|
||||||
fakeGlobal = { clearInterval: fakeClearInterval },
|
fakeGlobal = { clearInterval: fakeClearInterval },
|
||||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||||
'delayedFunctionScheduler',
|
'delayedFunctionScheduler',
|
||||||
@@ -147,7 +147,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not install if the current setTimeout is not the original function on the global', function() {
|
it('does not install if the current setTimeout is not the original function on the global', function() {
|
||||||
var originalFakeSetTimeout = function() {},
|
const originalFakeSetTimeout = function() {},
|
||||||
replacedSetTimeout = function() {},
|
replacedSetTimeout = function() {},
|
||||||
fakeGlobal = { setTimeout: originalFakeSetTimeout },
|
fakeGlobal = { setTimeout: originalFakeSetTimeout },
|
||||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||||
@@ -171,7 +171,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not install if the current clearTimeout is not the original function on the global', function() {
|
it('does not install if the current clearTimeout is not the original function on the global', function() {
|
||||||
var originalFakeClearTimeout = function() {},
|
const originalFakeClearTimeout = function() {},
|
||||||
replacedClearTimeout = function() {},
|
replacedClearTimeout = function() {},
|
||||||
fakeGlobal = { clearTimeout: originalFakeClearTimeout },
|
fakeGlobal = { clearTimeout: originalFakeClearTimeout },
|
||||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||||
@@ -195,7 +195,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not install if the current setInterval is not the original function on the global', function() {
|
it('does not install if the current setInterval is not the original function on the global', function() {
|
||||||
var originalFakeSetInterval = function() {},
|
const originalFakeSetInterval = function() {},
|
||||||
replacedSetInterval = function() {},
|
replacedSetInterval = function() {},
|
||||||
fakeGlobal = { setInterval: originalFakeSetInterval },
|
fakeGlobal = { setInterval: originalFakeSetInterval },
|
||||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||||
@@ -219,7 +219,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not install if the current clearInterval is not the original function on the global', function() {
|
it('does not install if the current clearInterval is not the original function on the global', function() {
|
||||||
var originalFakeClearInterval = function() {},
|
const originalFakeClearInterval = function() {},
|
||||||
replacedClearInterval = function() {},
|
replacedClearInterval = function() {},
|
||||||
fakeGlobal = { clearInterval: originalFakeClearInterval },
|
fakeGlobal = { clearInterval: originalFakeClearInterval },
|
||||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||||
@@ -243,7 +243,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('replaces the global timer functions on uninstall', function() {
|
it('replaces the global timer functions on uninstall', function() {
|
||||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||||
@@ -286,7 +286,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can be installed for the duration of a passed in function and uninstalled when done', function() {
|
it('can be installed for the duration of a passed in function and uninstalled when done', function() {
|
||||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||||
@@ -312,8 +312,8 @@ describe('Clock', function() {
|
|||||||
return delayedFunctionScheduler;
|
return delayedFunctionScheduler;
|
||||||
},
|
},
|
||||||
mockDate
|
mockDate
|
||||||
),
|
);
|
||||||
passedFunctionCalled = false;
|
let passedFunctionCalled = false;
|
||||||
|
|
||||||
clock.withMock(function() {
|
clock.withMock(function() {
|
||||||
fakeGlobal.setTimeout(delayedFn, 0);
|
fakeGlobal.setTimeout(delayedFn, 0);
|
||||||
@@ -346,7 +346,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can be installed for the duration of a passed in function and uninstalled if an error is thrown', function() {
|
it('can be installed for the duration of a passed in function and uninstalled if an error is thrown', function() {
|
||||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||||
@@ -372,8 +372,8 @@ describe('Clock', function() {
|
|||||||
return delayedFunctionScheduler;
|
return delayedFunctionScheduler;
|
||||||
},
|
},
|
||||||
mockDate
|
mockDate
|
||||||
),
|
);
|
||||||
passedFunctionCalled = false;
|
let passedFunctionCalled = false;
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
clock.withMock(function() {
|
clock.withMock(function() {
|
||||||
@@ -409,7 +409,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('schedules the delayed function (via setTimeout) with the fake timer', function() {
|
it('schedules the delayed function (via setTimeout) with the fake timer', function() {
|
||||||
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
const fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||||
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
||||||
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
||||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||||
@@ -451,7 +451,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an id for the delayed function', function() {
|
it('returns an id for the delayed function', function() {
|
||||||
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
const fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||||
scheduleId = 123,
|
scheduleId = 123,
|
||||||
scheduleFunction = jasmine
|
scheduleFunction = jasmine
|
||||||
.createSpy('scheduleFunction')
|
.createSpy('scheduleFunction')
|
||||||
@@ -470,11 +470,10 @@ describe('Clock', function() {
|
|||||||
return delayedFunctionScheduler;
|
return delayedFunctionScheduler;
|
||||||
},
|
},
|
||||||
mockDate
|
mockDate
|
||||||
),
|
);
|
||||||
timeout;
|
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
timeout = clock.setTimeout(delayedFn, 0);
|
const timeout = clock.setTimeout(delayedFn, 0);
|
||||||
|
|
||||||
if (!NODE_JS) {
|
if (!NODE_JS) {
|
||||||
expect(timeout).toEqual(123);
|
expect(timeout).toEqual(123);
|
||||||
@@ -484,7 +483,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('clears the scheduled function with the scheduler', function() {
|
it('clears the scheduled function with the scheduler', function() {
|
||||||
var fakeClearTimeout = jasmine.createSpy('clearTimeout'),
|
const fakeClearTimeout = jasmine.createSpy('clearTimeout'),
|
||||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||||
'delayedFunctionScheduler',
|
'delayedFunctionScheduler',
|
||||||
['removeFunctionWithId']
|
['removeFunctionWithId']
|
||||||
@@ -513,7 +512,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('schedules the delayed function with the fake timer', function() {
|
it('schedules the delayed function with the fake timer', function() {
|
||||||
var fakeSetInterval = jasmine.createSpy('setInterval'),
|
const fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||||
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
||||||
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
||||||
fakeGlobal = { setInterval: fakeSetInterval },
|
fakeGlobal = { setInterval: fakeSetInterval },
|
||||||
@@ -556,7 +555,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an id for the delayed function', function() {
|
it('returns an id for the delayed function', function() {
|
||||||
var fakeSetInterval = jasmine.createSpy('setInterval'),
|
const fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||||
scheduleId = 123,
|
scheduleId = 123,
|
||||||
scheduleFunction = jasmine
|
scheduleFunction = jasmine
|
||||||
.createSpy('scheduleFunction')
|
.createSpy('scheduleFunction')
|
||||||
@@ -575,11 +574,10 @@ describe('Clock', function() {
|
|||||||
return delayedFunctionScheduler;
|
return delayedFunctionScheduler;
|
||||||
},
|
},
|
||||||
mockDate
|
mockDate
|
||||||
),
|
);
|
||||||
interval;
|
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
interval = clock.setInterval(delayedFn, 0);
|
const interval = clock.setInterval(delayedFn, 0);
|
||||||
|
|
||||||
if (!NODE_JS) {
|
if (!NODE_JS) {
|
||||||
expect(interval).toEqual(123);
|
expect(interval).toEqual(123);
|
||||||
@@ -589,7 +587,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('clears the scheduled function with the scheduler', function() {
|
it('clears the scheduled function with the scheduler', function() {
|
||||||
var clearInterval = jasmine.createSpy('clearInterval'),
|
const clearInterval = jasmine.createSpy('clearInterval'),
|
||||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||||
'delayedFunctionScheduler',
|
'delayedFunctionScheduler',
|
||||||
['removeFunctionWithId']
|
['removeFunctionWithId']
|
||||||
@@ -618,7 +616,7 @@ describe('Clock', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('gives you a friendly reminder if the Clock is not installed and you tick', function() {
|
it('gives you a friendly reminder if the Clock is not installed and you tick', function() {
|
||||||
var clock = new jasmineUnderTest.Clock(
|
const clock = new jasmineUnderTest.Clock(
|
||||||
{},
|
{},
|
||||||
jasmine.createSpyObj('delayedFunctionScheduler', ['tick'])
|
jasmine.createSpyObj('delayedFunctionScheduler', ['tick'])
|
||||||
);
|
);
|
||||||
@@ -630,7 +628,7 @@ describe('Clock', function() {
|
|||||||
|
|
||||||
describe('Clock (acceptance)', function() {
|
describe('Clock (acceptance)', function() {
|
||||||
it('can run setTimeouts/setIntervals synchronously', function() {
|
it('can run setTimeouts/setIntervals synchronously', function() {
|
||||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||||
delayedFn3 = jasmine.createSpy('delayedFn3'),
|
delayedFn3 = jasmine.createSpy('delayedFn3'),
|
||||||
recurring1 = jasmine.createSpy('recurring1'),
|
recurring1 = jasmine.createSpy('recurring1'),
|
||||||
@@ -651,7 +649,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
clock.setTimeout(delayedFn1, 0);
|
clock.setTimeout(delayedFn1, 0);
|
||||||
var intervalId = clock.setInterval(recurring1, 50);
|
const intervalId = clock.setInterval(recurring1, 50);
|
||||||
clock.setTimeout(delayedFn2, 100);
|
clock.setTimeout(delayedFn2, 100);
|
||||||
clock.setTimeout(delayedFn3, 200);
|
clock.setTimeout(delayedFn3, 200);
|
||||||
|
|
||||||
@@ -690,7 +688,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can clear a previously set timeout', function() {
|
it('can clear a previously set timeout', function() {
|
||||||
var clearedFn = jasmine.createSpy('clearedFn'),
|
const clearedFn = jasmine.createSpy('clearedFn'),
|
||||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
mockDate = {
|
mockDate = {
|
||||||
install: function() {},
|
install: function() {},
|
||||||
@@ -703,12 +701,11 @@ describe('Clock (acceptance)', function() {
|
|||||||
return delayedFunctionScheduler;
|
return delayedFunctionScheduler;
|
||||||
},
|
},
|
||||||
mockDate
|
mockDate
|
||||||
),
|
);
|
||||||
timeoutId;
|
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
timeoutId = clock.setTimeout(clearedFn, 100);
|
const timeoutId = clock.setTimeout(clearedFn, 100);
|
||||||
expect(clearedFn).not.toHaveBeenCalled();
|
expect(clearedFn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
clock.clearTimeout(timeoutId);
|
clock.clearTimeout(timeoutId);
|
||||||
@@ -718,7 +715,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("can clear a previously set interval using that interval's handler", function() {
|
it("can clear a previously set interval using that interval's handler", function() {
|
||||||
var spy = jasmine.createSpy('spy'),
|
const spy = jasmine.createSpy('spy'),
|
||||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
mockDate = {
|
mockDate = {
|
||||||
install: function() {},
|
install: function() {},
|
||||||
@@ -731,12 +728,11 @@ describe('Clock (acceptance)', function() {
|
|||||||
return delayedFunctionScheduler;
|
return delayedFunctionScheduler;
|
||||||
},
|
},
|
||||||
mockDate
|
mockDate
|
||||||
),
|
);
|
||||||
intervalId;
|
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
intervalId = clock.setInterval(function() {
|
const intervalId = clock.setInterval(function() {
|
||||||
spy();
|
spy();
|
||||||
clock.clearInterval(intervalId);
|
clock.clearInterval(intervalId);
|
||||||
}, 100);
|
}, 100);
|
||||||
@@ -746,7 +742,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly schedules functions after the Clock has advanced', function() {
|
it('correctly schedules functions after the Clock has advanced', function() {
|
||||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
mockDate = {
|
mockDate = {
|
||||||
install: function() {},
|
install: function() {},
|
||||||
@@ -772,7 +768,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly schedules functions while the Clock is advancing', function() {
|
it('correctly schedules functions while the Clock is advancing', function() {
|
||||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
mockDate = {
|
mockDate = {
|
||||||
@@ -803,7 +799,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly calls functions scheduled while the Clock is advancing', function() {
|
it('correctly calls functions scheduled while the Clock is advancing', function() {
|
||||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
mockDate = {
|
mockDate = {
|
||||||
@@ -831,7 +827,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly schedules functions scheduled while the Clock is advancing but after the Clock is uninstalled', function() {
|
it('correctly schedules functions scheduled while the Clock is advancing but after the Clock is uninstalled', function() {
|
||||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
mockDate = {
|
mockDate = {
|
||||||
@@ -865,7 +861,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not mock the Date object by default', function() {
|
it('does not mock the Date object by default', function() {
|
||||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
global = { Date: Date },
|
global = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(global),
|
mockDate = new jasmineUnderTest.MockDate(global),
|
||||||
clock = new jasmineUnderTest.Clock(
|
clock = new jasmineUnderTest.Clock(
|
||||||
@@ -880,7 +876,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
|
|
||||||
expect(global.Date).toEqual(Date);
|
expect(global.Date).toEqual(Date);
|
||||||
|
|
||||||
var now = new global.Date().getTime();
|
const now = new global.Date().getTime();
|
||||||
|
|
||||||
clock.tick(50);
|
clock.tick(50);
|
||||||
|
|
||||||
@@ -888,7 +884,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('mocks the Date object and sets it to current time', function() {
|
it('mocks the Date object and sets it to current time', function() {
|
||||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
global = { Date: Date },
|
global = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(global),
|
mockDate = new jasmineUnderTest.MockDate(global),
|
||||||
clock = new jasmineUnderTest.Clock(
|
clock = new jasmineUnderTest.Clock(
|
||||||
@@ -901,13 +897,13 @@ describe('Clock (acceptance)', function() {
|
|||||||
|
|
||||||
clock.install().mockDate();
|
clock.install().mockDate();
|
||||||
|
|
||||||
var now = new global.Date().getTime();
|
const now = new global.Date().getTime();
|
||||||
|
|
||||||
clock.tick(50);
|
clock.tick(50);
|
||||||
|
|
||||||
expect(new global.Date().getTime() - now).toEqual(50);
|
expect(new global.Date().getTime() - now).toEqual(50);
|
||||||
|
|
||||||
var timeoutDate = 0;
|
let timeoutDate = 0;
|
||||||
clock.setTimeout(function() {
|
clock.setTimeout(function() {
|
||||||
timeoutDate = new global.Date().getTime();
|
timeoutDate = new global.Date().getTime();
|
||||||
}, 100);
|
}, 100);
|
||||||
@@ -918,7 +914,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('mocks the Date object and sets it to a given time', function() {
|
it('mocks the Date object and sets it to a given time', function() {
|
||||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
global = { Date: Date },
|
global = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(global),
|
mockDate = new jasmineUnderTest.MockDate(global),
|
||||||
clock = new jasmineUnderTest.Clock(
|
clock = new jasmineUnderTest.Clock(
|
||||||
@@ -932,7 +928,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
|
|
||||||
clock.install().mockDate(baseTime);
|
clock.install().mockDate(baseTime);
|
||||||
|
|
||||||
var now = new global.Date().getTime();
|
const now = new global.Date().getTime();
|
||||||
|
|
||||||
expect(now).toEqual(baseTime.getTime());
|
expect(now).toEqual(baseTime.getTime());
|
||||||
|
|
||||||
@@ -940,7 +936,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
|
|
||||||
expect(new global.Date().getTime()).toEqual(baseTime.getTime() + 50);
|
expect(new global.Date().getTime()).toEqual(baseTime.getTime() + 50);
|
||||||
|
|
||||||
var timeoutDate = 0;
|
let timeoutDate = 0;
|
||||||
clock.setTimeout(function() {
|
clock.setTimeout(function() {
|
||||||
timeoutDate = new global.Date().getTime();
|
timeoutDate = new global.Date().getTime();
|
||||||
}, 100);
|
}, 100);
|
||||||
@@ -951,7 +947,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws mockDate is called with a non-Date', function() {
|
it('throws mockDate is called with a non-Date', function() {
|
||||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
global = { Date: Date },
|
global = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(global),
|
mockDate = new jasmineUnderTest.MockDate(global),
|
||||||
clock = new jasmineUnderTest.Clock(
|
clock = new jasmineUnderTest.Clock(
|
||||||
@@ -960,8 +956,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
return delayedFunctionScheduler;
|
return delayedFunctionScheduler;
|
||||||
},
|
},
|
||||||
mockDate
|
mockDate
|
||||||
),
|
);
|
||||||
env = jasmineUnderTest.getEnv();
|
|
||||||
|
|
||||||
expect(() => clock.mockDate(12345)).toThrowError(
|
expect(() => clock.mockDate(12345)).toThrowError(
|
||||||
'The argument to jasmine.clock().mockDate(), if specified, should be ' +
|
'The argument to jasmine.clock().mockDate(), if specified, should be ' +
|
||||||
@@ -970,7 +965,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('mocks the Date object and updates the date per delayed function', function() {
|
it('mocks the Date object and updates the date per delayed function', function() {
|
||||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
global = { Date: Date },
|
global = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(global),
|
mockDate = new jasmineUnderTest.MockDate(global),
|
||||||
clock = new jasmineUnderTest.Clock(
|
clock = new jasmineUnderTest.Clock(
|
||||||
@@ -984,8 +979,8 @@ describe('Clock (acceptance)', function() {
|
|||||||
|
|
||||||
clock.install().mockDate(baseTime);
|
clock.install().mockDate(baseTime);
|
||||||
|
|
||||||
var actualTimes = [];
|
const actualTimes = [];
|
||||||
var pushCurrentTime = function() {
|
const pushCurrentTime = function() {
|
||||||
actualTimes.push(global.Date().getTime());
|
actualTimes.push(global.Date().getTime());
|
||||||
};
|
};
|
||||||
delayedFunctionScheduler.scheduleFunction(pushCurrentTime);
|
delayedFunctionScheduler.scheduleFunction(pushCurrentTime);
|
||||||
@@ -1009,7 +1004,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly clears a scheduled timeout while the Clock is advancing', function() {
|
it('correctly clears a scheduled timeout while the Clock is advancing', function() {
|
||||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
global = { Date: Date, setTimeout: undefined },
|
global = { Date: Date, setTimeout: undefined },
|
||||||
mockDate = new jasmineUnderTest.MockDate(global),
|
mockDate = new jasmineUnderTest.MockDate(global),
|
||||||
clock = new jasmineUnderTest.Clock(
|
clock = new jasmineUnderTest.Clock(
|
||||||
@@ -1022,7 +1017,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
var timerId2;
|
let timerId2;
|
||||||
|
|
||||||
global.setTimeout(function() {
|
global.setTimeout(function() {
|
||||||
global.clearTimeout(timerId2);
|
global.clearTimeout(timerId2);
|
||||||
@@ -1034,7 +1029,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly clears a scheduled interval while the Clock is advancing', function() {
|
it('correctly clears a scheduled interval while the Clock is advancing', function() {
|
||||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
global = { Date: Date, setTimeout: undefined },
|
global = { Date: Date, setTimeout: undefined },
|
||||||
mockDate = new jasmineUnderTest.MockDate(global),
|
mockDate = new jasmineUnderTest.MockDate(global),
|
||||||
clock = new jasmineUnderTest.Clock(
|
clock = new jasmineUnderTest.Clock(
|
||||||
@@ -1047,7 +1042,7 @@ describe('Clock (acceptance)', function() {
|
|||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
var timerId2;
|
let timerId2;
|
||||||
global.setInterval(function() {
|
global.setInterval(function() {
|
||||||
global.clearInterval(timerId2);
|
global.clearInterval(timerId2);
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('DelayedFunctionScheduler', function() {
|
describe('DelayedFunctionScheduler', function() {
|
||||||
it('schedules a function for later execution', function() {
|
it('schedules a function for later execution', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn');
|
fn = jasmine.createSpy('fn');
|
||||||
|
|
||||||
scheduler.scheduleFunction(fn, 0);
|
scheduler.scheduleFunction(fn, 0);
|
||||||
@@ -13,7 +13,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('schedules a string for later execution', function() {
|
it('schedules a string for later execution', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
strfn = 'horrible = true;';
|
strfn = 'horrible = true;';
|
||||||
|
|
||||||
scheduler.scheduleFunction(strfn, 0);
|
scheduler.scheduleFunction(strfn, 0);
|
||||||
@@ -24,7 +24,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('#tick defaults to 0', function() {
|
it('#tick defaults to 0', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn');
|
fn = jasmine.createSpy('fn');
|
||||||
|
|
||||||
scheduler.scheduleFunction(fn, 0);
|
scheduler.scheduleFunction(fn, 0);
|
||||||
@@ -37,7 +37,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('defaults delay to 0', function() {
|
it('defaults delay to 0', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn');
|
fn = jasmine.createSpy('fn');
|
||||||
|
|
||||||
scheduler.scheduleFunction(fn);
|
scheduler.scheduleFunction(fn);
|
||||||
@@ -50,7 +50,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('optionally passes params to scheduled functions', function() {
|
it('optionally passes params to scheduled functions', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn');
|
fn = jasmine.createSpy('fn');
|
||||||
|
|
||||||
scheduler.scheduleFunction(fn, 0, ['foo', 'bar']);
|
scheduler.scheduleFunction(fn, 0, ['foo', 'bar']);
|
||||||
@@ -63,7 +63,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('scheduled fns can optionally reoccur', function() {
|
it('scheduled fns can optionally reoccur', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn');
|
fn = jasmine.createSpy('fn');
|
||||||
|
|
||||||
scheduler.scheduleFunction(fn, 20, [], true);
|
scheduler.scheduleFunction(fn, 20, [], true);
|
||||||
@@ -84,7 +84,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('increments scheduled fns ids unless one is passed', function() {
|
it('increments scheduled fns ids unless one is passed', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler();
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler();
|
||||||
|
|
||||||
expect(scheduler.scheduleFunction(function() {}, 0)).toBe(1);
|
expect(scheduler.scheduleFunction(function() {}, 0)).toBe(1);
|
||||||
expect(scheduler.scheduleFunction(function() {}, 0)).toBe(2);
|
expect(scheduler.scheduleFunction(function() {}, 0)).toBe(2);
|
||||||
@@ -95,11 +95,9 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('#removeFunctionWithId removes a previously scheduled function with a given id', function() {
|
it('#removeFunctionWithId removes a previously scheduled function with a given id', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn'),
|
fn = jasmine.createSpy('fn'),
|
||||||
timeoutKey;
|
timeoutKey = scheduler.scheduleFunction(fn, 0);
|
||||||
|
|
||||||
timeoutKey = scheduler.scheduleFunction(fn, 0);
|
|
||||||
|
|
||||||
expect(fn).not.toHaveBeenCalled();
|
expect(fn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
@@ -111,15 +109,15 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('executes recurring functions interleaved with regular functions in the correct order', function() {
|
it('executes recurring functions interleaved with regular functions in the correct order', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler();
|
||||||
fn = jasmine.createSpy('fn'),
|
const fn = jasmine.createSpy('fn');
|
||||||
recurringCallCount = 0,
|
let recurringCallCount = 0;
|
||||||
recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
const recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
||||||
recurringCallCount++;
|
recurringCallCount++;
|
||||||
if (recurringCallCount < 5) {
|
if (recurringCallCount < 5) {
|
||||||
expect(fn).not.toHaveBeenCalled();
|
expect(fn).not.toHaveBeenCalled();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scheduler.scheduleFunction(recurring, 10, [], true);
|
scheduler.scheduleFunction(recurring, 10, [], true);
|
||||||
scheduler.scheduleFunction(fn, 50);
|
scheduler.scheduleFunction(fn, 50);
|
||||||
@@ -132,7 +130,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('schedules a function for later execution during a tick', function() {
|
it('schedules a function for later execution during a tick', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn'),
|
fn = jasmine.createSpy('fn'),
|
||||||
fnDelay = 10;
|
fnDelay = 10;
|
||||||
|
|
||||||
@@ -148,10 +146,10 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('#removeFunctionWithId removes a previously scheduled function with a given id during a tick', function() {
|
it('#removeFunctionWithId removes a previously scheduled function with a given id during a tick', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn'),
|
fn = jasmine.createSpy('fn'),
|
||||||
fnDelay = 10,
|
fnDelay = 10;
|
||||||
timeoutKey;
|
let timeoutKey;
|
||||||
|
|
||||||
scheduler.scheduleFunction(function() {
|
scheduler.scheduleFunction(function() {
|
||||||
scheduler.removeFunctionWithId(timeoutKey);
|
scheduler.removeFunctionWithId(timeoutKey);
|
||||||
@@ -166,24 +164,24 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('executes recurring functions interleaved with regular functions and functions scheduled during a tick in the correct order', function() {
|
it('executes recurring functions interleaved with regular functions and functions scheduled during a tick in the correct order', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler();
|
||||||
fn = jasmine.createSpy('fn'),
|
const fn = jasmine.createSpy('fn');
|
||||||
recurringCallCount = 0,
|
let recurringCallCount = 0;
|
||||||
recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
const recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
||||||
recurringCallCount++;
|
recurringCallCount++;
|
||||||
if (recurringCallCount < 5) {
|
if (recurringCallCount < 5) {
|
||||||
expect(fn).not.toHaveBeenCalled();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
innerFn = jasmine.createSpy('innerFn').and.callFake(function() {
|
|
||||||
expect(recurring.calls.count()).toBe(4);
|
|
||||||
expect(fn).not.toHaveBeenCalled();
|
expect(fn).not.toHaveBeenCalled();
|
||||||
}),
|
}
|
||||||
scheduling = jasmine.createSpy('scheduling').and.callFake(function() {
|
});
|
||||||
expect(recurring.calls.count()).toBe(3);
|
const innerFn = jasmine.createSpy('innerFn').and.callFake(function() {
|
||||||
expect(fn).not.toHaveBeenCalled();
|
expect(recurring.calls.count()).toBe(4);
|
||||||
scheduler.scheduleFunction(innerFn, 10); // 41ms absolute
|
expect(fn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
const scheduling = jasmine.createSpy('scheduling').and.callFake(function() {
|
||||||
|
expect(recurring.calls.count()).toBe(3);
|
||||||
|
expect(fn).not.toHaveBeenCalled();
|
||||||
|
scheduler.scheduleFunction(innerFn, 10); // 41ms absolute
|
||||||
|
});
|
||||||
|
|
||||||
scheduler.scheduleFunction(recurring, 10, [], true);
|
scheduler.scheduleFunction(recurring, 10, [], true);
|
||||||
scheduler.scheduleFunction(fn, 50);
|
scheduler.scheduleFunction(fn, 50);
|
||||||
@@ -199,7 +197,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('executes recurring functions after rescheduling them', function() {
|
it('executes recurring functions after rescheduling them', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
recurring = function() {
|
recurring = function() {
|
||||||
expect(scheduler.scheduleFunction).toHaveBeenCalled();
|
expect(scheduler.scheduleFunction).toHaveBeenCalled();
|
||||||
};
|
};
|
||||||
@@ -212,11 +210,11 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('removes functions during a tick that runs the function', function() {
|
it('removes functions during a tick that runs the function', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
spy = jasmine.createSpy('fn'),
|
spy = jasmine.createSpy('fn'),
|
||||||
spyAndRemove = jasmine.createSpy('fn'),
|
spyAndRemove = jasmine.createSpy('fn'),
|
||||||
fnDelay = 10,
|
fnDelay = 10;
|
||||||
timeoutKey;
|
let timeoutKey;
|
||||||
|
|
||||||
spyAndRemove.and.callFake(function() {
|
spyAndRemove.and.callFake(function() {
|
||||||
scheduler.removeFunctionWithId(timeoutKey);
|
scheduler.removeFunctionWithId(timeoutKey);
|
||||||
@@ -233,10 +231,10 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('removes functions during the first tick that runs the function', function() {
|
it('removes functions during the first tick that runs the function', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn'),
|
fn = jasmine.createSpy('fn'),
|
||||||
fnDelay = 10,
|
fnDelay = 10;
|
||||||
timeoutKey;
|
let timeoutKey;
|
||||||
|
|
||||||
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
|
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
|
||||||
scheduler.scheduleFunction(function() {
|
scheduler.scheduleFunction(function() {
|
||||||
@@ -252,7 +250,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not remove a function that hasn't been added yet", function() {
|
it("does not remove a function that hasn't been added yet", function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn'),
|
fn = jasmine.createSpy('fn'),
|
||||||
fnDelay = 10;
|
fnDelay = 10;
|
||||||
|
|
||||||
@@ -267,7 +265,7 @@ describe('DelayedFunctionScheduler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates the mockDate per scheduled time', function() {
|
it('updates the mockDate per scheduled time', function() {
|
||||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||||
tickDate = jasmine.createSpy('tickDate');
|
tickDate = jasmine.createSpy('tickDate');
|
||||||
|
|
||||||
scheduler.scheduleFunction(function() {});
|
scheduler.scheduleFunction(function() {});
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('logs the mesage without context when the runnable is the top suite', function() {
|
it('logs the mesage without context when the runnable is the top suite', function() {
|
||||||
var runnable = { addDeprecationWarning: function() {} };
|
const runnable = { addDeprecationWarning: function() {} };
|
||||||
var deprecator = new jasmineUnderTest.Deprecator(runnable);
|
const deprecator = new jasmineUnderTest.Deprecator(runnable);
|
||||||
deprecator.verboseDeprecations(true);
|
deprecator.verboseDeprecations(true);
|
||||||
|
|
||||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||||
@@ -18,14 +18,14 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('logs the message in a descendant suite', function() {
|
it('logs the message in a descendant suite', function() {
|
||||||
var runnable = {
|
const runnable = {
|
||||||
addDeprecationWarning: function() {},
|
addDeprecationWarning: function() {},
|
||||||
getFullName: function() {
|
getFullName: function() {
|
||||||
return 'the suite';
|
return 'the suite';
|
||||||
},
|
},
|
||||||
children: []
|
children: []
|
||||||
};
|
};
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
deprecator.verboseDeprecations(true);
|
deprecator.verboseDeprecations(true);
|
||||||
|
|
||||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||||
@@ -38,13 +38,13 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('logs and reports the message in a spec', function() {
|
it('logs and reports the message in a spec', function() {
|
||||||
var runnable = {
|
const runnable = {
|
||||||
addDeprecationWarning: function() {},
|
addDeprecationWarning: function() {},
|
||||||
getFullName: function() {
|
getFullName: function() {
|
||||||
return 'the spec';
|
return 'the spec';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
deprecator.verboseDeprecations(true);
|
deprecator.verboseDeprecations(true);
|
||||||
|
|
||||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||||
@@ -57,12 +57,12 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('logs and reports the message without runnable info when ignoreRunnable is true', function() {
|
it('logs and reports the message without runnable info when ignoreRunnable is true', function() {
|
||||||
var topSuite = jasmine.createSpyObj('topSuite', [
|
const topSuite = jasmine.createSpyObj('topSuite', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
var deprecator = new jasmineUnderTest.Deprecator(topSuite);
|
const deprecator = new jasmineUnderTest.Deprecator(topSuite);
|
||||||
var runnable = jasmine.createSpyObj('spec', [
|
const runnable = jasmine.createSpyObj('spec', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
@@ -105,12 +105,12 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('emits the deprecation only once when verboseDeprecations is not set', function() {
|
it('emits the deprecation only once when verboseDeprecations is not set', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable1 = jasmine.createSpyObj('runnable1', [
|
const runnable1 = jasmine.createSpyObj('runnable1', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
var runnable2 = jasmine.createSpyObj('runnable2', [
|
const runnable2 = jasmine.createSpyObj('runnable2', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
@@ -124,12 +124,12 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('emits the deprecation only once when verboseDeprecations is false', function() {
|
it('emits the deprecation only once when verboseDeprecations is false', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable1 = jasmine.createSpyObj('runnable1', [
|
const runnable1 = jasmine.createSpyObj('runnable1', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
var runnable2 = jasmine.createSpyObj('runnable2', [
|
const runnable2 = jasmine.createSpyObj('runnable2', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
@@ -144,12 +144,12 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('emits the deprecation for each call when verboseDeprecations is true', function() {
|
it('emits the deprecation for each call when verboseDeprecations is true', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable1 = jasmine.createSpyObj('runnable1', [
|
const runnable1 = jasmine.createSpyObj('runnable1', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
var runnable2 = jasmine.createSpyObj('runnable2', [
|
const runnable2 = jasmine.createSpyObj('runnable2', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
@@ -164,8 +164,8 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('includes a note about verboseDeprecations', function() {
|
it('includes a note about verboseDeprecations', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable = jasmine.createSpyObj('runnable', [
|
const runnable = jasmine.createSpyObj('runnable', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
@@ -183,8 +183,8 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('omits the note about verboseDeprecations when verboseDeprecations is true', function() {
|
it('omits the note about verboseDeprecations when verboseDeprecations is true', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable = jasmine.createSpyObj('runnable', [
|
const runnable = jasmine.createSpyObj('runnable', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
@@ -207,13 +207,12 @@ describe('Deprecator', function() {
|
|||||||
// to report their own deprecations through Jasmine. See
|
// to report their own deprecations through Jasmine. See
|
||||||
// <https://github.com/jasmine/jasmine/pull/1498>.
|
// <https://github.com/jasmine/jasmine/pull/1498>.
|
||||||
it('passes the error through unchanged', function() {
|
it('passes the error through unchanged', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable = jasmine.createSpyObj('runnable', [
|
const runnable = jasmine.createSpyObj('runnable', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter();
|
let deprecation, originalStack;
|
||||||
var deprecation, originalStack;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
throw new Error('the deprecation');
|
throw new Error('the deprecation');
|
||||||
@@ -239,12 +238,12 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports the deprecation every time, regardless of config.verboseDeprecations', function() {
|
it('reports the deprecation every time, regardless of config.verboseDeprecations', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable = jasmine.createSpyObj('runnable', [
|
const runnable = jasmine.createSpyObj('runnable', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
var deprecation;
|
let deprecation;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
throw new Error('the deprecation');
|
throw new Error('the deprecation');
|
||||||
@@ -260,12 +259,12 @@ describe('Deprecator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('omits the note about verboseDeprecations', function() {
|
it('omits the note about verboseDeprecations', function() {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable = jasmine.createSpyObj('runnable', [
|
const runnable = jasmine.createSpyObj('runnable', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
var deprecation;
|
let deprecation;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
throw new Error('the deprecation');
|
throw new Error('the deprecation');
|
||||||
@@ -294,8 +293,8 @@ describe('Deprecator', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testStackTrace(options) {
|
function testStackTrace(options) {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable = jasmine.createSpyObj('runnable', [
|
const runnable = jasmine.createSpyObj('runnable', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
@@ -312,8 +311,8 @@ describe('Deprecator', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testNoStackTrace(options) {
|
function testNoStackTrace(options) {
|
||||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||||
var runnable = jasmine.createSpyObj('runnable', [
|
const runnable = jasmine.createSpyObj('runnable', [
|
||||||
'addDeprecationWarning',
|
'addDeprecationWarning',
|
||||||
'getFullName'
|
'getFullName'
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// TODO: Fix these unit tests!
|
// TODO: Fix these unit tests!
|
||||||
describe('Env', function() {
|
describe('Env', function() {
|
||||||
var env;
|
let env;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
});
|
});
|
||||||
@@ -27,7 +27,6 @@ describe('Env', function() {
|
|||||||
|
|
||||||
describe('#topSuite', function() {
|
describe('#topSuite', function() {
|
||||||
it('returns an object that describes the tree of suites and specs', function() {
|
it('returns an object that describes the tree of suites and specs', function() {
|
||||||
var suite;
|
|
||||||
spyOn(env, 'deprecated');
|
spyOn(env, 'deprecated');
|
||||||
|
|
||||||
env.it('a top level spec');
|
env.it('a top level spec');
|
||||||
@@ -38,7 +37,7 @@ describe('Env', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite = env.topSuite();
|
const suite = env.topSuite();
|
||||||
expect(suite).not.toBeInstanceOf(jasmineUnderTest.Suite);
|
expect(suite).not.toBeInstanceOf(jasmineUnderTest.Suite);
|
||||||
expect(suite.description).toEqual('Jasmine__TopLevel__Suite');
|
expect(suite.description).toEqual('Jasmine__TopLevel__Suite');
|
||||||
expect(suite.getFullName()).toEqual('');
|
expect(suite.getFullName()).toEqual('');
|
||||||
@@ -81,6 +80,19 @@ describe('Env', function() {
|
|||||||
);
|
);
|
||||||
expect(suite.children[1].children[1].children[0].children).toBeFalsy();
|
expect(suite.children[1].children[1].children[0].children).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws if called in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
check();
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
check();
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
expect(function() {
|
||||||
|
env.topSuite();
|
||||||
|
}).toThrowError("'topSuite' is not available in parallel mode");
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts its own current configureation', function() {
|
it('accepts its own current configureation', function() {
|
||||||
@@ -113,7 +125,7 @@ describe('Env', function() {
|
|||||||
|
|
||||||
it('ignores configuration properties that are present but undefined', function() {
|
it('ignores configuration properties that are present but undefined', function() {
|
||||||
spyOn(env, 'deprecated');
|
spyOn(env, 'deprecated');
|
||||||
var initialConfig = {
|
const initialConfig = {
|
||||||
random: true,
|
random: true,
|
||||||
seed: '123',
|
seed: '123',
|
||||||
failSpecWithNoExpectations: true,
|
failSpecWithNoExpectations: true,
|
||||||
@@ -161,8 +173,8 @@ describe('Env', function() {
|
|||||||
it('returns a suite metadata object', function() {
|
it('returns a suite metadata object', function() {
|
||||||
let innerSuite;
|
let innerSuite;
|
||||||
let spec;
|
let spec;
|
||||||
const suite = env.describe('outer suite', function() {
|
const suite = env[methodName]('outer suite', function() {
|
||||||
innerSuite = env.describe('inner suite', function() {
|
innerSuite = env[methodName]('inner suite', function() {
|
||||||
spec = env.it('a spec');
|
spec = env.it('a spec');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -193,6 +205,7 @@ describe('Env', function() {
|
|||||||
|
|
||||||
it('throws an error when given arguments', function() {
|
it('throws an error when given arguments', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
env.describe('done method', function(done) {});
|
env.describe('done method', function(done) {});
|
||||||
}).toThrowError('describe does not expect any arguments');
|
}).toThrowError('describe does not expect any arguments');
|
||||||
});
|
});
|
||||||
@@ -235,14 +248,31 @@ describe('Env', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error when it has no children', function() {
|
it('throws an error when it has no children', function() {
|
||||||
expect(function() {
|
let ran = false;
|
||||||
env.describe('done method', function() {});
|
env.describe('parent suite', function() {
|
||||||
}).toThrowError('describe with no children (describe() or it())');
|
expect(function() {
|
||||||
|
env.describe('child suite', function() {});
|
||||||
|
}).toThrowError(
|
||||||
|
'describe with no children (describe() or it()): parent suite child suite'
|
||||||
|
);
|
||||||
|
ran = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ran).toBeTrue();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#fdescribe', function() {
|
describe('#fdescribe', function() {
|
||||||
behavesLikeDescribe('fdescribe');
|
behavesLikeDescribe('fdescribe');
|
||||||
|
|
||||||
|
it('throws an error in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
expect(function() {
|
||||||
|
env.fdescribe('a suite', function() {
|
||||||
|
env.it('a spec');
|
||||||
|
});
|
||||||
|
}).toThrowError("'fdescribe' is not available in parallel mode");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('xdescribe', function() {
|
describe('xdescribe', function() {
|
||||||
@@ -307,8 +337,8 @@ describe('Env', function() {
|
|||||||
behavesLikeIt('xit');
|
behavesLikeIt('xit');
|
||||||
|
|
||||||
it('calls spec.exclude with "Temporarily disabled with xit"', function() {
|
it('calls spec.exclude with "Temporarily disabled with xit"', function() {
|
||||||
var excludeSpy = jasmine.createSpy();
|
const excludeSpy = jasmine.createSpy();
|
||||||
spyOn(env, 'it_').and.returnValue({
|
spyOn(jasmineUnderTest.SuiteBuilder.prototype, 'it_').and.returnValue({
|
||||||
exclude: excludeSpy
|
exclude: excludeSpy
|
||||||
});
|
});
|
||||||
env.xit('foo', function() {});
|
env.xit('foo', function() {});
|
||||||
@@ -316,10 +346,10 @@ describe('Env', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls spec.pend with "Temporarily disabled with xit"', function() {
|
it('calls spec.pend with "Temporarily disabled with xit"', function() {
|
||||||
var pendSpy = jasmine.createSpy();
|
const pendSpy = jasmine.createSpy();
|
||||||
var realExclude = jasmineUnderTest.Spec.prototype.exclude;
|
const realExclude = jasmineUnderTest.Spec.prototype.exclude;
|
||||||
|
|
||||||
spyOn(env, 'it_').and.returnValue({
|
spyOn(jasmineUnderTest.SuiteBuilder.prototype, 'it_').and.returnValue({
|
||||||
exclude: realExclude,
|
exclude: realExclude,
|
||||||
pend: pendSpy
|
pend: pendSpy
|
||||||
});
|
});
|
||||||
@@ -364,6 +394,13 @@ describe('Env', function() {
|
|||||||
env.fit('huge timeout', function() {}, 2147483648);
|
env.fit('huge timeout', function() {}, 2147483648);
|
||||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws an error in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
expect(function() {
|
||||||
|
env.fit('a spec', function() {});
|
||||||
|
}).toThrowError("'fit' is not available in parallel mode");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#beforeEach', function() {
|
describe('#beforeEach', function() {
|
||||||
@@ -386,6 +423,28 @@ describe('Env', function() {
|
|||||||
env.beforeEach(function() {}, 2147483648);
|
env.beforeEach(function() {}, 2147483648);
|
||||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws when called at the top level in a spec file in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
expect(function() {
|
||||||
|
env.beforeEach(function() {});
|
||||||
|
}).toThrowError(
|
||||||
|
'In parallel mode, beforeEach must be in a describe block or in a helper file'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw when called at the top level in a helper file in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
env.beforeEach(function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw when called in a describe in a spec file in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
env.describe('a suite', function() {
|
||||||
|
env.beforeEach(function() {});
|
||||||
|
env.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#beforeAll', function() {
|
describe('#beforeAll', function() {
|
||||||
@@ -408,6 +467,47 @@ describe('Env', function() {
|
|||||||
env.beforeAll(function() {}, 2147483648);
|
env.beforeAll(function() {}, 2147483648);
|
||||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('in parallel mode', function() {
|
||||||
|
it('throws an error when called at the top level', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
check();
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
check();
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
expect(function() {
|
||||||
|
env.beforeAll(function() {});
|
||||||
|
}).toThrowError(
|
||||||
|
"In parallel mode, 'beforeAll' must be in a describe block. " +
|
||||||
|
'Use the globalSetup config property for exactly-once setup in' +
|
||||||
|
' parallel mode.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw an error when called in a describe', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
check();
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
check();
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
let done = false;
|
||||||
|
|
||||||
|
env.describe('a suite', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.it('a spec');
|
||||||
|
env.beforeAll(function() {});
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
done = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(done).toBeTrue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#afterEach', function() {
|
describe('#afterEach', function() {
|
||||||
@@ -430,6 +530,28 @@ describe('Env', function() {
|
|||||||
env.afterEach(function() {}, 2147483648);
|
env.afterEach(function() {}, 2147483648);
|
||||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws when called at the top level in a spec file in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
expect(function() {
|
||||||
|
env.afterEach(function() {});
|
||||||
|
}).toThrowError(
|
||||||
|
'In parallel mode, afterEach must be in a describe block or in a helper file'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw when called at the top level in a helper file in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
env.afterEach(function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw when called in a describe in a spec file in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
env.describe('a suite', function() {
|
||||||
|
env.afterEach(function() {});
|
||||||
|
env.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#afterAll', function() {
|
describe('#afterAll', function() {
|
||||||
@@ -452,15 +574,57 @@ describe('Env', function() {
|
|||||||
env.afterAll(function() {}, 2147483648);
|
env.afterAll(function() {}, 2147483648);
|
||||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('in parallel mode', function() {
|
||||||
|
it('throws an error when called at the top level', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
check();
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
check();
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
expect(function() {
|
||||||
|
env.afterAll(function() {});
|
||||||
|
}).toThrowError(
|
||||||
|
"In parallel mode, 'afterAll' must be in a describe block. " +
|
||||||
|
'Use the globalTeardown config property for exactly-once ' +
|
||||||
|
'teardown in parallel mode.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw an error when called in a describe', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
check();
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
check();
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
let done = false;
|
||||||
|
|
||||||
|
env.describe('a suite', function() {
|
||||||
|
expect(function() {
|
||||||
|
env.it('a spec');
|
||||||
|
env.afterAll(function() {});
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
done = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(done).toBeTrue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when not constructed with suppressLoadErrors: true', function() {
|
describe('when not constructed with suppressLoadErrors: true', function() {
|
||||||
it('installs a global error handler on construction', function() {
|
it('installs a global error handler on construction', function() {
|
||||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||||
'install',
|
'install',
|
||||||
'uninstall',
|
'uninstall',
|
||||||
'pushListener',
|
'pushListener',
|
||||||
'popListener'
|
'popListener',
|
||||||
|
'removeOverrideListener'
|
||||||
]);
|
]);
|
||||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
@@ -471,11 +635,12 @@ describe('Env', function() {
|
|||||||
|
|
||||||
describe('when constructed with suppressLoadErrors: true', function() {
|
describe('when constructed with suppressLoadErrors: true', function() {
|
||||||
it('does not install a global error handler until execute is called', function() {
|
it('does not install a global error handler until execute is called', function() {
|
||||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||||
'install',
|
'install',
|
||||||
'uninstall',
|
'uninstall',
|
||||||
'pushListener',
|
'pushListener',
|
||||||
'popListener'
|
'popListener',
|
||||||
|
'removeOverrideListener'
|
||||||
]);
|
]);
|
||||||
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
|
||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
@@ -486,13 +651,13 @@ describe('Env', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates an expectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
it('creates an expectationFactory that uses the current custom equality testers and object formatters', async function() {
|
||||||
function customEqualityTester() {}
|
function customEqualityTester() {}
|
||||||
function customObjectFormatter() {}
|
function customObjectFormatter() {}
|
||||||
function prettyPrinter() {}
|
function prettyPrinter() {}
|
||||||
var RealSpec = jasmineUnderTest.Spec,
|
const RealSpec = jasmineUnderTest.Spec;
|
||||||
specInstance,
|
let specInstance;
|
||||||
expectationFactory;
|
let expectationFactory;
|
||||||
spyOn(jasmineUnderTest, 'MatchersUtil');
|
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||||
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||||
@@ -507,25 +672,23 @@ describe('Env', function() {
|
|||||||
expectationFactory('actual', specInstance);
|
expectationFactory('actual', specInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
customObjectFormatter
|
customObjectFormatter
|
||||||
]);
|
]);
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
customTesters: [customEqualityTester],
|
customTesters: [customEqualityTester],
|
||||||
pp: prettyPrinter
|
pp: prettyPrinter
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', async function() {
|
||||||
function customEqualityTester() {}
|
function customEqualityTester() {}
|
||||||
function customObjectFormatter() {}
|
function customObjectFormatter() {}
|
||||||
function prettyPrinter() {}
|
function prettyPrinter() {}
|
||||||
var RealSpec = jasmineUnderTest.Spec,
|
const RealSpec = jasmineUnderTest.Spec;
|
||||||
specInstance,
|
let specInstance;
|
||||||
asyncExpectationFactory;
|
let asyncExpectationFactory;
|
||||||
spyOn(jasmineUnderTest, 'MatchersUtil');
|
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||||
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||||
@@ -540,20 +703,19 @@ describe('Env', function() {
|
|||||||
asyncExpectationFactory('actual', specInstance);
|
asyncExpectationFactory('actual', specInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
await env.execute();
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
|
||||||
customObjectFormatter
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||||
]);
|
customObjectFormatter
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
]);
|
||||||
customTesters: [customEqualityTester],
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||||
pp: prettyPrinter
|
customTesters: [customEqualityTester],
|
||||||
});
|
pp: prettyPrinter
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not expose the suite as 'this'", function() {
|
it("does not expose the suite as 'this'", function() {
|
||||||
var suiteThis;
|
let suiteThis;
|
||||||
spyOn(env, 'deprecated');
|
spyOn(env, 'deprecated');
|
||||||
|
|
||||||
env.describe('a suite', function() {
|
env.describe('a suite', function() {
|
||||||
@@ -577,14 +739,96 @@ describe('Env', function() {
|
|||||||
return env.execute(); // 2
|
return env.execute(); // 2
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
var id;
|
|
||||||
expect(
|
expect(
|
||||||
jasmineUnderTest.Suite.prototype.reset
|
jasmineUnderTest.Suite.prototype.reset
|
||||||
).toHaveBeenCalledOnceWith();
|
).toHaveBeenCalledOnceWith();
|
||||||
id = jasmineUnderTest.Suite.prototype.reset.calls.thisFor(0).id;
|
const id = jasmineUnderTest.Suite.prototype.reset.calls.thisFor(0).id;
|
||||||
expect(id).toBeTruthy();
|
expect(id).toBeTruthy();
|
||||||
expect(id).toEqual(env.topSuite().id);
|
expect(id).toEqual(env.topSuite().id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not reset the topSuite if parallelReset was called since the last run', async function() {
|
||||||
|
await env.execute();
|
||||||
|
env.parallelReset();
|
||||||
|
spyOn(jasmineUnderTest.Suite.prototype, 'reset');
|
||||||
|
await env.execute();
|
||||||
|
expect(jasmineUnderTest.Suite.prototype.reset).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('In parallel mode', function() {
|
||||||
|
it('rejects if random is set to false', async function() {
|
||||||
|
env.configure({ random: false });
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
await expectAsync(env.execute()).toBeRejectedWithError(
|
||||||
|
'Randomization cannot be disabled in parallel mode'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects if seed is set', async function() {
|
||||||
|
env.configure({ seed: 1234 });
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
await expectAsync(env.execute()).toBeRejectedWithError(
|
||||||
|
'Random seed cannot be set in parallel mode'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#spyOnGlobalErrorsAsync', function() {
|
||||||
|
it('throws if the callback does not return a promise', async function() {
|
||||||
|
const msg =
|
||||||
|
'The callback to spyOnGlobalErrorsAsync must be an async or ' +
|
||||||
|
'promise-returning function';
|
||||||
|
|
||||||
|
await expectAsync(
|
||||||
|
env.spyOnGlobalErrorsAsync(() => undefined)
|
||||||
|
).toBeRejectedWithError(msg);
|
||||||
|
await expectAsync(
|
||||||
|
env.spyOnGlobalErrorsAsync(() => 'not a promise')
|
||||||
|
).toBeRejectedWithError(msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addReporter', function() {
|
||||||
|
it('throws when called in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
expect(function() {
|
||||||
|
env.addReporter({});
|
||||||
|
}).toThrowError('Reporters cannot be added via Env in parallel mode');
|
||||||
|
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
expect(function() {
|
||||||
|
env.addReporter({});
|
||||||
|
}).toThrowError('Reporters cannot be added via Env in parallel mode');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#clearReporters', function() {
|
||||||
|
it('throws when called in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
expect(function() {
|
||||||
|
env.clearReporters();
|
||||||
|
}).toThrowError('Reporters cannot be removed via Env in parallel mode');
|
||||||
|
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
expect(function() {
|
||||||
|
env.clearReporters();
|
||||||
|
}).toThrowError('Reporters cannot be removed via Env in parallel mode');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#configure', function() {
|
||||||
|
it('throws when called in parallel mode', function() {
|
||||||
|
env.setParallelLoadingState('helpers');
|
||||||
|
expect(function() {
|
||||||
|
env.configure({});
|
||||||
|
}).toThrowError('Jasmine cannot be configured via Env in parallel mode');
|
||||||
|
|
||||||
|
env.setParallelLoadingState('specs');
|
||||||
|
expect(function() {
|
||||||
|
env.configure({});
|
||||||
|
}).toThrowError('Jasmine cannot be configured via Env in parallel mode');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
describe('ExceptionFormatter', function() {
|
describe('ExceptionFormatter', function() {
|
||||||
describe('#message', function() {
|
describe('#message', function() {
|
||||||
it('formats Firefox exception messages', function() {
|
it('formats Firefox exception messages', function() {
|
||||||
var sampleFirefoxException = {
|
const sampleFirefoxException = {
|
||||||
fileName: 'foo.js',
|
fileName: 'foo.js',
|
||||||
lineNumber: '1978',
|
lineNumber: '1978',
|
||||||
message: 'you got your foo in my bar',
|
message: 'you got your foo in my bar',
|
||||||
@@ -16,7 +16,7 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('formats Webkit exception messages', function() {
|
it('formats Webkit exception messages', function() {
|
||||||
var sampleWebkitException = {
|
const sampleWebkitException = {
|
||||||
sourceURL: 'foo.js',
|
sourceURL: 'foo.js',
|
||||||
line: '1978',
|
line: '1978',
|
||||||
message: 'you got your foo in my bar',
|
message: 'you got your foo in my bar',
|
||||||
@@ -31,7 +31,7 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('formats V8 exception messages', function() {
|
it('formats V8 exception messages', function() {
|
||||||
var sampleV8 = {
|
const sampleV8 = {
|
||||||
message: 'you got your foo in my bar',
|
message: 'you got your foo in my bar',
|
||||||
name: 'A Classic Mistake'
|
name: 'A Classic Mistake'
|
||||||
},
|
},
|
||||||
@@ -42,29 +42,29 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('formats unnamed exceptions with message', function() {
|
it('formats unnamed exceptions with message', function() {
|
||||||
var unnamedError = { message: 'This is an unnamed error message.' };
|
const unnamedError = { message: 'This is an unnamed error message.' };
|
||||||
|
|
||||||
var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
const exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||||
message = exceptionFormatter.message(unnamedError);
|
message = exceptionFormatter.message(unnamedError);
|
||||||
|
|
||||||
expect(message).toEqual('This is an unnamed error message.');
|
expect(message).toEqual('This is an unnamed error message.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('formats empty exceptions with toString format', function() {
|
it('formats empty exceptions with toString format', function() {
|
||||||
var EmptyError = function() {};
|
const EmptyError = function() {};
|
||||||
EmptyError.prototype.toString = function() {
|
EmptyError.prototype.toString = function() {
|
||||||
return '[EmptyError]';
|
return '[EmptyError]';
|
||||||
};
|
};
|
||||||
var emptyError = new EmptyError();
|
const emptyError = new EmptyError();
|
||||||
|
|
||||||
var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
const exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||||
message = exceptionFormatter.message(emptyError);
|
message = exceptionFormatter.message(emptyError);
|
||||||
|
|
||||||
expect(message).toEqual('[EmptyError] thrown');
|
expect(message).toEqual('[EmptyError] thrown');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("formats thrown exceptions that aren't errors", function() {
|
it("formats thrown exceptions that aren't errors", function() {
|
||||||
var thrown = 'crazy error',
|
const thrown = 'crazy error',
|
||||||
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||||
message = exceptionFormatter.message(thrown);
|
message = exceptionFormatter.message(thrown);
|
||||||
|
|
||||||
@@ -74,12 +74,7 @@ describe('ExceptionFormatter', function() {
|
|||||||
|
|
||||||
describe('#stack', function() {
|
describe('#stack', function() {
|
||||||
it('formats stack traces', function() {
|
it('formats stack traces', function() {
|
||||||
var error;
|
const error = new Error('an error');
|
||||||
try {
|
|
||||||
throw new Error('an error');
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(new jasmineUnderTest.ExceptionFormatter().stack(error)).toMatch(
|
expect(new jasmineUnderTest.ExceptionFormatter().stack(error)).toMatch(
|
||||||
/ExceptionFormatterSpec\.js.*\d+/
|
/ExceptionFormatterSpec\.js.*\d+/
|
||||||
@@ -87,7 +82,7 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('filters Jasmine stack frames from V8-style traces but leaves unmatched lines intact', function() {
|
it('filters Jasmine stack frames from V8-style traces but leaves unmatched lines intact', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||||
@@ -101,10 +96,10 @@ describe('ExceptionFormatter', function() {
|
|||||||
' at fn3 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7575:25)\n' +
|
' at fn3 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7575:25)\n' +
|
||||||
' at fn4 (node:internal/timers:462:21)\n'
|
' at fn4 (node:internal/timers:462:21)\n'
|
||||||
};
|
};
|
||||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||||
jasmineFile: 'C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js'
|
jasmineFile: 'C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js'
|
||||||
});
|
});
|
||||||
var result = subject.stack(error);
|
const result = subject.stack(error);
|
||||||
expect(result).toEqual(
|
expect(result).toEqual(
|
||||||
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||||
" new Error('nope');\n" +
|
" new Error('nope');\n" +
|
||||||
@@ -118,7 +113,7 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('filters Jasmine stack frames from V8 style traces', function() {
|
it('filters Jasmine stack frames from V8 style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'Error: nope\n' +
|
'Error: nope\n' +
|
||||||
@@ -127,10 +122,10 @@ describe('ExceptionFormatter', function() {
|
|||||||
' at fn3 (http://localhost:8888/__jasmine__/jasmine.js:4320:20)\n' +
|
' at fn3 (http://localhost:8888/__jasmine__/jasmine.js:4320:20)\n' +
|
||||||
' at fn4 (http://localhost:8888/__spec__/core/UtilSpec.js:110:19)\n'
|
' at fn4 (http://localhost:8888/__spec__/core/UtilSpec.js:110:19)\n'
|
||||||
};
|
};
|
||||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||||
});
|
});
|
||||||
var result = subject.stack(error);
|
const result = subject.stack(error);
|
||||||
expect(result).toEqual(
|
expect(result).toEqual(
|
||||||
'Error: nope\n' +
|
'Error: nope\n' +
|
||||||
' at fn1 (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
' at fn1 (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||||
@@ -140,17 +135,17 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('filters Jasmine stack frames from Webkit style traces', function() {
|
it('filters Jasmine stack frames from Webkit style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
stack:
|
stack:
|
||||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||||
'fn1@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
|
'fn1@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
|
||||||
'fn2@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
|
'fn2@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
|
||||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28'
|
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28'
|
||||||
};
|
};
|
||||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||||
});
|
});
|
||||||
var result = subject.stack(error);
|
const result = subject.stack(error);
|
||||||
expect(result).toEqual(
|
expect(result).toEqual(
|
||||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||||
'<Jasmine>\n' +
|
'<Jasmine>\n' +
|
||||||
@@ -159,17 +154,12 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('filters Jasmine stack frames in this environment', function() {
|
it('filters Jasmine stack frames in this environment', function() {
|
||||||
var error, i;
|
const error = new Error('an error');
|
||||||
try {
|
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||||
throw new Error('an error');
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
|
||||||
jasmineFile: jasmine.util.jasmineFile()
|
jasmineFile: jasmine.util.jasmineFile()
|
||||||
});
|
});
|
||||||
var result = subject.stack(error);
|
const result = subject.stack(error);
|
||||||
var lines = result.split('\n');
|
const lines = result.split('\n');
|
||||||
|
|
||||||
if (lines[0].match(/an error/)) {
|
if (lines[0].match(/an error/)) {
|
||||||
lines.shift();
|
lines.shift();
|
||||||
@@ -179,28 +169,23 @@ describe('ExceptionFormatter', function() {
|
|||||||
expect(lines[1]).toMatch(/<Jasmine>/);
|
expect(lines[1]).toMatch(/<Jasmine>/);
|
||||||
|
|
||||||
// Node has some number of additional frames below Jasmine.
|
// Node has some number of additional frames below Jasmine.
|
||||||
for (i = 2; i < lines.length; i++) {
|
for (let i = 2; i < lines.length; i++) {
|
||||||
expect(lines[i]).not.toMatch(/jasmine.js/);
|
expect(lines[i]).not.toMatch(/jasmine.js/);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles multiline error messages in this environment', function() {
|
it('handles multiline error messages in this environment', function() {
|
||||||
var error,
|
const msg = 'an error\nwith two lines';
|
||||||
msg = 'an error\nwith two lines';
|
const error = new Error(msg);
|
||||||
try {
|
|
||||||
throw new Error(msg);
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error.stack.indexOf(msg) === -1) {
|
if (error.stack.indexOf(msg) === -1) {
|
||||||
pending("Stack traces don't have messages in this environment");
|
pending("Stack traces don't have messages in this environment");
|
||||||
}
|
}
|
||||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||||
jasmineFile: jasmine.util.jasmineFile()
|
jasmineFile: jasmine.util.jasmineFile()
|
||||||
});
|
});
|
||||||
var result = subject.stack(error);
|
const result = subject.stack(error);
|
||||||
var lines = result.split('\n');
|
const lines = result.split('\n');
|
||||||
|
|
||||||
expect(lines[0]).toMatch(/an error/);
|
expect(lines[0]).toMatch(/an error/);
|
||||||
expect(lines[1]).toMatch(/with two lines/);
|
expect(lines[1]).toMatch(/with two lines/);
|
||||||
@@ -212,20 +197,28 @@ describe('ExceptionFormatter', function() {
|
|||||||
expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull();
|
expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('includes error properties in stack', function() {
|
it("includes the error's own properties in stack", function() {
|
||||||
var error;
|
const error = new Error('an error');
|
||||||
try {
|
|
||||||
throw new Error('an error');
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
error.someProperty = 'hello there';
|
error.someProperty = 'hello there';
|
||||||
|
|
||||||
var result = new jasmineUnderTest.ExceptionFormatter().stack(error);
|
const result = new jasmineUnderTest.ExceptionFormatter().stack(error);
|
||||||
|
|
||||||
expect(result).toMatch(/error properties:.*someProperty.*hello there/);
|
expect(result).toMatch(/error properties:.*someProperty.*hello there/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not include inherited error properties', function() {
|
||||||
|
function CustomError(msg) {
|
||||||
|
Error.call(this, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomError.prototype = new Error();
|
||||||
|
CustomError.prototype.anInheritedProp = 'something';
|
||||||
|
const error = new CustomError('nope');
|
||||||
|
|
||||||
|
const result = new jasmineUnderTest.ExceptionFormatter().stack(error);
|
||||||
|
expect(result).not.toContain('anInheritedProp');
|
||||||
|
});
|
||||||
|
|
||||||
describe('When omitMessage is true', function() {
|
describe('When omitMessage is true', function() {
|
||||||
it('filters the message from V8-style stack traces', function() {
|
it('filters the message from V8-style stack traces', function() {
|
||||||
const error = {
|
const error = {
|
||||||
@@ -268,12 +261,7 @@ describe('ExceptionFormatter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ensures that stack traces do not include the message in this environment', function() {
|
it('ensures that stack traces do not include the message in this environment', function() {
|
||||||
let error;
|
const error = new Error('an error');
|
||||||
try {
|
|
||||||
throw new Error('an error');
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||||
jasmineFile: jasmine.util.jasmineFile()
|
jasmineFile: jasmine.util.jasmineFile()
|
||||||
});
|
});
|
||||||
@@ -281,5 +269,61 @@ describe('ExceptionFormatter', function() {
|
|||||||
expect(result).not.toContain('an error');
|
expect(result).not.toContain('an error');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when the error has a cause property', function() {
|
||||||
|
it('recursively includes the cause in the stack trace in this environment', function() {
|
||||||
|
const subject = new jasmineUnderTest.ExceptionFormatter();
|
||||||
|
const rootCause = new Error('root cause');
|
||||||
|
const proximateCause = new Error('proximate cause', {
|
||||||
|
cause: rootCause
|
||||||
|
});
|
||||||
|
const symptom = new Error('symptom', { cause: proximateCause });
|
||||||
|
|
||||||
|
const lines = subject.stack(symptom).split('\n');
|
||||||
|
// Not all environments include the message in the stack trace.
|
||||||
|
const hasRootMessage = lines[0].indexOf('symptom') !== -1;
|
||||||
|
const firstSymptomStackIx = hasRootMessage ? 1 : 0;
|
||||||
|
|
||||||
|
expect(lines[firstSymptomStackIx])
|
||||||
|
.withContext('first symptom stack frame')
|
||||||
|
.toContain('ExceptionFormatterSpec.js');
|
||||||
|
const proximateCauseMsgIx = lines.indexOf(
|
||||||
|
'Caused by: Error: proximate cause'
|
||||||
|
);
|
||||||
|
expect(proximateCauseMsgIx)
|
||||||
|
.withContext('index of proximate cause message')
|
||||||
|
.toBeGreaterThan(firstSymptomStackIx);
|
||||||
|
expect(lines[proximateCauseMsgIx + 1])
|
||||||
|
.withContext('first proximate cause stack frame')
|
||||||
|
.toContain('ExceptionFormatterSpec.js');
|
||||||
|
const rootCauseMsgIx = lines.indexOf('Caused by: Error: root cause');
|
||||||
|
expect(rootCauseMsgIx)
|
||||||
|
.withContext('index of root cause message')
|
||||||
|
.toBeGreaterThan(proximateCauseMsgIx + 1);
|
||||||
|
expect(lines[rootCauseMsgIx + 1])
|
||||||
|
.withContext('first root cause stack frame')
|
||||||
|
.toContain('ExceptionFormatterSpec.js');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw if cause is a non Error', function() {
|
||||||
|
const formatter = new jasmineUnderTest.ExceptionFormatter();
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
formatter.stack(
|
||||||
|
new Error('error', {
|
||||||
|
cause: function() {}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}).not.toThrowError();
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
formatter.stack(
|
||||||
|
new Error('error', {
|
||||||
|
cause: 'another error'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}).not.toThrowError();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe('Exceptions:', function() {
|
describe('Exceptions:', function() {
|
||||||
var env;
|
let env;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
@@ -9,8 +9,8 @@ describe('Exceptions:', function() {
|
|||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle exceptions thrown, but continue', function(done) {
|
it('should handle exceptions thrown, but continue', async function() {
|
||||||
var secondTest = jasmine.createSpy('second test');
|
const secondTest = jasmine.createSpy('second test');
|
||||||
env.describe('Suite for handles exceptions', function() {
|
env.describe('Suite for handles exceptions', function() {
|
||||||
env.it(
|
env.it(
|
||||||
'should be a test that fails because it throws an exception',
|
'should be a test that fails because it throws an exception',
|
||||||
@@ -24,16 +24,13 @@ describe('Exceptions:', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
var expectations = function() {
|
await env.execute();
|
||||||
expect(secondTest).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
env.execute(null, expectations);
|
expect(secondTest).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
|
it('should handle exceptions thrown directly in top-level describe blocks and continue', async function() {
|
||||||
var secondDescribe = jasmine
|
const secondDescribe = jasmine
|
||||||
.createSpy('second describe')
|
.createSpy('second describe')
|
||||||
.and.callFake(function() {
|
.and.callFake(function() {
|
||||||
env.it('has a test', function() {});
|
env.it('has a test', function() {});
|
||||||
@@ -47,11 +44,8 @@ describe('Exceptions:', function() {
|
|||||||
});
|
});
|
||||||
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
||||||
|
|
||||||
var expectations = function() {
|
await env.execute();
|
||||||
expect(secondDescribe).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
env.execute(null, expectations);
|
expect(secondDescribe).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
describe('ExpectationFilterChain', function() {
|
describe('ExpectationFilterChain', function() {
|
||||||
describe('#addFilter', function() {
|
describe('#addFilter', function() {
|
||||||
it('returns a new filter chain with the added filter', function() {
|
it('returns a new filter chain with the added filter', function() {
|
||||||
var first = jasmine.createSpy('first'),
|
const first = jasmine.createSpy('first'),
|
||||||
second = jasmine.createSpy('second'),
|
second = jasmine.createSpy('second'),
|
||||||
orig = new jasmineUnderTest.ExpectationFilterChain({
|
orig = new jasmineUnderTest.ExpectationFilterChain({
|
||||||
modifyFailureMessage: first
|
modifyFailureMessage: first
|
||||||
@@ -15,7 +15,7 @@ describe('ExpectationFilterChain', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not modify the original filter chain', function() {
|
it('does not modify the original filter chain', function() {
|
||||||
var orig = new jasmineUnderTest.ExpectationFilterChain({}),
|
const orig = new jasmineUnderTest.ExpectationFilterChain({}),
|
||||||
f = jasmine.createSpy('f');
|
f = jasmine.createSpy('f');
|
||||||
|
|
||||||
orig.addFilter({ selectComparisonFunc: f });
|
orig.addFilter({ selectComparisonFunc: f });
|
||||||
@@ -28,7 +28,7 @@ describe('ExpectationFilterChain', function() {
|
|||||||
describe('#selectComparisonFunc', function() {
|
describe('#selectComparisonFunc', function() {
|
||||||
describe('When no filters have #selectComparisonFunc', function() {
|
describe('When no filters have #selectComparisonFunc', function() {
|
||||||
it('returns undefined', function() {
|
it('returns undefined', function() {
|
||||||
var chain = new jasmineUnderTest.ExpectationFilterChain();
|
const chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||||
chain.addFilter({});
|
chain.addFilter({});
|
||||||
expect(chain.selectComparisonFunc()).toBeUndefined();
|
expect(chain.selectComparisonFunc()).toBeUndefined();
|
||||||
});
|
});
|
||||||
@@ -36,15 +36,13 @@ describe('ExpectationFilterChain', function() {
|
|||||||
|
|
||||||
describe('When some filters have #selectComparisonFunc', function() {
|
describe('When some filters have #selectComparisonFunc', function() {
|
||||||
it('calls the first filter that has #selectComparisonFunc', function() {
|
it('calls the first filter that has #selectComparisonFunc', function() {
|
||||||
var first = jasmine.createSpy('first').and.returnValue('first'),
|
const first = jasmine.createSpy('first').and.returnValue('first'),
|
||||||
second = jasmine.createSpy('second').and.returnValue('second'),
|
second = jasmine.createSpy('second').and.returnValue('second'),
|
||||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||||
.addFilter({ selectComparisonFunc: first })
|
.addFilter({ selectComparisonFunc: first })
|
||||||
.addFilter({ selectComparisonFunc: second }),
|
.addFilter({ selectComparisonFunc: second }),
|
||||||
matcher = {},
|
matcher = {},
|
||||||
result;
|
result = chain.selectComparisonFunc(matcher);
|
||||||
|
|
||||||
result = chain.selectComparisonFunc(matcher);
|
|
||||||
|
|
||||||
expect(first).toHaveBeenCalledWith(matcher);
|
expect(first).toHaveBeenCalledWith(matcher);
|
||||||
expect(second).not.toHaveBeenCalled();
|
expect(second).not.toHaveBeenCalled();
|
||||||
@@ -56,7 +54,7 @@ describe('ExpectationFilterChain', function() {
|
|||||||
describe('#buildFailureMessage', function() {
|
describe('#buildFailureMessage', function() {
|
||||||
describe('When no filters have #buildFailureMessage', function() {
|
describe('When no filters have #buildFailureMessage', function() {
|
||||||
it('returns undefined', function() {
|
it('returns undefined', function() {
|
||||||
var chain = new jasmineUnderTest.ExpectationFilterChain();
|
const chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||||
chain.addFilter({});
|
chain.addFilter({});
|
||||||
expect(chain.buildFailureMessage()).toBeUndefined();
|
expect(chain.buildFailureMessage()).toBeUndefined();
|
||||||
});
|
});
|
||||||
@@ -64,7 +62,7 @@ describe('ExpectationFilterChain', function() {
|
|||||||
|
|
||||||
describe('When some filters have #buildFailureMessage', function() {
|
describe('When some filters have #buildFailureMessage', function() {
|
||||||
it('calls the first filter that has #buildFailureMessage', function() {
|
it('calls the first filter that has #buildFailureMessage', function() {
|
||||||
var first = jasmine.createSpy('first').and.returnValue('first'),
|
const first = jasmine.createSpy('first').and.returnValue('first'),
|
||||||
second = jasmine.createSpy('second').and.returnValue('second'),
|
second = jasmine.createSpy('second').and.returnValue('second'),
|
||||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||||
.addFilter({ buildFailureMessage: first })
|
.addFilter({ buildFailureMessage: first })
|
||||||
@@ -72,10 +70,9 @@ describe('ExpectationFilterChain', function() {
|
|||||||
matcherResult = { pass: false },
|
matcherResult = { pass: false },
|
||||||
matcherName = 'foo',
|
matcherName = 'foo',
|
||||||
args = [],
|
args = [],
|
||||||
matchersUtil = {},
|
matchersUtil = {};
|
||||||
result;
|
|
||||||
|
|
||||||
result = chain.buildFailureMessage(
|
const result = chain.buildFailureMessage(
|
||||||
matcherResult,
|
matcherResult,
|
||||||
matcherName,
|
matcherName,
|
||||||
args,
|
args,
|
||||||
@@ -97,7 +94,7 @@ describe('ExpectationFilterChain', function() {
|
|||||||
describe('#modifyFailureMessage', function() {
|
describe('#modifyFailureMessage', function() {
|
||||||
describe('When no filters have #modifyFailureMessage', function() {
|
describe('When no filters have #modifyFailureMessage', function() {
|
||||||
it('returns the original message', function() {
|
it('returns the original message', function() {
|
||||||
var chain = new jasmineUnderTest.ExpectationFilterChain();
|
const chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||||
chain.addFilter({});
|
chain.addFilter({});
|
||||||
expect(chain.modifyFailureMessage('msg')).toEqual('msg');
|
expect(chain.modifyFailureMessage('msg')).toEqual('msg');
|
||||||
});
|
});
|
||||||
@@ -105,14 +102,12 @@ describe('ExpectationFilterChain', function() {
|
|||||||
|
|
||||||
describe('When some filters have #modifyFailureMessage', function() {
|
describe('When some filters have #modifyFailureMessage', function() {
|
||||||
it('calls the first filter that has #modifyFailureMessage', function() {
|
it('calls the first filter that has #modifyFailureMessage', function() {
|
||||||
var first = jasmine.createSpy('first').and.returnValue('first'),
|
const first = jasmine.createSpy('first').and.returnValue('first'),
|
||||||
second = jasmine.createSpy('second').and.returnValue('second'),
|
second = jasmine.createSpy('second').and.returnValue('second'),
|
||||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||||
.addFilter({ modifyFailureMessage: first })
|
.addFilter({ modifyFailureMessage: first })
|
||||||
.addFilter({ modifyFailureMessage: second }),
|
.addFilter({ modifyFailureMessage: second }),
|
||||||
result;
|
result = chain.modifyFailureMessage('original');
|
||||||
|
|
||||||
result = chain.modifyFailureMessage('original');
|
|
||||||
|
|
||||||
expect(first).toHaveBeenCalledWith('original');
|
expect(first).toHaveBeenCalledWith('original');
|
||||||
expect(second).not.toHaveBeenCalled();
|
expect(second).not.toHaveBeenCalled();
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
describe('buildExpectationResult', function() {
|
|
||||||
it('defaults to passed', function() {
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: 'some-value'
|
|
||||||
});
|
|
||||||
expect(result.passed).toBe('some-value');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('message defaults to Passed for passing specs', function() {
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: true,
|
|
||||||
message: 'some-value'
|
|
||||||
});
|
|
||||||
expect(result.message).toBe('Passed.');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('message returns the message for failing expectations', function() {
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: false,
|
|
||||||
message: 'some-value'
|
|
||||||
});
|
|
||||||
expect(result.message).toBe('some-value');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('delegates message formatting to the provided formatter if there was an Error', function() {
|
|
||||||
var fakeError = { message: 'foo' },
|
|
||||||
messageFormatter = jasmine
|
|
||||||
.createSpy('exception message formatter')
|
|
||||||
.and.returnValue(fakeError.message);
|
|
||||||
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: false,
|
|
||||||
error: fakeError,
|
|
||||||
messageFormatter: messageFormatter
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(messageFormatter).toHaveBeenCalledWith(fakeError);
|
|
||||||
expect(result.message).toEqual('foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('delegates stack formatting to the provided formatter if there was an Error', function() {
|
|
||||||
var fakeError = { stack: 'foo' },
|
|
||||||
stackFormatter = jasmine
|
|
||||||
.createSpy('stack formatter')
|
|
||||||
.and.returnValue(fakeError.stack);
|
|
||||||
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: false,
|
|
||||||
error: fakeError,
|
|
||||||
stackFormatter: stackFormatter
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(stackFormatter).toHaveBeenCalledWith(fakeError, {
|
|
||||||
omitMessage: true
|
|
||||||
});
|
|
||||||
expect(result.stack).toEqual('foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('delegates stack formatting to the provided formatter if there was a provided errorForStack', function() {
|
|
||||||
var fakeError = { stack: 'foo' },
|
|
||||||
stackFormatter = jasmine
|
|
||||||
.createSpy('stack formatter')
|
|
||||||
.and.returnValue(fakeError.stack);
|
|
||||||
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: false,
|
|
||||||
errorForStack: fakeError,
|
|
||||||
stackFormatter: stackFormatter
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(stackFormatter).toHaveBeenCalledWith(fakeError, {
|
|
||||||
omitMessage: true
|
|
||||||
});
|
|
||||||
expect(result.stack).toEqual('foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('matcherName returns passed matcherName', function() {
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
matcherName: 'some-value'
|
|
||||||
});
|
|
||||||
expect(result.matcherName).toBe('some-value');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('expected returns passed expected', function() {
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
expected: 'some-value'
|
|
||||||
});
|
|
||||||
expect(result.expected).toBe('some-value');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('actual returns passed actual', function() {
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
actual: 'some-value'
|
|
||||||
});
|
|
||||||
expect(result.actual).toBe('some-value');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('handles nodejs assertions', function() {
|
|
||||||
if (typeof require === 'undefined') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var assert = require('assert');
|
|
||||||
var error;
|
|
||||||
var value = 8421;
|
|
||||||
var expectedValue = 'JasmineExpectationTestValue';
|
|
||||||
try {
|
|
||||||
assert.equal(value, expectedValue);
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error.code).toEqual('ERR_ASSERTION');
|
|
||||||
expect(error.actual).toEqual(value);
|
|
||||||
expect(error.expected).toEqual(expectedValue);
|
|
||||||
expect(error.operator).toEqual('==');
|
|
||||||
|
|
||||||
var result = jasmineUnderTest.buildExpectationResult({
|
|
||||||
passed: false,
|
|
||||||
matcherName: '',
|
|
||||||
expected: '',
|
|
||||||
actual: '',
|
|
||||||
error: error
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.code).toEqual('ERR_ASSERTION');
|
|
||||||
expect(result.actual).toEqual(value);
|
|
||||||
expect(result.expected).toEqual(expectedValue);
|
|
||||||
expect(result.matcherName).toEqual('assert ==');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,34 +1,31 @@
|
|||||||
describe('Expectation', function() {
|
describe('Expectation', function() {
|
||||||
it('makes custom matchers available to this expectation', function() {
|
it('makes custom matchers available to this expectation', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {},
|
toFoo: function() {},
|
||||||
toBar: function() {}
|
toBar: function() {}
|
||||||
},
|
},
|
||||||
expectation;
|
expectation = jasmineUnderTest.Expectation.factory({
|
||||||
|
customMatchers: matchers
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
});
|
||||||
customMatchers: matchers
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(expectation.toFoo).toBeDefined();
|
expect(expectation.toFoo).toBeDefined();
|
||||||
expect(expectation.toBar).toBeDefined();
|
expect(expectation.toBar).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('.addCoreMatchers makes matchers available to any expectation', function() {
|
it('.addCoreMatchers makes matchers available to any expectation', function() {
|
||||||
var coreMatchers = {
|
const coreMatchers = {
|
||||||
toQuux: function() {}
|
toQuux: function() {}
|
||||||
},
|
};
|
||||||
expectation;
|
|
||||||
|
|
||||||
jasmineUnderTest.Expectation.addCoreMatchers(coreMatchers);
|
jasmineUnderTest.Expectation.addCoreMatchers(coreMatchers);
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({});
|
const expectation = jasmineUnderTest.Expectation.factory({});
|
||||||
|
|
||||||
expect(expectation.toQuux).toBeDefined();
|
expect(expectation.toQuux).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("wraps matchers's compare functions, passing in matcher dependencies", function() {
|
it("wraps matchers's compare functions, passing in matcher dependencies", function() {
|
||||||
var fakeCompare = function() {
|
const fakeCompare = function() {
|
||||||
return { pass: true };
|
return { pass: true };
|
||||||
},
|
},
|
||||||
matcherFactory = jasmine
|
matcherFactory = jasmine
|
||||||
@@ -40,10 +37,9 @@ describe('Expectation', function() {
|
|||||||
matchersUtil = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -56,7 +52,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
||||||
var fakeCompare = jasmine
|
const fakeCompare = jasmine
|
||||||
.createSpy('fake-compare')
|
.createSpy('fake-compare')
|
||||||
.and.returnValue({ pass: true }),
|
.and.returnValue({ pass: true }),
|
||||||
matchers = {
|
matchers = {
|
||||||
@@ -69,10 +65,9 @@ describe('Expectation', function() {
|
|||||||
matchersUtil = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -85,7 +80,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a passing result to the spec when the comparison passes', function() {
|
it('reports a passing result to the spec when the comparison passes', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -97,10 +92,9 @@ describe('Expectation', function() {
|
|||||||
matchersUtil = {
|
matchersUtil = {
|
||||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -121,7 +115,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result to the spec when the comparison fails', function() {
|
it('reports a failing result to the spec when the comparison fails', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -135,10 +129,9 @@ describe('Expectation', function() {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
@@ -159,7 +152,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result and a custom fail message to the spec when the comparison fails', function() {
|
it('reports a failing result and a custom fail message to the spec when the comparison fails', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -171,10 +164,9 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -194,7 +186,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result with a custom fail message function to the spec when the comparison fails', function() {
|
it('reports a failing result with a custom fail message function to the spec when the comparison fails', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -208,10 +200,9 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -231,7 +222,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a passing result to the spec when the comparison fails for a negative expectation', function() {
|
it('reports a passing result to the spec when the comparison fails for a negative expectation', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -241,10 +232,9 @@ describe('Expectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual';
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -264,7 +254,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result to the spec when the comparison passes for a negative expectation', function() {
|
it('reports a failing result to the spec when the comparison passes for a negative expectation', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -279,10 +269,9 @@ describe('Expectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual';
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
matchersUtil: matchersUtil,
|
matchersUtil: matchersUtil,
|
||||||
@@ -303,7 +292,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failing result and a custom fail message to the spec when the comparison passes for a negative expectation', function() {
|
it('reports a failing result and a custom fail message to the spec when the comparison passes for a negative expectation', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -316,10 +305,9 @@ describe('Expectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual';
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -339,7 +327,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a passing result to the spec when the 'not' comparison passes, given a negativeCompare", function() {
|
it("reports a passing result to the spec when the 'not' comparison passes, given a negativeCompare", function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -352,10 +340,9 @@ describe('Expectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual';
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -375,7 +362,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a failing result and a custom fail message to the spec when the 'not' comparison fails, given a negativeCompare", function() {
|
it("reports a failing result and a custom fail message to the spec when the 'not' comparison fails, given a negativeCompare", function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -391,10 +378,9 @@ describe('Expectation', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||||
actual = 'an actual',
|
actual = 'an actual';
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -414,8 +400,8 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a custom error message to the spec', function() {
|
it('reports a custom error message to the spec', function() {
|
||||||
var customError = new Error('I am a custom error');
|
const customError = new Error('I am a custom error');
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -428,10 +414,9 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -451,8 +436,8 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a custom message to the spec when a 'not' comparison fails", function() {
|
it("reports a custom message to the spec when a 'not' comparison fails", function() {
|
||||||
var customError = new Error('I am a custom error');
|
const customError = new Error('I am a custom error');
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -465,10 +450,9 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -488,8 +472,8 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a custom message func to the spec when a 'not' comparison fails", function() {
|
it("reports a custom message func to the spec when a 'not' comparison fails", function() {
|
||||||
var customError = new Error('I am a custom error');
|
const customError = new Error('I am a custom error');
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -504,10 +488,9 @@ describe('Expectation', function() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||||
expectation;
|
|
||||||
|
|
||||||
expectation = jasmineUnderTest.Expectation.factory({
|
const expectation = jasmineUnderTest.Expectation.factory({
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
@@ -528,7 +511,7 @@ describe('Expectation', function() {
|
|||||||
|
|
||||||
describe('#withContext', function() {
|
describe('#withContext', function() {
|
||||||
it('prepends the context to the generated failure message', function() {
|
it('prepends the context to the generated failure message', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -561,7 +544,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prepends the context to a custom failure message', function() {
|
it('prepends the context to a custom failure message', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -588,7 +571,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('indents a multiline failure message', function() {
|
it('indents a multiline failure message', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -602,19 +585,18 @@ describe('Expectation', function() {
|
|||||||
customMatchers: matchers,
|
customMatchers: matchers,
|
||||||
actual: 'an actual',
|
actual: 'an actual',
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
}),
|
});
|
||||||
actualMessage;
|
|
||||||
|
|
||||||
expectation.withContext('Some context').toFoo('hello');
|
expectation.withContext('Some context').toFoo('hello');
|
||||||
|
|
||||||
actualMessage = addExpectationResult.calls.argsFor(0)[1].message;
|
const actualMessage = addExpectationResult.calls.argsFor(0)[1].message;
|
||||||
expect(actualMessage).toEqual(
|
expect(actualMessage).toEqual(
|
||||||
'Some context:\n a\n multiline\n message'
|
'Some context:\n a\n multiline\n message'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prepends the context to a custom failure message from a function', function() {
|
it('prepends the context to a custom failure message from a function', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -646,7 +628,7 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('works with #not', function() {
|
it('works with #not', function() {
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
@@ -675,8 +657,8 @@ describe('Expectation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('works with #not and a custom message', function() {
|
it('works with #not and a custom message', function() {
|
||||||
var customError = new Error('I am a custom error');
|
const customError = new Error('I am a custom error');
|
||||||
var matchers = {
|
const matchers = {
|
||||||
toFoo: function() {
|
toFoo: function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
|
|||||||
@@ -1,75 +1,65 @@
|
|||||||
describe('GlobalErrors', function() {
|
describe('GlobalErrors', function() {
|
||||||
it('calls the added handler on error', function() {
|
it('calls the added handler on error', function() {
|
||||||
var fakeGlobal = { onerror: null },
|
const fakeGlobal = browserGlobal();
|
||||||
handler = jasmine.createSpy('errorHandler'),
|
const handler = jasmine.createSpy('errorHandler');
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
errors.pushListener(handler);
|
errors.pushListener(handler);
|
||||||
|
|
||||||
fakeGlobal.onerror('foo');
|
const error = new Error('nope');
|
||||||
|
dispatchErrorEvent(fakeGlobal, { error });
|
||||||
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'),
|
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
|
||||||
fooError = new Error('foo');
|
|
||||||
|
|
||||||
errors.install();
|
|
||||||
errors.pushListener(handler);
|
|
||||||
|
|
||||||
fakeGlobal.onerror(fooError.message, 'foo.js', 1, 1, fooError);
|
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledWith(
|
expect(handler).toHaveBeenCalledWith(
|
||||||
fooError.message,
|
jasmine.is(error),
|
||||||
'foo.js',
|
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||||
1,
|
);
|
||||||
1,
|
});
|
||||||
fooError
|
|
||||||
|
it('is not affected by overriding global.onerror', function() {
|
||||||
|
const fakeGlobal = browserGlobal();
|
||||||
|
const handler = jasmine.createSpy('errorHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
|
||||||
|
fakeGlobal.onerror = () => {};
|
||||||
|
|
||||||
|
const error = new Error('nope');
|
||||||
|
dispatchErrorEvent(fakeGlobal, { error });
|
||||||
|
|
||||||
|
expect(handler).toHaveBeenCalledWith(
|
||||||
|
jasmine.is(error),
|
||||||
|
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only calls the most recent handler', function() {
|
it('only calls the most recent handler', function() {
|
||||||
var fakeGlobal = { onerror: null },
|
const fakeGlobal = browserGlobal();
|
||||||
handler1 = jasmine.createSpy('errorHandler1'),
|
const handler1 = jasmine.createSpy('errorHandler1');
|
||||||
handler2 = jasmine.createSpy('errorHandler2'),
|
const handler2 = jasmine.createSpy('errorHandler2');
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
errors.pushListener(handler1);
|
errors.pushListener(handler1);
|
||||||
errors.pushListener(handler2);
|
errors.pushListener(handler2);
|
||||||
|
|
||||||
fakeGlobal.onerror('foo');
|
const error = new Error('nope');
|
||||||
|
dispatchErrorEvent(fakeGlobal, { error });
|
||||||
|
|
||||||
expect(handler1).not.toHaveBeenCalled();
|
expect(handler1).not.toHaveBeenCalled();
|
||||||
expect(handler2).toHaveBeenCalledWith('foo');
|
expect(handler2).toHaveBeenCalledWith(
|
||||||
|
jasmine.is(error),
|
||||||
|
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls previous handlers when one is removed', function() {
|
it('calls previous handlers when one is removed', function() {
|
||||||
var fakeGlobal = { onerror: null },
|
const fakeGlobal = browserGlobal();
|
||||||
handler1 = jasmine.createSpy('errorHandler1'),
|
const handler1 = jasmine.createSpy('errorHandler1');
|
||||||
handler2 = jasmine.createSpy('errorHandler2'),
|
const handler2 = jasmine.createSpy('errorHandler2');
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
errors.pushListener(handler1);
|
errors.pushListener(handler1);
|
||||||
@@ -77,44 +67,44 @@ describe('GlobalErrors', function() {
|
|||||||
|
|
||||||
errors.popListener(handler2);
|
errors.popListener(handler2);
|
||||||
|
|
||||||
fakeGlobal.onerror('foo');
|
const error = new Error('nope');
|
||||||
|
dispatchErrorEvent(fakeGlobal, { error });
|
||||||
|
|
||||||
expect(handler1).toHaveBeenCalledWith('foo');
|
expect(handler1).toHaveBeenCalledWith(
|
||||||
|
jasmine.is(error),
|
||||||
|
jasmine.objectContaining({ error: jasmine.is(error) })
|
||||||
|
);
|
||||||
expect(handler2).not.toHaveBeenCalled();
|
expect(handler2).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws when no listener is passed to #popListener', function() {
|
it('throws when no listener is passed to #popListener', function() {
|
||||||
var errors = new jasmineUnderTest.GlobalErrors({});
|
const errors = new jasmineUnderTest.GlobalErrors({});
|
||||||
expect(function() {
|
expect(function() {
|
||||||
errors.popListener();
|
errors.popListener();
|
||||||
}).toThrowError('popListener expects a listener');
|
}).toThrowError('popListener expects a listener');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uninstalls itself, putting back a previous callback', function() {
|
it('uninstalls itself', function() {
|
||||||
var originalCallback = jasmine.createSpy('error'),
|
const fakeGlobal = browserGlobal();
|
||||||
fakeGlobal = { onerror: originalCallback },
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
function unrelatedListener() {}
|
||||||
|
|
||||||
expect(fakeGlobal.onerror).toBe(originalCallback);
|
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
|
fakeGlobal.addEventListener('error', unrelatedListener);
|
||||||
expect(fakeGlobal.onerror).not.toBe(originalCallback);
|
|
||||||
|
|
||||||
errors.uninstall();
|
errors.uninstall();
|
||||||
|
|
||||||
expect(fakeGlobal.onerror).toBe(originalCallback);
|
expect(fakeGlobal.listeners_.error).toEqual([unrelatedListener]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rethrows the original error when there is no handler', function() {
|
it('rethrows the original error when there is no handler', function() {
|
||||||
var fakeGlobal = {},
|
const fakeGlobal = browserGlobal();
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
originalError = new Error('nope');
|
const originalError = new Error('nope');
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fakeGlobal.onerror(originalError);
|
dispatchErrorEvent(fakeGlobal, { error: originalError });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toBe(originalError);
|
expect(e).toBe(originalError);
|
||||||
}
|
}
|
||||||
@@ -123,7 +113,7 @@ describe('GlobalErrors', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports uncaught exceptions in node.js', function() {
|
it('reports uncaught exceptions in node.js', function() {
|
||||||
var fakeGlobal = {
|
const fakeGlobal = {
|
||||||
process: {
|
process: {
|
||||||
on: jasmine.createSpy('process.on'),
|
on: jasmine.createSpy('process.on'),
|
||||||
removeListener: jasmine.createSpy('process.removeListener'),
|
removeListener: jasmine.createSpy('process.removeListener'),
|
||||||
@@ -150,7 +140,7 @@ describe('GlobalErrors', function() {
|
|||||||
|
|
||||||
errors.pushListener(handler);
|
errors.pushListener(handler);
|
||||||
|
|
||||||
var addedListener = fakeGlobal.process.on.calls.argsFor(0)[1];
|
const addedListener = fakeGlobal.process.on.calls.argsFor(0)[1];
|
||||||
addedListener(new Error('bar'));
|
addedListener(new Error('bar'));
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
||||||
@@ -172,7 +162,7 @@ describe('GlobalErrors', function() {
|
|||||||
|
|
||||||
describe('Reporting unhandled promise rejections in node.js', function() {
|
describe('Reporting unhandled promise rejections in node.js', function() {
|
||||||
it('reports rejections with `Error` reasons', function() {
|
it('reports rejections with `Error` reasons', function() {
|
||||||
var fakeGlobal = {
|
const fakeGlobal = {
|
||||||
process: {
|
process: {
|
||||||
on: jasmine.createSpy('process.on'),
|
on: jasmine.createSpy('process.on'),
|
||||||
removeListener: jasmine.createSpy('process.removeListener'),
|
removeListener: jasmine.createSpy('process.removeListener'),
|
||||||
@@ -199,7 +189,7 @@ describe('GlobalErrors', function() {
|
|||||||
|
|
||||||
errors.pushListener(handler);
|
errors.pushListener(handler);
|
||||||
|
|
||||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
const addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||||
addedListener(new Error('bar'));
|
addedListener(new Error('bar'));
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
||||||
@@ -220,7 +210,7 @@ describe('GlobalErrors', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports rejections with non-`Error` reasons', function() {
|
it('reports rejections with non-`Error` reasons', function() {
|
||||||
var fakeGlobal = {
|
const fakeGlobal = {
|
||||||
process: {
|
process: {
|
||||||
on: jasmine.createSpy('process.on'),
|
on: jasmine.createSpy('process.on'),
|
||||||
removeListener: function() {},
|
removeListener: function() {},
|
||||||
@@ -239,7 +229,7 @@ describe('GlobalErrors', function() {
|
|||||||
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
||||||
'unhandledRejection'
|
'unhandledRejection'
|
||||||
);
|
);
|
||||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
const addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||||
addedListener(17);
|
addedListener(17);
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledWith(
|
expect(handler).toHaveBeenCalledWith(
|
||||||
@@ -252,7 +242,7 @@ describe('GlobalErrors', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports rejections with no reason provided', function() {
|
it('reports rejections with no reason provided', function() {
|
||||||
var fakeGlobal = {
|
const fakeGlobal = {
|
||||||
process: {
|
process: {
|
||||||
on: jasmine.createSpy('process.on'),
|
on: jasmine.createSpy('process.on'),
|
||||||
removeListener: function() {},
|
removeListener: function() {},
|
||||||
@@ -271,7 +261,7 @@ describe('GlobalErrors', function() {
|
|||||||
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
||||||
'unhandledRejection'
|
'unhandledRejection'
|
||||||
);
|
);
|
||||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
const addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||||
addedListener(undefined);
|
addedListener(undefined);
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledWith(
|
expect(handler).toHaveBeenCalledWith(
|
||||||
@@ -286,136 +276,239 @@ describe('GlobalErrors', function() {
|
|||||||
|
|
||||||
describe('Reporting unhandled promise rejections in the browser', function() {
|
describe('Reporting unhandled promise rejections in the browser', function() {
|
||||||
it('subscribes and unsubscribes from the unhandledrejection event', function() {
|
it('subscribes and unsubscribes from the unhandledrejection event', function() {
|
||||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
const fakeGlobal = browserGlobal();
|
||||||
'addEventListener',
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
'removeEventListener',
|
|
||||||
'onerror'
|
|
||||||
]),
|
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
expect(fakeGlobal.addEventListener).toHaveBeenCalledWith(
|
expect(fakeGlobal.listeners_.unhandledrejection).toEqual([
|
||||||
'unhandledrejection',
|
|
||||||
jasmine.any(Function)
|
jasmine.any(Function)
|
||||||
);
|
]);
|
||||||
|
|
||||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
|
||||||
errors.uninstall();
|
errors.uninstall();
|
||||||
|
expect(fakeGlobal.listeners_.unhandledrejection).toEqual([]);
|
||||||
expect(fakeGlobal.removeEventListener).toHaveBeenCalledWith(
|
|
||||||
'unhandledrejection',
|
|
||||||
addedListener
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports rejections whose reason is a string', function() {
|
it('reports rejections whose reason is a string', function() {
|
||||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
const fakeGlobal = browserGlobal();
|
||||||
'addEventListener',
|
const handler = jasmine.createSpy('errorHandler');
|
||||||
'removeEventListener',
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
'onerror'
|
|
||||||
]),
|
|
||||||
handler = jasmine.createSpy('errorHandler'),
|
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
errors.pushListener(handler);
|
errors.pushListener(handler);
|
||||||
|
|
||||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
const event = { reason: 'nope' };
|
||||||
addedListener({ reason: 'nope' });
|
dispatchUnhandledRejectionEvent(fakeGlobal, event);
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledWith('Unhandled promise rejection: nope');
|
expect(handler).toHaveBeenCalledWith(
|
||||||
|
'Unhandled promise rejection: nope',
|
||||||
|
event
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports rejections whose reason is an Error', function() {
|
it('reports rejections whose reason is an Error', function() {
|
||||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
const fakeGlobal = browserGlobal();
|
||||||
'addEventListener',
|
const handler = jasmine.createSpy('errorHandler');
|
||||||
'removeEventListener',
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
'onerror'
|
|
||||||
]),
|
|
||||||
handler = jasmine.createSpy('errorHandler'),
|
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
errors.pushListener(handler);
|
errors.pushListener(handler);
|
||||||
|
|
||||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
const reason = new Error('bar');
|
||||||
var reason;
|
const event = { reason };
|
||||||
|
dispatchUnhandledRejectionEvent(fakeGlobal, event);
|
||||||
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(
|
expect(handler).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||||
message: reason.message,
|
message: reason.message,
|
||||||
stack: reason.stack
|
stack: reason.stack
|
||||||
})
|
}),
|
||||||
|
event
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Enabling external interception of reported rejections by overriding global.onerror', function() {
|
describe('#setOverrideListener', function() {
|
||||||
it('overriding global.onerror intercepts rejections whose reason is a string', function() {
|
it('overrides the existing handlers in browsers until removed', function() {
|
||||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
const fakeGlobal = browserGlobal();
|
||||||
'addEventListener'
|
const handler0 = jasmine.createSpy('handler0');
|
||||||
]),
|
const handler1 = jasmine.createSpy('handler1');
|
||||||
handler = jasmine.createSpy('errorHandler'),
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
|
||||||
|
|
||||||
errors.install();
|
errors.install();
|
||||||
errors.pushListener(handler);
|
errors.pushListener(handler0);
|
||||||
|
errors.setOverrideListener(overrideHandler, () => {});
|
||||||
|
errors.pushListener(handler1);
|
||||||
|
dispatchErrorEvent(fakeGlobal, { error: 'foo' });
|
||||||
|
|
||||||
fakeGlobal.onerror = hijackHandler;
|
expect(overrideHandler).toHaveBeenCalledWith('foo');
|
||||||
|
expect(handler0).not.toHaveBeenCalled();
|
||||||
|
expect(handler1).not.toHaveBeenCalled();
|
||||||
|
|
||||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
errors.removeOverrideListener();
|
||||||
addedListener({ reason: 'nope' });
|
|
||||||
|
|
||||||
expect(hijackHandler).toHaveBeenCalledWith(
|
const event = { error: 'baz' };
|
||||||
'Unhandled promise rejection: nope'
|
dispatchErrorEvent(fakeGlobal, event);
|
||||||
);
|
expect(overrideHandler).not.toHaveBeenCalledWith('baz');
|
||||||
expect(handler).not.toHaveBeenCalled();
|
expect(handler1).toHaveBeenCalledWith('baz', event);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('overriding global.onerror intercepts rejections whose reason is an Error', function() {
|
it('overrides the existing handlers in Node until removed', function() {
|
||||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
const globalEventListeners = {};
|
||||||
'addEventListener'
|
const fakeGlobal = {
|
||||||
]),
|
process: {
|
||||||
handler = jasmine.createSpy('errorHandler'),
|
on: (name, listener) => (globalEventListeners[name] = listener),
|
||||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
removeListener: () => {},
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
listeners: name => globalEventListeners[name],
|
||||||
|
removeAllListeners: name => (globalEventListeners[name] = [])
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
const handler0 = jasmine.createSpy('handler0');
|
||||||
|
const handler1 = jasmine.createSpy('handler1');
|
||||||
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
addedListener({ reason: reason });
|
errors.install();
|
||||||
|
errors.pushListener(handler0);
|
||||||
|
errors.setOverrideListener(overrideHandler);
|
||||||
|
errors.pushListener(handler1);
|
||||||
|
|
||||||
expect(hijackHandler).toHaveBeenCalledWith(
|
globalEventListeners['uncaughtException'](new Error('foo'));
|
||||||
jasmine.objectContaining({
|
|
||||||
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
expect(overrideHandler).toHaveBeenCalledWith(new Error('foo'));
|
||||||
message: reason.message,
|
expect(handler0).not.toHaveBeenCalled();
|
||||||
stack: reason.stack
|
expect(handler1).not.toHaveBeenCalled();
|
||||||
})
|
|
||||||
);
|
errors.removeOverrideListener();
|
||||||
expect(handler).not.toHaveBeenCalled();
|
|
||||||
});
|
globalEventListeners['uncaughtException'](new Error('bar'));
|
||||||
|
expect(overrideHandler).not.toHaveBeenCalledWith(new Error('bar'));
|
||||||
|
expect(handler1).toHaveBeenCalledWith(new Error('bar'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles unhandled promise rejections in browsers', function() {
|
||||||
|
const globalEventListeners = {};
|
||||||
|
const fakeGlobal = {
|
||||||
|
addEventListener(name, listener) {
|
||||||
|
globalEventListeners[name] = listener;
|
||||||
|
},
|
||||||
|
removeEventListener() {}
|
||||||
|
};
|
||||||
|
const handler = jasmine.createSpy('handler');
|
||||||
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler);
|
||||||
|
errors.setOverrideListener(overrideHandler, () => {});
|
||||||
|
|
||||||
|
const reason = new Error('bar');
|
||||||
|
|
||||||
|
globalEventListeners['unhandledrejection']({ reason: reason });
|
||||||
|
|
||||||
|
expect(overrideHandler).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||||
|
message: reason.message,
|
||||||
|
stack: reason.stack
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(handler).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles unhandled promise rejections in Node', function() {
|
||||||
|
const globalEventListeners = {};
|
||||||
|
const fakeGlobal = {
|
||||||
|
process: {
|
||||||
|
on(name, listener) {
|
||||||
|
globalEventListeners[name] = listener;
|
||||||
|
},
|
||||||
|
removeListener() {},
|
||||||
|
listeners(name) {
|
||||||
|
return globalEventListeners[name];
|
||||||
|
},
|
||||||
|
removeAllListeners(name) {
|
||||||
|
globalEventListeners[name] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handler0 = jasmine.createSpy('handler0');
|
||||||
|
const handler1 = jasmine.createSpy('handler1');
|
||||||
|
const overrideHandler = jasmine.createSpy('overrideHandler');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||||
|
|
||||||
|
errors.install();
|
||||||
|
errors.pushListener(handler0);
|
||||||
|
errors.setOverrideListener(overrideHandler, () => {});
|
||||||
|
errors.pushListener(handler1);
|
||||||
|
|
||||||
|
globalEventListeners['unhandledRejection'](new Error('nope'));
|
||||||
|
|
||||||
|
expect(overrideHandler).toHaveBeenCalledWith(new Error('nope'));
|
||||||
|
expect(handler0).not.toHaveBeenCalled();
|
||||||
|
expect(handler1).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws if there is already an override handler', function() {
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(browserGlobal());
|
||||||
|
|
||||||
|
errors.setOverrideListener(() => {}, () => {});
|
||||||
|
expect(function() {
|
||||||
|
errors.setOverrideListener(() => {}, () => {});
|
||||||
|
}).toThrowError("Can't set more than one override listener at a time");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#removeOverrideListener', function() {
|
||||||
|
it("calls the handler's onRemove callback", function() {
|
||||||
|
const onRemove = jasmine.createSpy('onRemove');
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(browserGlobal());
|
||||||
|
|
||||||
|
errors.setOverrideListener(() => {}, onRemove);
|
||||||
|
errors.removeOverrideListener();
|
||||||
|
|
||||||
|
expect(onRemove).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not throw if there is no handler', function() {
|
||||||
|
const errors = new jasmineUnderTest.GlobalErrors(browserGlobal());
|
||||||
|
|
||||||
|
expect(() => errors.removeOverrideListener()).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function browserGlobal() {
|
||||||
|
return {
|
||||||
|
listeners_: { error: [], unhandledrejection: [] },
|
||||||
|
addEventListener(eventName, listener) {
|
||||||
|
this.listeners_[eventName].push(listener);
|
||||||
|
},
|
||||||
|
removeEventListener(eventName, listener) {
|
||||||
|
this.listeners_[eventName] = this.listeners_[eventName].filter(
|
||||||
|
l => l !== listener
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function dispatchErrorEvent(global, event) {
|
||||||
|
expect(global.listeners_.error.length)
|
||||||
|
.withContext('number of error listeners')
|
||||||
|
.toBeGreaterThan(0);
|
||||||
|
|
||||||
|
for (const l of global.listeners_.error) {
|
||||||
|
l(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function dispatchUnhandledRejectionEvent(global, event) {
|
||||||
|
expect(global.listeners_.unhandledrejection.length)
|
||||||
|
.withContext('number of unhandledrejection listeners')
|
||||||
|
.toBeGreaterThan(0);
|
||||||
|
|
||||||
|
for (const l of global.listeners_.unhandledrejection) {
|
||||||
|
l(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('JsApiReporter', function() {
|
describe('JsApiReporter', function() {
|
||||||
it('knows when a full environment is started', function() {
|
it('knows when a full environment is started', function() {
|
||||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
|
|
||||||
expect(reporter.started).toBe(false);
|
expect(reporter.started).toBe(false);
|
||||||
expect(reporter.finished).toBe(false);
|
expect(reporter.finished).toBe(false);
|
||||||
@@ -12,7 +12,7 @@ describe('JsApiReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('knows when a full environment is done', function() {
|
it('knows when a full environment is done', function() {
|
||||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
|
|
||||||
expect(reporter.started).toBe(false);
|
expect(reporter.started).toBe(false);
|
||||||
expect(reporter.finished).toBe(false);
|
expect(reporter.finished).toBe(false);
|
||||||
@@ -24,13 +24,13 @@ describe('JsApiReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("defaults to 'loaded' status", function() {
|
it("defaults to 'loaded' status", function() {
|
||||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
|
|
||||||
expect(reporter.status()).toEqual('loaded');
|
expect(reporter.status()).toEqual('loaded');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports 'started' when Jasmine has started", function() {
|
it("reports 'started' when Jasmine has started", function() {
|
||||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
|
|
||||||
reporter.jasmineStarted();
|
reporter.jasmineStarted();
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ describe('JsApiReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports 'done' when Jasmine is done", function() {
|
it("reports 'done' when Jasmine is done", function() {
|
||||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
|
|
||||||
reporter.jasmineDone({});
|
reporter.jasmineDone({});
|
||||||
|
|
||||||
@@ -46,14 +46,14 @@ describe('JsApiReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('tracks a suite', function() {
|
it('tracks a suite', function() {
|
||||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
|
|
||||||
reporter.suiteStarted({
|
reporter.suiteStarted({
|
||||||
id: 123,
|
id: 123,
|
||||||
description: 'A suite'
|
description: 'A suite'
|
||||||
});
|
});
|
||||||
|
|
||||||
var suites = reporter.suites();
|
const suites = reporter.suites();
|
||||||
|
|
||||||
expect(suites).toEqual({ 123: { id: 123, description: 'A suite' } });
|
expect(suites).toEqual({ 123: { id: 123, description: 'A suite' } });
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ describe('JsApiReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#specResults', function() {
|
describe('#specResults', function() {
|
||||||
var reporter, specResult1, specResult2;
|
let reporter, specResult1, specResult2;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
reporter = new jasmineUnderTest.JsApiReporter({});
|
reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
specResult1 = {
|
specResult1 = {
|
||||||
@@ -99,7 +99,7 @@ describe('JsApiReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#suiteResults', function() {
|
describe('#suiteResults', function() {
|
||||||
var reporter, suiteStarted1, suiteResult1, suiteResult2;
|
let reporter, suiteStarted1, suiteResult1, suiteResult2;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
reporter = new jasmineUnderTest.JsApiReporter({});
|
reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
suiteStarted1 = {
|
suiteStarted1 = {
|
||||||
@@ -137,7 +137,7 @@ describe('JsApiReporter', function() {
|
|||||||
|
|
||||||
describe('#executionTime', function() {
|
describe('#executionTime', function() {
|
||||||
it('should start the timer when jasmine starts', function() {
|
it('should start the timer when jasmine starts', function() {
|
||||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
const timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
reporter = new jasmineUnderTest.JsApiReporter({
|
reporter = new jasmineUnderTest.JsApiReporter({
|
||||||
timer: timerSpy
|
timer: timerSpy
|
||||||
});
|
});
|
||||||
@@ -147,7 +147,7 @@ describe('JsApiReporter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the time it took the specs to run, in ms', function() {
|
it('should return the time it took the specs to run, in ms', function() {
|
||||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
const timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
reporter = new jasmineUnderTest.JsApiReporter({
|
reporter = new jasmineUnderTest.JsApiReporter({
|
||||||
timer: timerSpy
|
timer: timerSpy
|
||||||
});
|
});
|
||||||
@@ -159,7 +159,7 @@ describe('JsApiReporter', function() {
|
|||||||
|
|
||||||
describe("when the specs haven't finished being run", function() {
|
describe("when the specs haven't finished being run", function() {
|
||||||
it('should return undefined', function() {
|
it('should return undefined', function() {
|
||||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
const timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
reporter = new jasmineUnderTest.JsApiReporter({
|
reporter = new jasmineUnderTest.JsApiReporter({
|
||||||
timer: timerSpy
|
timer: timerSpy
|
||||||
});
|
});
|
||||||
@@ -171,7 +171,7 @@ describe('JsApiReporter', function() {
|
|||||||
|
|
||||||
describe('#runDetails', function() {
|
describe('#runDetails', function() {
|
||||||
it('should have details about the run', function() {
|
it('should have details about the run', function() {
|
||||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||||
reporter.jasmineDone({ some: { run: 'details' } });
|
reporter.jasmineDone({ some: { run: 'details' } });
|
||||||
expect(reporter.runDetails).toEqual({ some: { run: 'details' } });
|
expect(reporter.runDetails).toEqual({ some: { run: 'details' } });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('FakeDate', function() {
|
describe('FakeDate', function() {
|
||||||
it('does not fail if no global date is found', function() {
|
it('does not fail if no global date is found', function() {
|
||||||
var fakeGlobal = {},
|
const fakeGlobal = {},
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -11,11 +11,13 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('replaces the global Date when it is installed', function() {
|
it('replaces the global Date when it is installed', function() {
|
||||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
const globalDate = jasmine
|
||||||
return {
|
.createSpy('global Date')
|
||||||
getTime: function() {}
|
.and.callFake(function() {
|
||||||
};
|
return {
|
||||||
}),
|
getTime: function() {}
|
||||||
|
};
|
||||||
|
}),
|
||||||
fakeGlobal = { Date: globalDate },
|
fakeGlobal = { Date: globalDate },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
@@ -26,11 +28,13 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('replaces the global Date on uninstall', function() {
|
it('replaces the global Date on uninstall', function() {
|
||||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
const globalDate = jasmine
|
||||||
return {
|
.createSpy('global Date')
|
||||||
getTime: function() {}
|
.and.callFake(function() {
|
||||||
};
|
return {
|
||||||
}),
|
getTime: function() {}
|
||||||
|
};
|
||||||
|
}),
|
||||||
fakeGlobal = { Date: globalDate },
|
fakeGlobal = { Date: globalDate },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
@@ -41,13 +45,15 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('takes the current time as the base when installing without parameters', function() {
|
it('takes the current time as the base when installing without parameters', function() {
|
||||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
const globalDate = jasmine
|
||||||
return {
|
.createSpy('global Date')
|
||||||
getTime: function() {
|
.and.callFake(function() {
|
||||||
return 1000;
|
return {
|
||||||
}
|
getTime: function() {
|
||||||
};
|
return 1000;
|
||||||
}),
|
}
|
||||||
|
};
|
||||||
|
}),
|
||||||
fakeGlobal = { Date: globalDate },
|
fakeGlobal = { Date: globalDate },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
@@ -59,7 +65,7 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can accept a date as time base when installing', function() {
|
it('can accept a date as time base when installing', function() {
|
||||||
var fakeGlobal = { Date: Date },
|
const fakeGlobal = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
|
||||||
baseDate = new Date();
|
baseDate = new Date();
|
||||||
|
|
||||||
@@ -70,7 +76,7 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('makes real dates', function() {
|
it('makes real dates', function() {
|
||||||
var fakeGlobal = { Date: Date },
|
const fakeGlobal = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
@@ -79,17 +85,19 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('fakes current time when using Date.now()', function() {
|
it('fakes current time when using Date.now()', function() {
|
||||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
const globalDate = jasmine
|
||||||
return {
|
.createSpy('global Date')
|
||||||
getTime: function() {
|
.and.callFake(function() {
|
||||||
return 1000;
|
return {
|
||||||
}
|
getTime: function() {
|
||||||
};
|
return 1000;
|
||||||
}),
|
}
|
||||||
|
};
|
||||||
|
}),
|
||||||
fakeGlobal = { Date: globalDate };
|
fakeGlobal = { Date: globalDate };
|
||||||
|
|
||||||
globalDate.now = function() {};
|
globalDate.now = function() {};
|
||||||
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
const mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
|
|
||||||
@@ -97,17 +105,19 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('makes time passes using tick', function() {
|
it('makes time passes using tick', function() {
|
||||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
const globalDate = jasmine
|
||||||
return {
|
.createSpy('global Date')
|
||||||
getTime: function() {
|
.and.callFake(function() {
|
||||||
return 1000;
|
return {
|
||||||
}
|
getTime: function() {
|
||||||
};
|
return 1000;
|
||||||
}),
|
}
|
||||||
|
};
|
||||||
|
}),
|
||||||
fakeGlobal = { Date: globalDate };
|
fakeGlobal = { Date: globalDate };
|
||||||
|
|
||||||
globalDate.now = function() {};
|
globalDate.now = function() {};
|
||||||
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
const mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
|
|
||||||
@@ -121,17 +131,19 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows to increase 0 milliseconds using tick', function() {
|
it('allows to increase 0 milliseconds using tick', function() {
|
||||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
const globalDate = jasmine
|
||||||
return {
|
.createSpy('global Date')
|
||||||
getTime: function() {
|
.and.callFake(function() {
|
||||||
return 1000;
|
return {
|
||||||
}
|
getTime: function() {
|
||||||
};
|
return 1000;
|
||||||
}),
|
}
|
||||||
|
};
|
||||||
|
}),
|
||||||
fakeGlobal = { Date: globalDate };
|
fakeGlobal = { Date: globalDate };
|
||||||
|
|
||||||
globalDate.now = function() {};
|
globalDate.now = function() {};
|
||||||
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
const mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
|
|
||||||
@@ -143,40 +155,40 @@ describe('FakeDate', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows creation of a Date in a different time than the mocked time', function() {
|
it('allows creation of a Date in a different time than the mocked time', function() {
|
||||||
var fakeGlobal = { Date: Date },
|
const fakeGlobal = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
|
|
||||||
var otherDate = new fakeGlobal.Date(2013, 9, 23, 0, 0, 1, 0);
|
const otherDate = new fakeGlobal.Date(2013, 9, 23, 0, 0, 1, 0);
|
||||||
expect(otherDate.getTime()).toEqual(
|
expect(otherDate.getTime()).toEqual(
|
||||||
new Date(2013, 9, 23, 0, 0, 1, 0).getTime()
|
new Date(2013, 9, 23, 0, 0, 1, 0).getTime()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows creation of a Date that isn't fully specified", function() {
|
it("allows creation of a Date that isn't fully specified", function() {
|
||||||
var fakeGlobal = { Date: Date },
|
const fakeGlobal = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
|
|
||||||
var otherDate = new fakeGlobal.Date(2013, 9, 23);
|
const otherDate = new fakeGlobal.Date(2013, 9, 23);
|
||||||
expect(otherDate.getTime()).toEqual(new Date(2013, 9, 23).getTime());
|
expect(otherDate.getTime()).toEqual(new Date(2013, 9, 23).getTime());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows creation of a Date with millis', function() {
|
it('allows creation of a Date with millis', function() {
|
||||||
var fakeGlobal = { Date: Date },
|
const fakeGlobal = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
|
||||||
now = new Date(2014, 3, 15).getTime();
|
now = new Date(2014, 3, 15).getTime();
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
|
|
||||||
var otherDate = new fakeGlobal.Date(now);
|
const otherDate = new fakeGlobal.Date(now);
|
||||||
expect(otherDate.getTime()).toEqual(now);
|
expect(otherDate.getTime()).toEqual(now);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('copies all Date properties to the mocked date', function() {
|
it('copies all Date properties to the mocked date', function() {
|
||||||
var fakeGlobal = { Date: Date },
|
const fakeGlobal = { Date: Date },
|
||||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||||
|
|
||||||
mockDate.install();
|
mockDate.install();
|
||||||
|
|||||||
176
spec/core/ParallelReportDispatcherSpec.js
Normal file
176
spec/core/ParallelReportDispatcherSpec.js
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
describe('ParallelReportDispatcher', function() {
|
||||||
|
it('dispatches the standard reporter events', async function() {
|
||||||
|
const subject = new jasmineUnderTest.ParallelReportDispatcher(() => {}, {
|
||||||
|
globalErrors: mockGlobalErrors()
|
||||||
|
});
|
||||||
|
const events = [
|
||||||
|
'jasmineStarted',
|
||||||
|
'jasmineDone',
|
||||||
|
'suiteStarted',
|
||||||
|
'suiteDone',
|
||||||
|
'specStarted',
|
||||||
|
'specDone'
|
||||||
|
];
|
||||||
|
const reporter = jasmine.createSpyObj('reporter', events);
|
||||||
|
subject.addReporter(reporter);
|
||||||
|
|
||||||
|
for (const eventName of events) {
|
||||||
|
const payload = { payloadFor: eventName };
|
||||||
|
await subject[eventName](payload);
|
||||||
|
expect(reporter[eventName]).toHaveBeenCalledWith(payload);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('installs and uninstalls the global error handler', function() {
|
||||||
|
const globalErrors = mockGlobalErrors();
|
||||||
|
const subject = new jasmineUnderTest.ParallelReportDispatcher(() => {}, {
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
|
||||||
|
subject.installGlobalErrors();
|
||||||
|
expect(globalErrors.install).toHaveBeenCalled();
|
||||||
|
|
||||||
|
subject.uninstallGlobalErrors();
|
||||||
|
expect(globalErrors.uninstall).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles global errors from async reporters', async function() {
|
||||||
|
const globalErrors = mockGlobalErrors();
|
||||||
|
const onError = jasmine.createSpy('onError');
|
||||||
|
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
const reporter = jasmine.createSpyObj('reporter', [
|
||||||
|
'jasmineStarted',
|
||||||
|
'jasmineDone'
|
||||||
|
]);
|
||||||
|
let resolveStarted;
|
||||||
|
reporter.jasmineStarted.and.callFake(function() {
|
||||||
|
return new Promise(function(res) {
|
||||||
|
resolveStarted = res;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
subject.addReporter(reporter);
|
||||||
|
|
||||||
|
const promise = subject.jasmineStarted({});
|
||||||
|
expect(globalErrors.pushListener).toHaveBeenCalled();
|
||||||
|
expect(globalErrors.popListener).not.toHaveBeenCalled();
|
||||||
|
const error = new Error('nope');
|
||||||
|
globalErrors.pushListener.calls.argsFor(0)[0](error);
|
||||||
|
expect(onError).toHaveBeenCalledWith(error);
|
||||||
|
|
||||||
|
resolveStarted();
|
||||||
|
await promise;
|
||||||
|
expect(globalErrors.popListener).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles done(error) from callback-style async reporters', function() {
|
||||||
|
const globalErrors = mockGlobalErrors();
|
||||||
|
const onError = jasmine.createSpy('onError');
|
||||||
|
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
const reporter = jasmine.createSpyObj('reporter', [
|
||||||
|
'jasmineStarted',
|
||||||
|
'jasmineDone'
|
||||||
|
]);
|
||||||
|
let callback;
|
||||||
|
reporter.jasmineStarted = function(event, cb) {
|
||||||
|
callback = cb;
|
||||||
|
};
|
||||||
|
subject.addReporter(reporter);
|
||||||
|
|
||||||
|
subject.jasmineStarted({});
|
||||||
|
|
||||||
|
expect(callback).toBeInstanceOf(Function);
|
||||||
|
const error = new Error('nope');
|
||||||
|
callback(error);
|
||||||
|
|
||||||
|
expect(onError).toHaveBeenCalledWith(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles done.fail() from callback-style async reporters', function() {
|
||||||
|
const globalErrors = mockGlobalErrors();
|
||||||
|
const onError = jasmine.createSpy('onError');
|
||||||
|
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
const reporter = jasmine.createSpyObj('reporter', [
|
||||||
|
'jasmineStarted',
|
||||||
|
'jasmineDone'
|
||||||
|
]);
|
||||||
|
let callback;
|
||||||
|
reporter.jasmineStarted = function(event, cb) {
|
||||||
|
callback = cb;
|
||||||
|
};
|
||||||
|
subject.addReporter(reporter);
|
||||||
|
|
||||||
|
subject.jasmineStarted({});
|
||||||
|
|
||||||
|
expect(callback).toBeInstanceOf(Function);
|
||||||
|
const error = new Error('nope');
|
||||||
|
callback.fail(error);
|
||||||
|
expect(onError).toHaveBeenCalledWith(error);
|
||||||
|
onError.calls.reset();
|
||||||
|
|
||||||
|
callback.fail();
|
||||||
|
expect(onError).toHaveBeenCalledWith(
|
||||||
|
new Error('A reporter called done.fail()')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles errors due to mixed async style in reporters', async function() {
|
||||||
|
const globalErrors = mockGlobalErrors();
|
||||||
|
const onError = jasmine.createSpy('onError');
|
||||||
|
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
subject.addReporter({
|
||||||
|
async jasmineStarted(event, done) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await subject.jasmineStarted({});
|
||||||
|
expect(onError).toHaveBeenCalledWith(
|
||||||
|
new Error(
|
||||||
|
'An asynchronous before/it/after function took a done callback but also returned a promise. Either remove the done callback (recommended) or change the function to not return a promise.'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles errors due to multiple done calls in reporters', async function() {
|
||||||
|
const globalErrors = mockGlobalErrors();
|
||||||
|
const onError = jasmine.createSpy('onError');
|
||||||
|
const subject = new jasmineUnderTest.ParallelReportDispatcher(onError, {
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
subject.addReporter({
|
||||||
|
jasmineStarted(event, done) {
|
||||||
|
done();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await subject.jasmineStarted({});
|
||||||
|
expect(onError).toHaveBeenCalledWith(
|
||||||
|
new Error(
|
||||||
|
"An asynchronous reporter callback called its 'done' callback more than once."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function mockGlobalErrors() {
|
||||||
|
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'install',
|
||||||
|
'pushListener',
|
||||||
|
'popListener'
|
||||||
|
]);
|
||||||
|
|
||||||
|
globalErrors.install.and.callFake(function() {
|
||||||
|
globalErrors.uninstall = jasmine.createSpy('globalErrors.uninstall');
|
||||||
|
});
|
||||||
|
|
||||||
|
return globalErrors;
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,12 +1,20 @@
|
|||||||
describe('PrettyPrinter', function() {
|
describe('PrettyPrinter', function() {
|
||||||
it('should wrap strings in single quotes', function() {
|
it('should wrap strings in single quotes', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp('some string')).toEqual("'some string'");
|
expect(pp('some string')).toEqual("'some string'");
|
||||||
expect(pp("som' string")).toEqual("'som' string'");
|
expect(pp("som' string")).toEqual("'som' string'");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stringifies empty string primitives and objects recognizably', function() {
|
||||||
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp(new String(''))).toEqual(pp(''));
|
||||||
|
expect(pp(new String(''))).toEqual("''");
|
||||||
|
expect(pp([new String('')])).toEqual(pp(['']));
|
||||||
|
expect(pp([new String('')])).toEqual("[ '' ]");
|
||||||
|
});
|
||||||
|
|
||||||
it('should stringify primitives properly', function() {
|
it('should stringify primitives properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp(true)).toEqual('true');
|
expect(pp(true)).toEqual('true');
|
||||||
expect(pp(false)).toEqual('false');
|
expect(pp(false)).toEqual('false');
|
||||||
expect(pp(null)).toEqual('null');
|
expect(pp(null)).toEqual('null');
|
||||||
@@ -18,23 +26,23 @@ describe('PrettyPrinter', function() {
|
|||||||
|
|
||||||
describe('stringify sets', function() {
|
describe('stringify sets', function() {
|
||||||
it('should stringify sets properly', function() {
|
it('should stringify sets properly', function() {
|
||||||
var set = new Set();
|
const set = new Set();
|
||||||
set.add(1);
|
set.add(1);
|
||||||
set.add(2);
|
set.add(2);
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp(set)).toEqual('Set( 1, 2 )');
|
expect(pp(set)).toEqual('Set( 1, 2 )');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should truncate sets with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
it('should truncate sets with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||||
var originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
const originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
var set = new Set();
|
const set = new Set();
|
||||||
set.add('a');
|
set.add('a');
|
||||||
set.add('b');
|
set.add('b');
|
||||||
set.add('c');
|
set.add('c');
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp(set)).toEqual("Set( 'a', 'b', ... )");
|
expect(pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||||
@@ -44,22 +52,22 @@ describe('PrettyPrinter', function() {
|
|||||||
|
|
||||||
describe('stringify maps', function() {
|
describe('stringify maps', function() {
|
||||||
it('should stringify maps properly', function() {
|
it('should stringify maps properly', function() {
|
||||||
var map = new Map();
|
const map = new Map();
|
||||||
map.set(1, 2);
|
map.set(1, 2);
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp(map)).toEqual('Map( [ 1, 2 ] )');
|
expect(pp(map)).toEqual('Map( [ 1, 2 ] )');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should truncate maps with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
it('should truncate maps with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||||
var originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
const originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
var map = new Map();
|
const map = new Map();
|
||||||
map.set('a', 1);
|
map.set('a', 1);
|
||||||
map.set('b', 2);
|
map.set('b', 2);
|
||||||
map.set('c', 3);
|
map.set('c', 3);
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
expect(pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||||
} finally {
|
} finally {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||||
@@ -69,17 +77,22 @@ describe('PrettyPrinter', function() {
|
|||||||
|
|
||||||
describe('stringify arrays', function() {
|
describe('stringify arrays', function() {
|
||||||
it('should stringify arrays properly', function() {
|
it('should stringify arrays properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp([1, 2])).toEqual('[ 1, 2 ]');
|
expect(pp([1, 2])).toEqual('[ 1, 2 ]');
|
||||||
expect(pp([1, 'foo', {}, jasmine.undefined, null])).toEqual(
|
expect(pp([1, 'foo', {}, jasmine.undefined, null])).toEqual(
|
||||||
"[ 1, 'foo', Object({ }), undefined, null ]"
|
"[ 1, 'foo', Object({ }), undefined, null ]"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('includes symbols', function() {
|
||||||
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
expect(pp([1, Symbol('foo'), 2])).toEqual('[ 1, Symbol(foo), 2 ]');
|
||||||
|
});
|
||||||
|
|
||||||
it('should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
it('should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
const originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
var array = [1, 2, 3];
|
const array = [1, 2, 3];
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
@@ -90,25 +103,25 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify arrays with properties properly', function() {
|
it('should stringify arrays with properties properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var arr = [1, 2];
|
const arr = [1, 2];
|
||||||
arr.foo = 'bar';
|
arr.foo = 'bar';
|
||||||
arr.baz = {};
|
arr.baz = {};
|
||||||
expect(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() {
|
it('should stringify empty arrays with properties properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var empty = [];
|
const empty = [];
|
||||||
empty.foo = 'bar';
|
empty.foo = 'bar';
|
||||||
empty.baz = {};
|
empty.baz = {};
|
||||||
expect(pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
|
expect(pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify long arrays with properties properly', function() {
|
it('should stringify long arrays with properties properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
const originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
var long = [1, 2, 3];
|
const long = [1, 2, 3];
|
||||||
long.foo = 'bar';
|
long.foo = 'bar';
|
||||||
long.baz = {};
|
long.baz = {};
|
||||||
|
|
||||||
@@ -123,22 +136,22 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should indicate circular array references', function() {
|
it('should indicate circular array references', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var array1 = [1, 2];
|
const array1 = [1, 2];
|
||||||
var array2 = [array1];
|
const array2 = [array1];
|
||||||
array1.push(array2);
|
array1.push(array2);
|
||||||
expect(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() {
|
it('should not indicate circular references incorrectly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var array = [[1]];
|
const array = [[1]];
|
||||||
expect(pp(array)).toEqual('[ [ 1 ] ]');
|
expect(pp(array)).toEqual('[ [ 1 ] ]');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects properly', function() {
|
it('should stringify objects properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp({ foo: 'bar' })).toEqual("Object({ foo: 'bar' })");
|
expect(pp({ foo: 'bar' })).toEqual("Object({ foo: 'bar' })");
|
||||||
expect(
|
expect(
|
||||||
pp({
|
pp({
|
||||||
@@ -155,15 +168,34 @@ describe('PrettyPrinter', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('includes symbol keys in objects', function() {
|
||||||
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
const obj = {};
|
||||||
|
obj[Symbol('foo')] = 'bar';
|
||||||
|
expect(pp(obj)).toEqual("Object({ Symbol(foo): 'bar' })");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stringifies string and symbol keys differently', function() {
|
||||||
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
const symObj = {};
|
||||||
|
const strObj = {};
|
||||||
|
const k = 'foo';
|
||||||
|
const v = 'bar';
|
||||||
|
symObj[Symbol(k)] = v;
|
||||||
|
strObj[k] = v;
|
||||||
|
|
||||||
|
expect(pp(symObj)).not.toEqual(pp(strObj));
|
||||||
|
});
|
||||||
|
|
||||||
it('should stringify objects that almost look like DOM nodes', function() {
|
it('should stringify objects that almost look like DOM nodes', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp({ nodeType: 1 })).toEqual('Object({ nodeType: 1 })');
|
expect(pp({ nodeType: 1 })).toEqual('Object({ nodeType: 1 })');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should truncate objects with too many keys', function() {
|
it('should truncate objects with too many keys', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
const originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||||
var long = { a: 1, b: 2, c: 3 };
|
const long = { a: 1, b: 2, c: 3 };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||||
@@ -174,7 +206,7 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function withMaxChars(maxChars, fn) {
|
function withMaxChars(maxChars, fn) {
|
||||||
var originalMaxChars = jasmineUnderTest.MAX_PRETTY_PRINT_CHARS;
|
const originalMaxChars = jasmineUnderTest.MAX_PRETTY_PRINT_CHARS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_CHARS = maxChars;
|
jasmineUnderTest.MAX_PRETTY_PRINT_CHARS = maxChars;
|
||||||
@@ -185,8 +217,8 @@ describe('PrettyPrinter', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should truncate outputs that are too long', function() {
|
it('should truncate outputs that are too long', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var big = [{ a: 1, b: 'a long string' }, {}];
|
const big = [{ a: 1, b: 'a long string' }, {}];
|
||||||
|
|
||||||
withMaxChars(34, function() {
|
withMaxChars(34, function() {
|
||||||
expect(pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
expect(pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
||||||
@@ -194,7 +226,7 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not serialize more objects after hitting MAX_PRETTY_PRINT_CHARS', function() {
|
it('should not serialize more objects after hitting MAX_PRETTY_PRINT_CHARS', function() {
|
||||||
var a = {
|
const a = {
|
||||||
jasmineToString: function() {
|
jasmineToString: function() {
|
||||||
return 'object a';
|
return 'object a';
|
||||||
}
|
}
|
||||||
@@ -224,25 +256,25 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp({ constructor: function() {} })).toContain('null({');
|
expect(pp({ constructor: function() {} })).toContain('null({');
|
||||||
expect(pp({ constructor: 'foo' })).toContain('null({');
|
expect(pp({ constructor: 'foo' })).toContain('null({');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not include inherited properties when stringifying an object', function() {
|
it('should not include inherited properties when stringifying an object', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var SomeClass = function SomeClass() {};
|
const SomeClass = function SomeClass() {};
|
||||||
SomeClass.prototype.foo = 'inherited foo';
|
SomeClass.prototype.foo = 'inherited foo';
|
||||||
var instance = new SomeClass();
|
const instance = new SomeClass();
|
||||||
instance.bar = 'my own bar';
|
instance.bar = 'my own bar';
|
||||||
expect(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() {
|
it('should not recurse objects and arrays more deeply than jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
|
const originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
|
||||||
var nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
const nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
||||||
var nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
const nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
|
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
|
||||||
@@ -268,8 +300,8 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify immutable circular objects', function() {
|
it('should stringify immutable circular objects', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var frozenObject = { foo: { bar: 'baz' } };
|
let frozenObject = { foo: { bar: 'baz' } };
|
||||||
frozenObject.circular = frozenObject;
|
frozenObject.circular = frozenObject;
|
||||||
frozenObject = Object.freeze(frozenObject);
|
frozenObject = Object.freeze(frozenObject);
|
||||||
expect(pp(frozenObject)).toEqual(
|
expect(pp(frozenObject)).toEqual(
|
||||||
@@ -278,52 +310,52 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify RegExp objects properly', function() {
|
it('should stringify RegExp objects properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp(/x|y|z/)).toEqual('/x|y|z/');
|
expect(pp(/x|y|z/)).toEqual('/x|y|z/');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should indicate circular object references', function() {
|
it('should indicate circular object references', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var sampleValue = { foo: 'hello' };
|
const sampleValue = { foo: 'hello' };
|
||||||
sampleValue.nested = sampleValue;
|
sampleValue.nested = sampleValue;
|
||||||
expect(pp(sampleValue)).toEqual(
|
expect(pp(sampleValue)).toEqual(
|
||||||
"Object({ foo: 'hello', nested: <circular reference: Object> })"
|
"Object({ foo: 'hello', nested: <circular reference: Object> })"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should indicate getters on objects as such', function() {
|
it('should use the return value of getters', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var sampleValue = {
|
const sampleValue = {
|
||||||
id: 1,
|
id: 1,
|
||||||
get calculatedValue() {
|
get calculatedValue() {
|
||||||
throw new Error("don't call me!");
|
return 'the getter return value';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
expect(pp(sampleValue)).toEqual(
|
expect(pp(sampleValue)).toEqual(
|
||||||
'Object({ id: 1, calculatedValue: <getter> })'
|
"Object({ id: 1, calculatedValue: 'the getter return value' })"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not do HTML escaping of strings', function() {
|
it('should not do HTML escaping of strings', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp('some <b>html string</b> &', false)).toEqual(
|
expect(pp('some <b>html string</b> &', false)).toEqual(
|
||||||
"'some <b>html string</b> &'"
|
"'some <b>html string</b> &'"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should abbreviate the global (usually window) object', function() {
|
it('should abbreviate the global (usually window) object', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
expect(pp(jasmine.getGlobal())).toEqual('<global>');
|
expect(pp(jasmine.getGlobal())).toEqual('<global>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify Date objects properly', function() {
|
it('should stringify Date objects properly', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var now = new Date();
|
const now = new Date();
|
||||||
expect(pp(now)).toEqual('Date(' + now.toString() + ')');
|
expect(pp(now)).toEqual('Date(' + now.toString() + ')');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with a spy object', function() {
|
describe('with a spy object', function() {
|
||||||
var env, pp;
|
let env, pp;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
@@ -335,11 +367,11 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify spy objects properly', function() {
|
it('should stringify spy objects properly', function() {
|
||||||
var TestObject = {
|
const TestObject = {
|
||||||
someFunction: function() {}
|
someFunction: function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
@@ -355,13 +387,13 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify spyOn toString properly', function() {
|
it('should stringify spyOn toString properly', function() {
|
||||||
var TestObject = {
|
const TestObject = {
|
||||||
someFunction: function() {}
|
someFunction: function() {}
|
||||||
},
|
},
|
||||||
env = new jasmineUnderTest.Env(),
|
env = new jasmineUnderTest.Env(),
|
||||||
pp = jasmineUnderTest.makePrettyPrinter();
|
pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
|
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
@@ -371,15 +403,15 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
spyRegistry.spyOn(TestObject, 'toString');
|
spyRegistry.spyOn(TestObject, 'toString');
|
||||||
var testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
const testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
||||||
|
|
||||||
expect(pp(testSpyObj)).toEqual('spy on TheClassName.toString');
|
expect(pp(testSpyObj)).toEqual('spy on TheClassName.toString');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects that implement jasmineToString', function() {
|
it('should stringify objects that implement jasmineToString', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
const obj = {
|
||||||
jasmineToString: function() {
|
jasmineToString: function() {
|
||||||
return 'strung';
|
return 'strung';
|
||||||
}
|
}
|
||||||
@@ -389,8 +421,8 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should pass itself to jasmineToString', function() {
|
it('should pass itself to jasmineToString', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter([]);
|
const pp = jasmineUnderTest.makePrettyPrinter([]);
|
||||||
var obj = {
|
const obj = {
|
||||||
jasmineToString: jasmine.createSpy('jasmineToString').and.returnValue('')
|
jasmineToString: jasmine.createSpy('jasmineToString').and.returnValue('')
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -399,8 +431,8 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects that implement custom toString', function() {
|
it('should stringify objects that implement custom toString', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
const obj = {
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return 'my toString';
|
return 'my toString';
|
||||||
}
|
}
|
||||||
@@ -410,7 +442,7 @@ describe('PrettyPrinter', function() {
|
|||||||
|
|
||||||
// Simulate object from another global context (e.g. an iframe or Web Worker) that does not actually have a custom
|
// Simulate object from another global context (e.g. an iframe or Web Worker) that does not actually have a custom
|
||||||
// toString despite obj.toString !== Object.prototype.toString
|
// toString despite obj.toString !== Object.prototype.toString
|
||||||
var objFromOtherContext = {
|
const objFromOtherContext = {
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return Object.prototype.toString.call(this);
|
return Object.prototype.toString.call(this);
|
||||||
@@ -423,8 +455,8 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should stringify objects have have a toString that isn't a function", function() {
|
it("should stringify objects have have a toString that isn't a function", function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
const obj = {
|
||||||
toString: 'foo'
|
toString: 'foo'
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -432,30 +464,30 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should stringify objects from anonymous constructors with custom toString', function() {
|
it('should stringify objects from anonymous constructors with custom toString', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var MyAnonymousConstructor = (function() {
|
const MyAnonymousConstructor = (function() {
|
||||||
return function() {};
|
return function() {};
|
||||||
})();
|
})();
|
||||||
MyAnonymousConstructor.toString = function() {
|
MyAnonymousConstructor.toString = function() {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
var a = new MyAnonymousConstructor();
|
const a = new MyAnonymousConstructor();
|
||||||
|
|
||||||
expect(pp(a)).toEqual('<anonymous>({ })');
|
expect(pp(a)).toEqual('<anonymous>({ })');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle objects with null prototype', function() {
|
it('should handle objects with null prototype', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = Object.create(null);
|
const obj = Object.create(null);
|
||||||
obj.foo = 'bar';
|
obj.foo = 'bar';
|
||||||
|
|
||||||
expect(pp(obj)).toEqual("null({ foo: 'bar' })");
|
expect(pp(obj)).toEqual("null({ foo: 'bar' })");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should gracefully handle objects with invalid toString implementations', function() {
|
it('should gracefully handle objects with invalid toString implementations', function() {
|
||||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||||
var obj = {
|
const obj = {
|
||||||
foo: {
|
foo: {
|
||||||
toString: function() {
|
toString: function() {
|
||||||
// Invalid: toString returning a number
|
// Invalid: toString returning a number
|
||||||
@@ -491,8 +523,8 @@ describe('PrettyPrinter', function() {
|
|||||||
|
|
||||||
describe('Custom object formatters', function() {
|
describe('Custom object formatters', function() {
|
||||||
it('should use the first custom object formatter that does not return undefined', function() {
|
it('should use the first custom object formatter that does not return undefined', function() {
|
||||||
var customObjectFormatters = [
|
const customObjectFormatters = [
|
||||||
function(obj) {
|
function() {
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
function(obj) {
|
function(obj) {
|
||||||
@@ -509,8 +541,8 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fall back to built in logic if all custom object formatters return undefined', function() {
|
it('should fall back to built in logic if all custom object formatters return undefined', function() {
|
||||||
var customObjectFormatters = [
|
const customObjectFormatters = [
|
||||||
function(obj) {
|
function() {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -523,8 +555,8 @@ describe('PrettyPrinter', function() {
|
|||||||
|
|
||||||
describe('#customFormat_', function() {
|
describe('#customFormat_', function() {
|
||||||
it('should use the first custom object formatter that does not return undefined', function() {
|
it('should use the first custom object formatter that does not return undefined', function() {
|
||||||
var customObjectFormatters = [
|
const customObjectFormatters = [
|
||||||
function(obj) {
|
function() {
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
function(obj) {
|
function(obj) {
|
||||||
@@ -541,8 +573,8 @@ describe('PrettyPrinter', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined if all custom object formatters return undefined', function() {
|
it('should return undefined if all custom object formatters return undefined', function() {
|
||||||
var customObjectFormatters = [
|
const customObjectFormatters = [
|
||||||
function(obj) {
|
function() {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('QueueRunner', function() {
|
describe('QueueRunner', function() {
|
||||||
it("runs all the functions it's passed", function() {
|
it("runs all the functions it's passed", function() {
|
||||||
var calls = [],
|
const calls = [],
|
||||||
queueableFn1 = { fn: jasmine.createSpy('fn1') },
|
queueableFn1 = { fn: jasmine.createSpy('fn1') },
|
||||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
@@ -19,9 +19,10 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("calls each function with a consistent 'this'-- an empty object", function() {
|
it("calls each function with a consistent 'this'-- an empty object", function() {
|
||||||
var queueableFn1 = { fn: jasmine.createSpy('fn1') },
|
const queueableFn1 = { fn: jasmine.createSpy('fn1') };
|
||||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
const queueableFn2 = { fn: jasmine.createSpy('fn2') };
|
||||||
queueableFn3 = {
|
let asyncContext;
|
||||||
|
const queueableFn3 = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
asyncContext = this;
|
asyncContext = this;
|
||||||
done();
|
done();
|
||||||
@@ -29,12 +30,11 @@ describe('QueueRunner', function() {
|
|||||||
},
|
},
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
queueableFns: [queueableFn1, queueableFn2, queueableFn3]
|
queueableFns: [queueableFn1, queueableFn2, queueableFn3]
|
||||||
}),
|
});
|
||||||
asyncContext;
|
|
||||||
|
|
||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
|
|
||||||
var context = queueableFn1.fn.calls.first().object;
|
const context = queueableFn1.fn.calls.first().object;
|
||||||
expect(context).toEqual(new jasmineUnderTest.UserContext());
|
expect(context).toEqual(new jasmineUnderTest.UserContext());
|
||||||
expect(queueableFn2.fn.calls.first().object).toBe(context);
|
expect(queueableFn2.fn.calls.first().object).toBe(context);
|
||||||
expect(asyncContext).toBe(context);
|
expect(asyncContext).toBe(context);
|
||||||
@@ -53,7 +53,7 @@ describe('QueueRunner', function() {
|
|||||||
//TODO: it would be nice if spy arity could match the fake, so we could do something like:
|
//TODO: it would be nice if spy arity could match the fake, so we could do something like:
|
||||||
//createSpy('asyncfn').and.callFake(function(done) {});
|
//createSpy('asyncfn').and.callFake(function(done) {});
|
||||||
|
|
||||||
var onComplete = jasmine.createSpy('onComplete'),
|
const onComplete = jasmine.createSpy('onComplete'),
|
||||||
beforeCallback = jasmine.createSpy('beforeCallback'),
|
beforeCallback = jasmine.createSpy('beforeCallback'),
|
||||||
fnCallback = jasmine.createSpy('fnCallback'),
|
fnCallback = jasmine.createSpy('fnCallback'),
|
||||||
afterCallback = jasmine.createSpy('afterCallback'),
|
afterCallback = jasmine.createSpy('afterCallback'),
|
||||||
@@ -104,7 +104,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('explicitly fails an async function with a provided fail function and moves to the next function', function() {
|
it('explicitly fails an async function with a provided fail function and moves to the next function', function() {
|
||||||
var queueableFn1 = {
|
const queueableFn1 = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
done.fail('foo');
|
done.fail('foo');
|
||||||
@@ -131,7 +131,7 @@ describe('QueueRunner', function() {
|
|||||||
|
|
||||||
describe('When next is called with an argument', function() {
|
describe('When next is called with an argument', function() {
|
||||||
it('explicitly fails and moves to the next function', function() {
|
it('explicitly fails and moves to the next function', function() {
|
||||||
var err = 'anything except undefined',
|
const err = 'anything except undefined',
|
||||||
queueableFn1 = {
|
queueableFn1 = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@@ -156,10 +156,62 @@ describe('QueueRunner', function() {
|
|||||||
expect(failFn).toHaveBeenCalledWith(err);
|
expect(failFn).toHaveBeenCalledWith(err);
|
||||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('as a result of a promise', function() {
|
||||||
|
describe('and the argument is an Error', function() {
|
||||||
|
// Since promise support was added, Jasmine has failed specs that
|
||||||
|
// return a promise that resolves to an error. That's probably not
|
||||||
|
// the desired behavior but it's also not something we should change
|
||||||
|
// except on a major release and with a deprecation warning in
|
||||||
|
// advance.
|
||||||
|
it('explicitly fails and moves to the next function', function(done) {
|
||||||
|
const err = new Error('foo'),
|
||||||
|
queueableFn1 = {
|
||||||
|
fn: function() {
|
||||||
|
return Promise.resolve(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||||
|
failFn = jasmine.createSpy('fail'),
|
||||||
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
|
queueableFns: [queueableFn1, queueableFn2],
|
||||||
|
fail: failFn,
|
||||||
|
onComplete: function() {
|
||||||
|
expect(failFn).toHaveBeenCalledWith(err);
|
||||||
|
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
queueRunner.execute();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and the argument is not an Error', function() {
|
||||||
|
it('does not report a failure', function(done) {
|
||||||
|
const queueableFn1 = {
|
||||||
|
fn: function() {
|
||||||
|
return Promise.resolve('not an error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
failFn = jasmine.createSpy('fail'),
|
||||||
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
|
queueableFns: [queueableFn1],
|
||||||
|
fail: failFn,
|
||||||
|
onComplete: function() {
|
||||||
|
expect(failFn).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
queueRunner.execute();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not cause an explicit fail if execution is being stopped', function() {
|
it('does not cause an explicit fail if execution is being stopped', function() {
|
||||||
var err = new jasmineUnderTest.StopExecutionError('foo'),
|
const err = new jasmineUnderTest.StopExecutionError('foo'),
|
||||||
queueableFn1 = {
|
queueableFn1 = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@@ -186,7 +238,8 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
|
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
|
||||||
var timeout = 3,
|
const timeout = 3,
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
beforeFn = { fn: function(done) {}, type: 'before', timeout: timeout },
|
beforeFn = { fn: function(done) {}, type: 'before', timeout: timeout },
|
||||||
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
|
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
|
||||||
onComplete = jasmine.createSpy('onComplete'),
|
onComplete = jasmine.createSpy('onComplete'),
|
||||||
@@ -208,22 +261,22 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not call onMultipleDone if an asynchrnous function completes after timing out', function() {
|
it('does not call onMultipleDone if an asynchrnous function completes after timing out', function() {
|
||||||
var timeout = 3,
|
const timeout = 3;
|
||||||
queueableFn = {
|
let queueableFnDone;
|
||||||
fn: function(done) {
|
const queueableFn = {
|
||||||
queueableFnDone = done;
|
fn: function(done) {
|
||||||
},
|
queueableFnDone = done;
|
||||||
type: 'queueable',
|
|
||||||
timeout: timeout
|
|
||||||
},
|
},
|
||||||
onComplete = jasmine.createSpy('onComplete'),
|
type: 'queueable',
|
||||||
onMultipleDone = jasmine.createSpy('onMultipleDone'),
|
timeout: timeout
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
};
|
||||||
queueableFns: [queueableFn],
|
const onComplete = jasmine.createSpy('onComplete');
|
||||||
onComplete: onComplete,
|
const onMultipleDone = jasmine.createSpy('onMultipleDone');
|
||||||
onMultipleDone: onMultipleDone
|
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
}),
|
queueableFns: [queueableFn],
|
||||||
queueableFnDone;
|
onComplete: onComplete,
|
||||||
|
onMultipleDone: onMultipleDone
|
||||||
|
});
|
||||||
|
|
||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
jasmine.clock().tick(timeout);
|
jasmine.clock().tick(timeout);
|
||||||
@@ -234,7 +287,8 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('by default does not set a timeout for asynchronous functions', function() {
|
it('by default does not set a timeout for asynchronous functions', function() {
|
||||||
var beforeFn = { fn: function(done) {} },
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const beforeFn = { fn: function(done) {} },
|
||||||
queueableFn = { fn: jasmine.createSpy('fn') },
|
queueableFn = { fn: jasmine.createSpy('fn') },
|
||||||
onComplete = jasmine.createSpy('onComplete'),
|
onComplete = jasmine.createSpy('onComplete'),
|
||||||
onException = jasmine.createSpy('onException'),
|
onException = jasmine.createSpy('onException'),
|
||||||
@@ -255,7 +309,8 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('clears the timeout when an async function throws an exception, to prevent additional exception reporting', function() {
|
it('clears the timeout when an async function throws an exception, to prevent additional exception reporting', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
throw new Error('error!');
|
throw new Error('error!');
|
||||||
}
|
}
|
||||||
@@ -278,7 +333,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('clears the timeout when the done callback is called', function() {
|
it('clears the timeout when the done callback is called', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -301,7 +356,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('only moves to the next spec the first time you call done', function() {
|
it('only moves to the next spec the first time you call done', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
done();
|
done();
|
||||||
done();
|
done();
|
||||||
@@ -321,44 +376,40 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not move to the next spec if done is called after an exception has ended the spec', function() {
|
it('does not move to the next spec if done is called after an exception has ended the spec', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
setTimeout(done, 1);
|
setTimeout(done, 1);
|
||||||
throw new Error('error!');
|
throw new Error('error!');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') },
|
nextQueueableFn = { fn: jasmine.createSpy('nextFn') },
|
||||||
deprecated = jasmine.createSpy('deprecated'),
|
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
deprecated: deprecated,
|
|
||||||
queueableFns: [queueableFn, nextQueueableFn]
|
queueableFns: [queueableFn, nextQueueableFn]
|
||||||
});
|
});
|
||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
jasmine.clock().tick(1);
|
jasmine.clock().tick(1);
|
||||||
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
|
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
|
||||||
// Don't issue a deprecation. The error already tells the user that
|
|
||||||
// something went wrong.
|
|
||||||
expect(deprecated).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a null when you call done', function() {
|
it('should return a null when you call done', function() {
|
||||||
// Some promises want handlers to return anything but undefined to help catch "forgotten returns".
|
// Some promises want handlers to return anything but undefined to help catch "forgotten returns".
|
||||||
var doneReturn,
|
let doneReturn;
|
||||||
queueableFn = {
|
const queueableFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
doneReturn = done();
|
doneReturn = done();
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
queueableFns: [queueableFn]
|
queueableFns: [queueableFn]
|
||||||
});
|
});
|
||||||
|
|
||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
expect(doneReturn).toBe(null);
|
expect(doneReturn).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('continues running functions when an exception is thrown in async code without timing out', function() {
|
it('continues running functions when an exception is thrown in async code without timing out', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
throwAsync();
|
throwAsync();
|
||||||
},
|
},
|
||||||
@@ -409,7 +460,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles exceptions thrown while waiting for the stack to clear', function() {
|
it('handles exceptions thrown while waiting for the stack to clear', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -460,7 +511,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs the function asynchronously, advancing once the promise is settled', function() {
|
it('runs the function asynchronously, advancing once the promise is settled', function() {
|
||||||
var onComplete = jasmine.createSpy('onComplete'),
|
const onComplete = jasmine.createSpy('onComplete'),
|
||||||
fnCallback = jasmine.createSpy('fnCallback'),
|
fnCallback = jasmine.createSpy('fnCallback'),
|
||||||
p1 = new StubPromise(),
|
p1 = new StubPromise(),
|
||||||
p2 = new StubPromise(),
|
p2 = new StubPromise(),
|
||||||
@@ -501,7 +552,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles a rejected promise like an unhandled exception', function() {
|
it('handles a rejected promise like an unhandled exception', function() {
|
||||||
var promise = new StubPromise(),
|
const promise = new StubPromise(),
|
||||||
queueableFn1 = {
|
queueableFn1 = {
|
||||||
fn: function() {
|
fn: function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@@ -529,7 +580,8 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('issues an error if the function also takes a parameter', function() {
|
it('issues an error if the function also takes a parameter', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
return new StubPromise();
|
return new StubPromise();
|
||||||
}
|
}
|
||||||
@@ -543,17 +595,20 @@ describe('QueueRunner', function() {
|
|||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
|
|
||||||
expect(onException).toHaveBeenCalledWith(
|
expect(onException).toHaveBeenCalledWith(
|
||||||
'An asynchronous ' +
|
new Error(
|
||||||
'before/it/after function took a done callback but also returned a ' +
|
'An asynchronous ' +
|
||||||
'promise. ' +
|
'before/it/after function took a done callback but also returned a ' +
|
||||||
'Either remove the done callback (recommended) or change the function ' +
|
'promise. ' +
|
||||||
'to not return a promise.'
|
'Either remove the done callback (recommended) or change the function ' +
|
||||||
|
'to not return a promise.'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('issues a more specific error if the function is `async`', function() {
|
it('issues a more specific error if the function is `async`', function() {
|
||||||
eval('var fn = async function(done){};');
|
// eslint-disable-next-line no-unused-vars
|
||||||
var onException = jasmine.createSpy('onException'),
|
async function fn(done) {}
|
||||||
|
const onException = jasmine.createSpy('onException'),
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
queueableFns: [{ fn: fn }],
|
queueableFns: [{ fn: fn }],
|
||||||
onException: onException
|
onException: onException
|
||||||
@@ -562,42 +617,31 @@ describe('QueueRunner', function() {
|
|||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
|
|
||||||
expect(onException).toHaveBeenCalledWith(
|
expect(onException).toHaveBeenCalledWith(
|
||||||
'An asynchronous ' +
|
new Error(
|
||||||
'before/it/after function was defined with the async keyword but ' +
|
'An asynchronous ' +
|
||||||
'also took a done callback. Either remove the done callback ' +
|
'before/it/after function was defined with the async keyword but ' +
|
||||||
'(recommended) or remove the async keyword.'
|
'also took a done callback. Either remove the done callback ' +
|
||||||
|
'(recommended) or remove the async keyword.'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the error instance to exception handlers in HTML browsers', function() {
|
it('passes final errors to exception handlers', function() {
|
||||||
var error = new Error('fake error'),
|
const error = new Error('fake error'),
|
||||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
onException: onExceptionCallback
|
onException: onExceptionCallback
|
||||||
});
|
});
|
||||||
|
|
||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
queueRunner.handleFinalError(error.message, 'fake.js', 1, 1, error);
|
queueRunner.handleFinalError(error);
|
||||||
|
|
||||||
expect(onExceptionCallback).toHaveBeenCalledWith(error);
|
expect(onExceptionCallback).toHaveBeenCalledWith(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the first argument to exception handlers for compatibility', function() {
|
|
||||||
var error = new Error('fake error'),
|
|
||||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
|
||||||
onException: onExceptionCallback
|
|
||||||
});
|
|
||||||
|
|
||||||
queueRunner.execute();
|
|
||||||
queueRunner.handleFinalError(error.message);
|
|
||||||
|
|
||||||
expect(onExceptionCallback).toHaveBeenCalledWith(error.message);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls exception handlers when an exception is thrown in a fn', function() {
|
it('calls exception handlers when an exception is thrown in a fn', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
type: 'queueable',
|
type: 'queueable',
|
||||||
fn: function() {
|
fn: function() {
|
||||||
throw new Error('fake error');
|
throw new Error('fake error');
|
||||||
@@ -615,7 +659,8 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('continues running the functions even after an exception is thrown in an async spec', function() {
|
it('continues running the functions even after an exception is thrown in an async spec', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
throw new Error('error');
|
throw new Error('error');
|
||||||
}
|
}
|
||||||
@@ -692,7 +737,7 @@ describe('QueueRunner', function() {
|
|||||||
|
|
||||||
describe('When configured to complete on first error', function() {
|
describe('When configured to complete on first error', function() {
|
||||||
it('skips to cleanup functions on the first exception', function() {
|
it('skips to cleanup functions on the first exception', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
fn: function() {
|
fn: function() {
|
||||||
throw new Error('error');
|
throw new Error('error');
|
||||||
}
|
}
|
||||||
@@ -718,7 +763,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not skip when a cleanup function throws', function() {
|
it('does not skip when a cleanup function throws', function() {
|
||||||
var queueableFn = { fn: function() {} },
|
const queueableFn = { fn: function() {} },
|
||||||
cleanupFn1 = {
|
cleanupFn1 = {
|
||||||
fn: function() {
|
fn: function() {
|
||||||
throw new Error('error');
|
throw new Error('error');
|
||||||
@@ -748,27 +793,30 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('skips to cleanup functions once the fn completes after an unhandled exception', function() {
|
it('skips to cleanup functions once the fn completes after an unhandled exception', function() {
|
||||||
var errorListeners = [],
|
const errorListeners = [];
|
||||||
queueableFn = {
|
let queueableFnDone;
|
||||||
fn: function(done) {
|
const queueableFn = {
|
||||||
queueableFnDone = done;
|
fn: function(done) {
|
||||||
|
queueableFnDone = done;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const nextQueueableFn = { fn: jasmine.createSpy('nextFunction') };
|
||||||
|
const cleanupFn = {
|
||||||
|
fn: jasmine.createSpy('cleanup'),
|
||||||
|
type: 'specCleanup'
|
||||||
|
};
|
||||||
|
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
|
globalErrors: {
|
||||||
|
pushListener: function(f) {
|
||||||
|
errorListeners.push(f);
|
||||||
|
},
|
||||||
|
popListener: function() {
|
||||||
|
errorListeners.pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
|
||||||
cleanupFn = { fn: jasmine.createSpy('cleanup'), type: 'specCleanup' },
|
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
});
|
||||||
globalErrors: {
|
|
||||||
pushListener: function(f) {
|
|
||||||
errorListeners.push(f);
|
|
||||||
},
|
|
||||||
popListener: function() {
|
|
||||||
errorListeners.pop();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
|
|
||||||
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
|
|
||||||
}),
|
|
||||||
queueableFnDone;
|
|
||||||
|
|
||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
errorListeners[errorListeners.length - 1](new Error('error'));
|
errorListeners[errorListeners.length - 1](new Error('error'));
|
||||||
@@ -779,7 +827,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('skips to cleanup functions when next.fail is called', function() {
|
it('skips to cleanup functions when next.fail is called', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
done.fail('nope');
|
done.fail('nope');
|
||||||
}
|
}
|
||||||
@@ -798,7 +846,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('skips to cleanup functions when next is called with an Error', function() {
|
it('skips to cleanup functions when next is called with an Error', function() {
|
||||||
var queueableFn = {
|
const queueableFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
done(new Error('nope'));
|
done(new Error('nope'));
|
||||||
}
|
}
|
||||||
@@ -822,7 +870,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls a provided complete callback when done', function() {
|
it('calls a provided complete callback when done', function() {
|
||||||
var queueableFn = { fn: jasmine.createSpy('fn') },
|
const queueableFn = { fn: jasmine.createSpy('fn') },
|
||||||
completeCallback = jasmine.createSpy('completeCallback'),
|
completeCallback = jasmine.createSpy('completeCallback'),
|
||||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
queueableFns: [queueableFn],
|
queueableFns: [queueableFn],
|
||||||
@@ -844,7 +892,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls a provided stack clearing function when done', function() {
|
it('calls a provided stack clearing function when done', function() {
|
||||||
var asyncFn = {
|
const asyncFn = {
|
||||||
fn: function(done) {
|
fn: function(done) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -873,16 +921,16 @@ describe('QueueRunner', function() {
|
|||||||
|
|
||||||
describe('when user context has not been defined', function() {
|
describe('when user context has not been defined', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
var fn;
|
const fn = jasmine.createSpy('fn1');
|
||||||
|
|
||||||
this.fn = fn = jasmine.createSpy('fn1');
|
this.fn = fn;
|
||||||
this.queueRunner = new jasmineUnderTest.QueueRunner({
|
this.queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
queueableFns: [{ fn: fn }]
|
queueableFns: [{ fn: fn }]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs the functions on the scope of a UserContext', function() {
|
it('runs the functions on the scope of a UserContext', function() {
|
||||||
var context;
|
let context;
|
||||||
this.fn.and.callFake(function() {
|
this.fn.and.callFake(function() {
|
||||||
context = this;
|
context = this;
|
||||||
});
|
});
|
||||||
@@ -895,9 +943,10 @@ describe('QueueRunner', function() {
|
|||||||
|
|
||||||
describe('when user context has been defined', function() {
|
describe('when user context has been defined', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
var fn, context;
|
const fn = jasmine.createSpy('fn1');
|
||||||
|
let context;
|
||||||
|
|
||||||
this.fn = fn = jasmine.createSpy('fn1');
|
this.fn = fn;
|
||||||
this.context = context = new jasmineUnderTest.UserContext();
|
this.context = context = new jasmineUnderTest.UserContext();
|
||||||
this.queueRunner = new jasmineUnderTest.QueueRunner({
|
this.queueRunner = new jasmineUnderTest.QueueRunner({
|
||||||
queueableFns: [{ fn: fn }],
|
queueableFns: [{ fn: fn }],
|
||||||
@@ -906,7 +955,7 @@ describe('QueueRunner', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs the functions on the scope of a UserContext', function() {
|
it('runs the functions on the scope of a UserContext', function() {
|
||||||
var context;
|
let context;
|
||||||
this.fn.and.callFake(function() {
|
this.fn.and.callFake(function() {
|
||||||
context = this;
|
context = this;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('ReportDispatcher', function() {
|
describe('ReportDispatcher', function() {
|
||||||
it('builds an interface of requested methods', function() {
|
it('builds an interface of requested methods', function() {
|
||||||
var dispatcher = new jasmineUnderTest.ReportDispatcher([
|
const dispatcher = new jasmineUnderTest.ReportDispatcher([
|
||||||
'foo',
|
'foo',
|
||||||
'bar',
|
'bar',
|
||||||
'baz'
|
'baz'
|
||||||
@@ -12,19 +12,18 @@ describe('ReportDispatcher', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('dispatches requested methods to added reporters', function() {
|
it('dispatches requested methods to added reporters', function() {
|
||||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
const queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||||
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
||||||
['foo', 'bar'],
|
['foo', 'bar'],
|
||||||
queueRunnerFactory
|
queueRunnerFactory
|
||||||
),
|
),
|
||||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||||
anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
|
||||||
completeCallback = jasmine.createSpy('complete');
|
|
||||||
|
|
||||||
dispatcher.addReporter(reporter);
|
dispatcher.addReporter(reporter);
|
||||||
dispatcher.addReporter(anotherReporter);
|
dispatcher.addReporter(anotherReporter);
|
||||||
|
|
||||||
dispatcher.foo(123, 456, completeCallback);
|
dispatcher.foo(123, 456);
|
||||||
|
|
||||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -36,7 +35,7 @@ describe('ReportDispatcher', function() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
let fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[0].fn();
|
fns[0].fn();
|
||||||
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
||||||
expect(reporter.foo.calls.mostRecent().object).toBe(reporter);
|
expect(reporter.foo.calls.mostRecent().object).toBe(reporter);
|
||||||
@@ -47,7 +46,7 @@ describe('ReportDispatcher', function() {
|
|||||||
|
|
||||||
queueRunnerFactory.calls.reset();
|
queueRunnerFactory.calls.reset();
|
||||||
|
|
||||||
dispatcher.bar('a', 'b', completeCallback);
|
dispatcher.bar('a', 'b');
|
||||||
|
|
||||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -68,7 +67,7 @@ describe('ReportDispatcher', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not dispatch to a reporter if the reporter doesn't accept the method", function() {
|
it("does not dispatch to a reporter if the reporter doesn't accept the method", function() {
|
||||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
const queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||||
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
||||||
['foo'],
|
['foo'],
|
||||||
queueRunnerFactory
|
queueRunnerFactory
|
||||||
@@ -86,16 +85,15 @@ describe('ReportDispatcher', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("allows providing a fallback reporter in case there's no other reporter", function() {
|
it("allows providing a fallback reporter in case there's no other reporter", function() {
|
||||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
const queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||||
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
||||||
['foo', 'bar'],
|
['foo', 'bar'],
|
||||||
queueRunnerFactory
|
queueRunnerFactory
|
||||||
),
|
),
|
||||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
|
||||||
completeCallback = jasmine.createSpy('complete');
|
|
||||||
|
|
||||||
dispatcher.provideFallbackReporter(reporter);
|
dispatcher.provideFallbackReporter(reporter);
|
||||||
dispatcher.foo(123, 456, completeCallback);
|
dispatcher.foo(123, 456);
|
||||||
|
|
||||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -104,24 +102,23 @@ describe('ReportDispatcher', function() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
const fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[0].fn();
|
fns[0].fn();
|
||||||
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not call fallback reporting methods when another reporter is provided', function() {
|
it('does not call fallback reporting methods when another reporter is provided', function() {
|
||||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
const queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||||
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
||||||
['foo', 'bar'],
|
['foo', 'bar'],
|
||||||
queueRunnerFactory
|
queueRunnerFactory
|
||||||
),
|
),
|
||||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||||
fallbackReporter = jasmine.createSpyObj('otherReporter', ['foo', 'bar']),
|
fallbackReporter = jasmine.createSpyObj('otherReporter', ['foo', 'bar']);
|
||||||
completeCallback = jasmine.createSpy('complete');
|
|
||||||
|
|
||||||
dispatcher.provideFallbackReporter(fallbackReporter);
|
dispatcher.provideFallbackReporter(fallbackReporter);
|
||||||
dispatcher.addReporter(reporter);
|
dispatcher.addReporter(reporter);
|
||||||
dispatcher.foo(123, 456, completeCallback);
|
dispatcher.foo(123, 456);
|
||||||
|
|
||||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -130,24 +127,23 @@ describe('ReportDispatcher', function() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
const fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[0].fn();
|
fns[0].fn();
|
||||||
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
||||||
expect(fallbackReporter.foo).not.toHaveBeenCalledWith(123, 456);
|
expect(fallbackReporter.foo).not.toHaveBeenCalledWith(123, 456);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows registered reporters to be cleared', function() {
|
it('allows registered reporters to be cleared', function() {
|
||||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
const queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||||
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
||||||
['foo', 'bar'],
|
['foo', 'bar'],
|
||||||
queueRunnerFactory
|
queueRunnerFactory
|
||||||
),
|
),
|
||||||
reporter1 = jasmine.createSpyObj('reporter1', ['foo', 'bar']),
|
reporter1 = jasmine.createSpyObj('reporter1', ['foo', 'bar']),
|
||||||
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']),
|
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']);
|
||||||
completeCallback = jasmine.createSpy('complete');
|
|
||||||
|
|
||||||
dispatcher.addReporter(reporter1);
|
dispatcher.addReporter(reporter1);
|
||||||
dispatcher.foo(123, completeCallback);
|
dispatcher.foo(123);
|
||||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||||
@@ -155,13 +151,13 @@ describe('ReportDispatcher', function() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
let fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[0].fn();
|
fns[0].fn();
|
||||||
expect(reporter1.foo).toHaveBeenCalledWith(123);
|
expect(reporter1.foo).toHaveBeenCalledWith(123);
|
||||||
|
|
||||||
dispatcher.clearReporters();
|
dispatcher.clearReporters();
|
||||||
dispatcher.addReporter(reporter2);
|
dispatcher.addReporter(reporter2);
|
||||||
dispatcher.bar(456, completeCallback);
|
dispatcher.bar(456);
|
||||||
|
|
||||||
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
expect(queueRunnerFactory).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
|
|||||||
557
spec/core/RunableResourcesSpec.js
Normal file
557
spec/core/RunableResourcesSpec.js
Normal file
@@ -0,0 +1,557 @@
|
|||||||
|
describe('RunableResources', function() {
|
||||||
|
describe('#spies', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'spies',
|
||||||
|
'Spies must be created in a before function or a spec',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customSpyStrategies', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customSpyStrategies',
|
||||||
|
'Custom spy strategies must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customEqualityTesters', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'customEqualityTesters',
|
||||||
|
'Custom Equalities must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customObjectFormatters', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'customObjectFormatters',
|
||||||
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customMatchers', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customMatchers',
|
||||||
|
'Matchers must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addCustomMatchers', function() {
|
||||||
|
it("adds all properties to the current runable's matchers", function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
function toBeFoo() {}
|
||||||
|
function toBeBar() {}
|
||||||
|
function toBeBaz() {}
|
||||||
|
|
||||||
|
runableResources.addCustomMatchers({ toBeFoo });
|
||||||
|
expect(runableResources.customMatchers()).toEqual({ toBeFoo });
|
||||||
|
|
||||||
|
runableResources.addCustomMatchers({ toBeBar, toBeBaz });
|
||||||
|
expect(runableResources.customMatchers()).toEqual({
|
||||||
|
toBeFoo,
|
||||||
|
toBeBar,
|
||||||
|
toBeBaz
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customAsyncMatchers', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customAsyncMatchers',
|
||||||
|
'Async Matchers must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addCustomAsyncMatchers', function() {
|
||||||
|
it("adds all properties to the current runable's matchers", function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
function toBeFoo() {}
|
||||||
|
function toBeBar() {}
|
||||||
|
function toBeBaz() {}
|
||||||
|
|
||||||
|
runableResources.addCustomAsyncMatchers({ toBeFoo });
|
||||||
|
expect(runableResources.customAsyncMatchers()).toEqual({ toBeFoo });
|
||||||
|
|
||||||
|
runableResources.addCustomAsyncMatchers({ toBeBar, toBeBaz });
|
||||||
|
expect(runableResources.customAsyncMatchers()).toEqual({
|
||||||
|
toBeFoo,
|
||||||
|
toBeBar,
|
||||||
|
toBeBaz
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#defaultSpyStrategy', function() {
|
||||||
|
it('returns undefined for a newly initialized resource', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the value previously set by #setDefaultSpyStrategy', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
const fn = () => {};
|
||||||
|
runableResources.setDefaultSpyStrategy(fn);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBe(fn);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources.setDefaultSpyStrategy(() => {});
|
||||||
|
currentRunableId = 2;
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not require a current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("inherits the parent runable's value", function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
const fn = () => {};
|
||||||
|
runableResources.setDefaultSpyStrategy(fn);
|
||||||
|
currentRunableId = 2;
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBe(fn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#setDefaultSpyStrategy', function() {
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(function() {
|
||||||
|
runableResources.setDefaultSpyStrategy();
|
||||||
|
}).toThrowError(
|
||||||
|
'Default spy strategy must be set in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#makePrettyPrinter', function() {
|
||||||
|
it('returns a pretty printer configured with the current customObjectFormatters', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.callThrough();
|
||||||
|
const pp = runableResources.makePrettyPrinter();
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
||||||
|
cof
|
||||||
|
]);
|
||||||
|
expect(pp).toBe(
|
||||||
|
jasmineUnderTest.makePrettyPrinter.calls.first().returnValue
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#makeMatchersUtil', function() {
|
||||||
|
describe('When there is a current runable', function() {
|
||||||
|
it('returns a MatchersUtil configured with the current resources', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
function ceq() {}
|
||||||
|
runableResources.customEqualityTesters().push(ceq);
|
||||||
|
const expectedPP = {};
|
||||||
|
const expectedMatchersUtil = {};
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(
|
||||||
|
expectedPP
|
||||||
|
);
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
||||||
|
expectedMatchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
const matchersUtil = runableResources.makeMatchersUtil();
|
||||||
|
|
||||||
|
expect(matchersUtil).toBe(expectedMatchersUtil);
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
||||||
|
cof
|
||||||
|
]);
|
||||||
|
// We need === equality on the pp passed to MatchersUtil
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledOnceWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customTesters: [ceq]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
||||||
|
expectedPP
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When there is no current runable', function() {
|
||||||
|
it('returns a MatchersUtil configured with defaults', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
const expectedMatchersUtil = {};
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
||||||
|
expectedMatchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
const matchersUtil = runableResources.makeMatchersUtil();
|
||||||
|
|
||||||
|
expect(matchersUtil).toBe(expectedMatchersUtil);
|
||||||
|
// We need === equality on the pp passed to MatchersUtil
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledTimes(1);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
||||||
|
jasmineUnderTest.basicPrettyPrinter_
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].customTesters
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.spyFactory', function() {
|
||||||
|
describe('When there is no current runable', function() {
|
||||||
|
it('is configured with default strategies and matchersUtil', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
spyOn(jasmineUnderTest, 'Spy');
|
||||||
|
const matchersUtil = {};
|
||||||
|
spyOn(runableResources, 'makeMatchersUtil').and.returnValue(
|
||||||
|
matchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
runableResources.spyFactory.createSpy('foo');
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
||||||
|
'foo',
|
||||||
|
is(matchersUtil),
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customStrategies: {},
|
||||||
|
defaultStrategyFn: undefined
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When there is a current runable', function() {
|
||||||
|
it("is configured with the current runable's strategies and matchersUtil", function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function customStrategy() {}
|
||||||
|
function defaultStrategy() {}
|
||||||
|
runableResources.customSpyStrategies().foo = customStrategy;
|
||||||
|
runableResources.setDefaultSpyStrategy(defaultStrategy);
|
||||||
|
spyOn(jasmineUnderTest, 'Spy');
|
||||||
|
const matchersUtil = {};
|
||||||
|
spyOn(runableResources, 'makeMatchersUtil').and.returnValue(
|
||||||
|
matchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
runableResources.spyFactory.createSpy('foo');
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
||||||
|
'foo',
|
||||||
|
is(matchersUtil),
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customStrategies: { foo: customStrategy },
|
||||||
|
defaultStrategyFn: defaultStrategy
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function is(expected) {
|
||||||
|
return {
|
||||||
|
asymmetricMatch: function(actual) {
|
||||||
|
return actual === expected;
|
||||||
|
},
|
||||||
|
jasmineToString: function(pp) {
|
||||||
|
return '<same instance as ' + pp(expected) + '>';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.spyRegistry', function() {
|
||||||
|
it("writes to the current runable's spies", function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function foo() {}
|
||||||
|
const spyObj = { foo };
|
||||||
|
runableResources.spyRegistry.spyOn(spyObj, 'foo');
|
||||||
|
|
||||||
|
expect(runableResources.spies()).toEqual([
|
||||||
|
jasmine.objectContaining({
|
||||||
|
restoreObjectToOriginalState: jasmine.any(Function)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
expect(jasmineUnderTest.isSpy(spyObj.foo)).toBeTrue();
|
||||||
|
|
||||||
|
runableResources.spyRegistry.clearSpies();
|
||||||
|
expect(spyObj.foo).toBe(foo);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#clearForRunable', function() {
|
||||||
|
it('removes resources for the specified runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
expect(function() {
|
||||||
|
runableResources.spies();
|
||||||
|
}).not.toThrow();
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(function() {
|
||||||
|
runableResources.spies();
|
||||||
|
}).toThrowError('Spies must be created in a before function or a spec');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears spies', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function foo() {}
|
||||||
|
const spyObj = { foo };
|
||||||
|
runableResources.spyRegistry.spyOn(spyObj, 'foo');
|
||||||
|
expect(spyObj.foo).not.toBe(foo);
|
||||||
|
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(spyObj.foo).toBe(foo);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the global error spy', function() {
|
||||||
|
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||||
|
'removeOverrideListener'
|
||||||
|
]);
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
getCurrentRunableId: () => 1,
|
||||||
|
globalErrors
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(globalErrors.removeOverrideListener).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not remove resources for other runables', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => 1
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
runableResources.clearForRunable(2);
|
||||||
|
expect(runableResources.customObjectFormatters()).toEqual([cof]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function behavesLikeAPerRunableMutableArray(
|
||||||
|
methodName,
|
||||||
|
errorMsg,
|
||||||
|
inherits = true
|
||||||
|
) {
|
||||||
|
it('is initially empty', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources[methodName]()).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is mutable', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function newItem() {}
|
||||||
|
runableResources[methodName]().push(newItem);
|
||||||
|
expect(runableResources[methodName]()).toEqual([newItem]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources[methodName]().push(() => {});
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
currentRunableId = 2;
|
||||||
|
expect(runableResources[methodName]()).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(function() {
|
||||||
|
runableResources[methodName]();
|
||||||
|
}).toThrowError(errorMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (inherits) {
|
||||||
|
it('inherits from the parent runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function parentItem() {}
|
||||||
|
runableResources[methodName]().push(parentItem);
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
currentRunableId = 2;
|
||||||
|
function childItem() {}
|
||||||
|
runableResources[methodName]().push(childItem);
|
||||||
|
expect(runableResources[methodName]()).toEqual([parentItem, childItem]);
|
||||||
|
|
||||||
|
currentRunableId = 1;
|
||||||
|
expect(runableResources[methodName]()).toEqual([parentItem]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function behavesLikeAPerRunableMutableObject(methodName, errorMsg) {
|
||||||
|
it('is initially empty', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources[methodName]()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is mutable', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function newItem() {}
|
||||||
|
runableResources[methodName]().foo = newItem;
|
||||||
|
expect(runableResources[methodName]()).toEqual({ foo: newItem });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources[methodName]().foo = function() {};
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
currentRunableId = 2;
|
||||||
|
expect(runableResources[methodName]()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => null
|
||||||
|
});
|
||||||
|
expect(function() {
|
||||||
|
runableResources[methodName]();
|
||||||
|
}).toThrowError(errorMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('inherits from the parent runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources({
|
||||||
|
globalErrors: stubGlobalErrors(),
|
||||||
|
getCurrentRunableId: () => currentRunableId
|
||||||
|
});
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function parentItem() {}
|
||||||
|
runableResources[methodName]().parentName = parentItem;
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
currentRunableId = 2;
|
||||||
|
function childItem() {}
|
||||||
|
runableResources[methodName]().childName = childItem;
|
||||||
|
expect(runableResources[methodName]()).toEqual({
|
||||||
|
parentName: parentItem,
|
||||||
|
childName: childItem
|
||||||
|
});
|
||||||
|
|
||||||
|
currentRunableId = 1;
|
||||||
|
expect(runableResources[methodName]()).toEqual({
|
||||||
|
parentName: parentItem
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stubGlobalErrors() {
|
||||||
|
return {
|
||||||
|
removeOverrideListener() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
describe('Spec', function() {
|
describe('Spec', function() {
|
||||||
it('#isPendingSpecException returns true for a pending spec exception', function() {
|
it('#isPendingSpecException returns true for a pending spec exception', function() {
|
||||||
var e = new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage);
|
const e = new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage);
|
||||||
|
|
||||||
expect(jasmineUnderTest.Spec.isPendingSpecException(e)).toBe(true);
|
expect(jasmineUnderTest.Spec.isPendingSpecException(e)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#isPendingSpecException returns true for a pending spec exception (even when FF bug is present)', function() {
|
it('#isPendingSpecException returns true for a pending spec exception (even when FF bug is present)', function() {
|
||||||
var fakeError = {
|
const fakeError = {
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return 'Error: ' + jasmineUnderTest.Spec.pendingSpecExceptionMessage;
|
return 'Error: ' + jasmineUnderTest.Spec.pendingSpecExceptionMessage;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('#isPendingSpecException returns false for not a pending spec exception', function() {
|
it('#isPendingSpecException returns false for not a pending spec exception', function() {
|
||||||
var e = new Error('foo');
|
const e = new Error('foo');
|
||||||
|
|
||||||
expect(jasmineUnderTest.Spec.isPendingSpecException(e)).toBe(false);
|
expect(jasmineUnderTest.Spec.isPendingSpecException(e)).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -34,31 +34,29 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('delegates execution to a QueueRunner', function() {
|
it('delegates execution to a QueueRunner', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
description: 'my test',
|
description: 'my test',
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} }
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the start callback on execution', function() {
|
it('should call the start callback on execution', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||||
startCallback = jasmine.createSpy('startCallback'),
|
startCallback = jasmine.createSpy('startCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
id: 123,
|
id: 123,
|
||||||
description: 'foo bar',
|
description: 'foo bar',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
onStart: startCallback,
|
onStart: startCallback
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||||
expect(startCallback).toHaveBeenCalled();
|
expect(startCallback).toHaveBeenCalled();
|
||||||
@@ -66,34 +64,33 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call the start callback on execution but before any befores are called', function() {
|
it('should call the start callback on execution but before any befores are called', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner');
|
||||||
beforesWereCalled = false,
|
let beforesWereCalled = false;
|
||||||
startCallback = jasmine
|
const startCallback = jasmine
|
||||||
.createSpy('start-callback')
|
.createSpy('start-callback')
|
||||||
.and.callFake(function() {
|
.and.callFake(function() {
|
||||||
expect(beforesWereCalled).toBe(false);
|
expect(beforesWereCalled).toBe(false);
|
||||||
}),
|
|
||||||
spec = new jasmineUnderTest.Spec({
|
|
||||||
queueableFn: { fn: function() {} },
|
|
||||||
beforeFns: function() {
|
|
||||||
return [
|
|
||||||
function() {
|
|
||||||
beforesWereCalled = true;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
},
|
|
||||||
onStart: startCallback,
|
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
queueableFn: { fn: function() {} },
|
||||||
|
beforeFns: function() {
|
||||||
|
return [
|
||||||
|
function() {
|
||||||
|
beforesWereCalled = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
},
|
||||||
|
onStart: startCallback
|
||||||
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||||
expect(startCallback).toHaveBeenCalled();
|
expect(startCallback).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('provides all before fns and after fns to be run', function() {
|
it('provides all before fns and after fns to be run', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||||
before = jasmine.createSpy('before'),
|
before = jasmine.createSpy('before'),
|
||||||
after = jasmine.createSpy('after'),
|
after = jasmine.createSpy('after'),
|
||||||
queueableFn = {
|
queueableFn = {
|
||||||
@@ -106,13 +103,12 @@ describe('Spec', function() {
|
|||||||
queueableFn: queueableFn,
|
queueableFn: queueableFn,
|
||||||
beforeAndAfterFns: function() {
|
beforeAndAfterFns: function() {
|
||||||
return { befores: [before], afters: [after] };
|
return { befores: [before], afters: [after] };
|
||||||
},
|
}
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
var options = fakeQueueRunner.calls.mostRecent().args[0];
|
const options = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
expect(options.queueableFns).toEqual([
|
expect(options.queueableFns).toEqual([
|
||||||
{ fn: jasmine.any(Function) },
|
{ fn: jasmine.any(Function) },
|
||||||
before,
|
before,
|
||||||
@@ -126,16 +122,15 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("tells the queue runner that it's a leaf node", function() {
|
it("tells the queue runner that it's a leaf node", function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
beforeAndAfterFns: function() {
|
beforeAndAfterFns: function() {
|
||||||
return { befores: [], afters: [] };
|
return { befores: [], afters: [] };
|
||||||
},
|
}
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -145,32 +140,29 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('is marked pending if created without a function body', function() {
|
it('is marked pending if created without a function body', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const startCallback = jasmine.createSpy('startCallback'),
|
||||||
startCallback = jasmine.createSpy('startCallback'),
|
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
onStart: startCallback,
|
onStart: startCallback,
|
||||||
queueableFn: { fn: null },
|
queueableFn: { fn: null },
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(spec.status()).toBe('pending');
|
expect(spec.status()).toBe('pending');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be excluded at execution time by a parent', function() {
|
it('can be excluded at execution time by a parent', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||||
startCallback = jasmine.createSpy('startCallback'),
|
startCallback = jasmine.createSpy('startCallback'),
|
||||||
specBody = jasmine.createSpy('specBody'),
|
specBody = jasmine.createSpy('specBody'),
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
onStart: startCallback,
|
onStart: startCallback,
|
||||||
queueableFn: { fn: specBody },
|
queueableFn: { fn: specBody },
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute('cally-back', true);
|
spec.execute(fakeQueueRunner, 'cally-back', true);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
@@ -186,7 +178,7 @@ describe('Spec', function() {
|
|||||||
);
|
);
|
||||||
expect(specBody).not.toHaveBeenCalled();
|
expect(specBody).not.toHaveBeenCalled();
|
||||||
|
|
||||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
args.queueableFns[0].fn();
|
args.queueableFns[0].fn();
|
||||||
expect(startCallback).toHaveBeenCalled();
|
expect(startCallback).toHaveBeenCalled();
|
||||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||||
@@ -196,17 +188,18 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can be marked pending, but still calls callbacks when executed', function() {
|
it('can be marked pending, but still calls callbacks when executed', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||||
startCallback = jasmine.createSpy('startCallback'),
|
startCallback = jasmine.createSpy('startCallback'),
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
onStart: startCallback,
|
onStart: startCallback,
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback,
|
||||||
description: 'with a spec',
|
description: 'with a spec',
|
||||||
|
parentSuiteId: 'suite1',
|
||||||
|
filename: 'someSpecFile.js',
|
||||||
getSpecName: function() {
|
getSpecName: function() {
|
||||||
return 'a suite with a spec';
|
return 'a suite with a spec';
|
||||||
},
|
},
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
queueableFn: { fn: null }
|
queueableFn: { fn: null }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -214,11 +207,11 @@ describe('Spec', function() {
|
|||||||
|
|
||||||
expect(spec.status()).toBe('pending');
|
expect(spec.status()).toBe('pending');
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||||
|
|
||||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
args.queueableFns[0].fn();
|
args.queueableFns[0].fn();
|
||||||
expect(startCallback).toHaveBeenCalled();
|
expect(startCallback).toHaveBeenCalled();
|
||||||
args.queueableFns[1].fn('things');
|
args.queueableFns[1].fn('things');
|
||||||
@@ -228,6 +221,8 @@ describe('Spec', function() {
|
|||||||
status: 'pending',
|
status: 'pending',
|
||||||
description: 'with a spec',
|
description: 'with a spec',
|
||||||
fullName: 'a suite with a spec',
|
fullName: 'a suite with a spec',
|
||||||
|
parentSuiteId: 'suite1',
|
||||||
|
filename: 'someSpecFile.js',
|
||||||
failedExpectations: [],
|
failedExpectations: [],
|
||||||
passedExpectations: [],
|
passedExpectations: [],
|
||||||
deprecationWarnings: [],
|
deprecationWarnings: [],
|
||||||
@@ -241,38 +236,35 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call the done callback on execution complete', function() {
|
it('should call the done callback on execution complete', function() {
|
||||||
var done = jasmine.createSpy('done callback'),
|
const done = jasmine.createSpy('done callback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
catchExceptions: function() {
|
catchExceptions: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
resultCallback: function() {},
|
resultCallback: function() {}
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
attrs.onComplete();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(done);
|
spec.execute(attrs => attrs.onComplete(), done);
|
||||||
|
|
||||||
expect(done).toHaveBeenCalled();
|
expect(done).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the done callback with an error if the spec is failed', function() {
|
it('should call the done callback with an error if the spec is failed', function() {
|
||||||
var done = jasmine.createSpy('done callback'),
|
const done = jasmine.createSpy('done callback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
catchExceptions: function() {
|
catchExceptions: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
resultCallback: function() {},
|
resultCallback: function() {}
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
spec.result.status = 'failed';
|
|
||||||
attrs.onComplete();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(done);
|
function queueRunnerFactory(attrs) {
|
||||||
|
spec.result.status = 'failed';
|
||||||
|
attrs.onComplete();
|
||||||
|
}
|
||||||
|
spec.execute(queueRunnerFactory, done);
|
||||||
|
|
||||||
expect(done).toHaveBeenCalledWith(
|
expect(done).toHaveBeenCalledWith(
|
||||||
jasmine.any(jasmineUnderTest.StopExecutionError)
|
jasmine.any(jasmineUnderTest.StopExecutionError)
|
||||||
@@ -280,150 +272,224 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should report the duration of the test', function() {
|
it('should report the duration of the test', function() {
|
||||||
var timer = jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }),
|
const timer = jasmine.createSpyObj('timer', {
|
||||||
spec = new jasmineUnderTest.Spec({
|
start: null,
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
elapsed: 77000
|
||||||
catchExceptions: function() {
|
});
|
||||||
return false;
|
let duration = undefined;
|
||||||
},
|
const spec = new jasmineUnderTest.Spec({
|
||||||
resultCallback: function(result) {
|
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||||
duration = result.duration;
|
catchExceptions: function() {
|
||||||
},
|
return false;
|
||||||
queueRunnerFactory: function(config) {
|
},
|
||||||
config.queueableFns.forEach(function(qf) {
|
resultCallback: function(result) {
|
||||||
qf.fn();
|
duration = result.duration;
|
||||||
});
|
},
|
||||||
config.onComplete();
|
timer: timer
|
||||||
},
|
});
|
||||||
timer: timer
|
|
||||||
}),
|
|
||||||
duration = undefined;
|
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
config.queueableFns.forEach(function(qf) {
|
||||||
|
qf.fn();
|
||||||
|
});
|
||||||
|
config.onComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(duration).toBe(77000);
|
expect(duration).toBe(77000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report properties set during the test', function() {
|
it('should report properties set during the test', function() {
|
||||||
var done = jasmine.createSpy('done callback'),
|
const done = jasmine.createSpy('done callback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||||
catchExceptions: function() {
|
catchExceptions: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
resultCallback: function() {},
|
resultCallback: function() {}
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
attrs.onComplete();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
spec.setSpecProperty('a', 4);
|
spec.setSpecProperty('a', 4);
|
||||||
spec.execute(done);
|
spec.execute(attrs => attrs.onComplete(), done);
|
||||||
expect(spec.result.properties).toEqual({ a: 4 });
|
expect(spec.result.properties).toEqual({ a: 4 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#status returns passing by default', function() {
|
it('#status returns passing by default', function() {
|
||||||
var spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||||
});
|
});
|
||||||
expect(spec.status()).toBe('passed');
|
expect(spec.status()).toBe('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#status returns passed if all expectations in the spec have passed', function() {
|
it('#status returns passed if all expectations in the spec have passed', function() {
|
||||||
var spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||||
});
|
});
|
||||||
spec.addExpectationResult(true);
|
spec.addExpectationResult(true, {});
|
||||||
expect(spec.status()).toBe('passed');
|
expect(spec.status()).toBe('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#status returns failed if any expectations in the spec have failed', function() {
|
it('#status returns failed if any expectations in the spec have failed', function() {
|
||||||
var spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||||
});
|
});
|
||||||
spec.addExpectationResult(true);
|
spec.addExpectationResult(true, {});
|
||||||
spec.addExpectationResult(false);
|
spec.addExpectationResult(false, {});
|
||||||
expect(spec.status()).toBe('failed');
|
expect(spec.status()).toBe('failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps track of passed and failed expectations', function() {
|
it('keeps track of passed and failed expectations', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback
|
resultCallback: resultCallback
|
||||||
});
|
});
|
||||||
spec.addExpectationResult(true, 'expectation1');
|
spec.addExpectationResult(true, { message: 'expectation1' });
|
||||||
spec.addExpectationResult(false, 'expectation2');
|
spec.addExpectationResult(false, { message: 'expectation2' });
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[fns.length - 1].fn();
|
fns[fns.length - 1].fn();
|
||||||
|
|
||||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||||
'expectation1'
|
jasmine.objectContaining({ message: 'expectation1' })
|
||||||
]);
|
]);
|
||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||||
'expectation2'
|
jasmine.objectContaining({ message: 'expectation2' })
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an ExpectationFailed error upon receiving a failed expectation when 'throwOnExpectationFailure' is set", function() {
|
it("throws an ExpectationFailed error upon receiving a failed expectation when 'throwOnExpectationFailure' is set", function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback,
|
||||||
throwOnExpectationFailure: true
|
throwOnExpectationFailure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.addExpectationResult(true, 'passed');
|
spec.addExpectationResult(true, { message: 'passed' });
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spec.addExpectationResult(false, 'failed');
|
spec.addExpectationResult(false, { message: 'failed' });
|
||||||
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
fns[fns.length - 1].fn();
|
fns[fns.length - 1].fn();
|
||||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||||
'passed'
|
jasmine.objectContaining({ message: 'passed' })
|
||||||
]);
|
]);
|
||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||||
'failed'
|
jasmine.objectContaining({ message: 'failed' })
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('forwards late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
spec.reportedDone = true;
|
||||||
|
spec.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: nope/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(spec.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
spec.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('forwards late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
|
||||||
|
spec.reportedDone = true;
|
||||||
|
spec.handleException(new Error('oops'));
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: oops/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(spec.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
onLateError,
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
const error = new Error('oops');
|
||||||
|
|
||||||
|
spec.handleException(error);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
expect(spec.result.failedExpectations.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the reportedDone flag when reset', function() {
|
||||||
|
const spec = new jasmineUnderTest.Spec({
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
spec.reportedDone = true;
|
||||||
|
|
||||||
|
spec.reset();
|
||||||
|
|
||||||
|
expect(spec.reportedDone).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
it('does not throw an ExpectationFailed error when handling an error', function() {
|
it('does not throw an ExpectationFailed error when handling an error', function() {
|
||||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: function(attrs) {
|
|
||||||
attrs.onComplete();
|
|
||||||
},
|
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback,
|
||||||
throwOnExpectationFailure: true
|
throwOnExpectationFailure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.onException('failing exception');
|
spec.handleException('failing exception');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can return its full name', function() {
|
it('can return its full name', function() {
|
||||||
var specNameSpy = jasmine
|
const specNameSpy = jasmine
|
||||||
.createSpy('specNameSpy')
|
.createSpy('specNameSpy')
|
||||||
.and.returnValue('expected val');
|
.and.returnValue('expected val');
|
||||||
|
|
||||||
var spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
getSpecName: specNameSpy,
|
getSpecName: specNameSpy,
|
||||||
queueableFn: { fn: null }
|
queueableFn: { fn: null }
|
||||||
});
|
});
|
||||||
@@ -434,7 +500,7 @@ describe('Spec', function() {
|
|||||||
|
|
||||||
describe('when a spec is marked pending during execution', function() {
|
describe('when a spec is marked pending during execution', function() {
|
||||||
it('should mark the spec as pending', function() {
|
it('should mark the spec as pending', function() {
|
||||||
var fakeQueueRunner = function(opts) {
|
const fakeQueueRunner = function(opts) {
|
||||||
opts.onException(
|
opts.onException(
|
||||||
new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage)
|
new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage)
|
||||||
);
|
);
|
||||||
@@ -442,18 +508,17 @@ describe('Spec', function() {
|
|||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
description: 'my test',
|
description: 'my test',
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} }
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(spec.status()).toEqual('pending');
|
expect(spec.status()).toEqual('pending');
|
||||||
expect(spec.result.pendingReason).toEqual('');
|
expect(spec.result.pendingReason).toEqual('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set the pendingReason', function() {
|
it('should set the pendingReason', function() {
|
||||||
var fakeQueueRunner = function(opts) {
|
const fakeQueueRunner = function(opts) {
|
||||||
opts.onException(
|
opts.onException(
|
||||||
new Error(
|
new Error(
|
||||||
jasmineUnderTest.Spec.pendingSpecExceptionMessage +
|
jasmineUnderTest.Spec.pendingSpecExceptionMessage +
|
||||||
@@ -464,11 +529,10 @@ describe('Spec', function() {
|
|||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
description: 'my test',
|
description: 'my test',
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} }
|
||||||
queueRunnerFactory: fakeQueueRunner
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
expect(spec.status()).toEqual('pending');
|
expect(spec.status()).toEqual('pending');
|
||||||
expect(spec.result.pendingReason).toEqual('custom message');
|
expect(spec.result.pendingReason).toEqual('custom message');
|
||||||
@@ -476,66 +540,58 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should log a failure when handling an exception', function() {
|
it('should log a failure when handling an exception', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback
|
resultCallback: resultCallback
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.onException('foo');
|
spec.handleException('foo');
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||||
{
|
{
|
||||||
error: 'foo',
|
message: 'foo thrown',
|
||||||
matcherName: '',
|
matcherName: '',
|
||||||
passed: false,
|
passed: false,
|
||||||
expected: '',
|
expected: '',
|
||||||
actual: ''
|
actual: '',
|
||||||
|
stack: null
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not log an additional failure when handling an ExpectationFailed error', function() {
|
it('should not log an additional failure when handling an ExpectationFailed error', function() {
|
||||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
const fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||||
resultCallback = jasmine.createSpy('resultCallback'),
|
resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
queueRunnerFactory: fakeQueueRunner,
|
|
||||||
resultCallback: resultCallback
|
resultCallback: resultCallback
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
spec.handleException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||||
spec.execute();
|
spec.execute(fakeQueueRunner);
|
||||||
|
|
||||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]);
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('treats multiple done calls as late errors', function() {
|
it('treats multiple done calls as late errors', function() {
|
||||||
var queueRunnerFactory = jasmine.createSpy('queueRunnerFactory'),
|
const queueRunnerFactory = jasmine.createSpy('queueRunnerFactory'),
|
||||||
onLateError = jasmine.createSpy('onLateError'),
|
onLateError = jasmine.createSpy('onLateError'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
onLateError: onLateError,
|
onLateError: onLateError,
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
queueRunnerFactory: queueRunnerFactory,
|
|
||||||
getSpecName: function() {
|
getSpecName: function() {
|
||||||
return 'a spec';
|
return 'a spec';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(queueRunnerFactory);
|
||||||
|
|
||||||
expect(queueRunnerFactory).toHaveBeenCalled();
|
expect(queueRunnerFactory).toHaveBeenCalled();
|
||||||
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
||||||
@@ -550,18 +606,17 @@ describe('Spec', function() {
|
|||||||
|
|
||||||
describe('#trace', function() {
|
describe('#trace', function() {
|
||||||
it('adds the messages to the result', function() {
|
it('adds the messages to the result', function() {
|
||||||
var timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
const timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: {
|
queueableFn: {
|
||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
queueRunnerFactory: function() {},
|
|
||||||
timer: timer
|
timer: timer
|
||||||
}),
|
}),
|
||||||
t1 = 123,
|
t1 = 123,
|
||||||
t2 = 456;
|
t2 = 456;
|
||||||
|
|
||||||
spec.execute();
|
spec.execute(() => {});
|
||||||
expect(spec.result.debugLogs).toBeNull();
|
expect(spec.result.debugLogs).toBeNull();
|
||||||
timer.elapsed.and.returnValue(t1);
|
timer.elapsed.and.returnValue(t1);
|
||||||
spec.debugLog('msg 1');
|
spec.debugLog('msg 1');
|
||||||
@@ -578,22 +633,23 @@ describe('Spec', function() {
|
|||||||
|
|
||||||
describe('When the spec passes', function() {
|
describe('When the spec passes', function() {
|
||||||
it('omits the messages from the reported result', function() {
|
it('omits the messages from the reported result', function() {
|
||||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: {
|
queueableFn: {
|
||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: function(config) {
|
|
||||||
spec.debugLog('msg');
|
|
||||||
for (const fn of config.queueableFns) {
|
|
||||||
fn.fn();
|
|
||||||
}
|
|
||||||
config.onComplete(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
spec.debugLog('msg');
|
||||||
|
for (const fn of config.queueableFns) {
|
||||||
|
fn.fn();
|
||||||
|
}
|
||||||
|
config.onComplete(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(resultCallback).toHaveBeenCalledWith(
|
expect(resultCallback).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({ debugLogs: null }),
|
jasmine.objectContaining({ debugLogs: null }),
|
||||||
undefined
|
undefined
|
||||||
@@ -601,22 +657,23 @@ describe('Spec', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('removes the messages to save memory', function() {
|
it('removes the messages to save memory', function() {
|
||||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: {
|
queueableFn: {
|
||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback
|
||||||
queueRunnerFactory: function(config) {
|
|
||||||
spec.debugLog('msg');
|
|
||||||
for (const fn of config.queueableFns) {
|
|
||||||
fn.fn();
|
|
||||||
}
|
|
||||||
config.onComplete(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
spec.debugLog('msg');
|
||||||
|
for (const fn of config.queueableFns) {
|
||||||
|
fn.fn();
|
||||||
|
}
|
||||||
|
config.onComplete(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(resultCallback).toHaveBeenCalled();
|
expect(resultCallback).toHaveBeenCalled();
|
||||||
expect(spec.result.debugLogs).toBeNull();
|
expect(spec.result.debugLogs).toBeNull();
|
||||||
});
|
});
|
||||||
@@ -624,28 +681,29 @@ describe('Spec', function() {
|
|||||||
|
|
||||||
describe('When the spec fails', function() {
|
describe('When the spec fails', function() {
|
||||||
it('includes the messages in the reported result', function() {
|
it('includes the messages in the reported result', function() {
|
||||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||||
timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
queueableFn: {
|
queueableFn: {
|
||||||
fn: function() {}
|
fn: function() {}
|
||||||
},
|
},
|
||||||
resultCallback: resultCallback,
|
resultCallback: resultCallback,
|
||||||
queueRunnerFactory: function(config) {
|
|
||||||
spec.debugLog('msg');
|
|
||||||
spec.onException(new Error('nope'));
|
|
||||||
for (const fn of config.queueableFns) {
|
|
||||||
fn.fn();
|
|
||||||
}
|
|
||||||
config.onComplete(true);
|
|
||||||
},
|
|
||||||
timer: timer
|
timer: timer
|
||||||
}),
|
}),
|
||||||
timestamp = 12345;
|
timestamp = 12345;
|
||||||
|
|
||||||
timer.elapsed.and.returnValue(timestamp);
|
timer.elapsed.and.returnValue(timestamp);
|
||||||
|
|
||||||
spec.execute(function() {});
|
function queueRunnerFactory(config) {
|
||||||
|
spec.debugLog('msg');
|
||||||
|
spec.handleException(new Error('nope'));
|
||||||
|
for (const fn of config.queueableFns) {
|
||||||
|
fn.fn();
|
||||||
|
}
|
||||||
|
config.onComplete(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
spec.execute(queueRunnerFactory, function() {});
|
||||||
expect(resultCallback).toHaveBeenCalledWith(
|
expect(resultCallback).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
debugLogs: [{ message: 'msg', timestamp: timestamp }]
|
debugLogs: [{ message: 'msg', timestamp: timestamp }]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ describe('SpyRegistry', function() {
|
|||||||
|
|
||||||
describe('#spyOn', function() {
|
describe('#spyOn', function() {
|
||||||
it('checks for the existence of the object', function() {
|
it('checks for the existence of the object', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: createSpy
|
createSpy: createSpy
|
||||||
});
|
});
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -14,7 +14,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks that a method name was passed', function() {
|
it('checks that a method name was passed', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -23,14 +23,14 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks that the object is not `null`', function() {
|
it('checks that the object is not `null`', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spyRegistry.spyOn(null, 'pants');
|
spyRegistry.spyOn(null, 'pants');
|
||||||
}).toThrowError(/could not find an object/);
|
}).toThrowError(/could not find an object/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checks that the method name is not `null`', function() {
|
it('checks that the method name is not `null`', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -39,7 +39,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks for the existence of the method', function() {
|
it('checks for the existence of the method', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -48,7 +48,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks if it has already been spied upon', function() {
|
it('checks if it has already been spied upon', function() {
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -65,7 +65,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks if it can be spied upon', function() {
|
it('checks if it can be spied upon', function() {
|
||||||
var scope = {};
|
const scope = {};
|
||||||
|
|
||||||
function myFunc() {
|
function myFunc() {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -77,7 +77,7 @@ describe('SpyRegistry', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -95,7 +95,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('overrides the method on the object and returns the spy', function() {
|
it('overrides the method on the object and returns the spy', function() {
|
||||||
var originalFunctionWasCalled = false,
|
const originalFunctionWasCalled = false,
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: createSpy
|
createSpy: createSpy
|
||||||
}),
|
}),
|
||||||
@@ -105,7 +105,7 @@ describe('SpyRegistry', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
|
const spy = spyRegistry.spyOn(subject, 'spiedFunc');
|
||||||
|
|
||||||
expect(subject.spiedFunc).toEqual(spy);
|
expect(subject.spiedFunc).toEqual(spy);
|
||||||
subject.spiedFunc();
|
subject.spiedFunc();
|
||||||
@@ -115,14 +115,14 @@ describe('SpyRegistry', function() {
|
|||||||
|
|
||||||
describe('#spyOnProperty', function() {
|
describe('#spyOnProperty', function() {
|
||||||
it('checks for the existence of the object', function() {
|
it('checks for the existence of the object', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spyRegistry.spyOnProperty(void 0, 'pants');
|
spyRegistry.spyOnProperty(void 0, 'pants');
|
||||||
}).toThrowError(/could not find an object/);
|
}).toThrowError(/could not find an object/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checks that a property name was passed', function() {
|
it('checks that a property name was passed', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -131,7 +131,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks for the existence of the method', function() {
|
it('checks for the existence of the method', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -140,7 +140,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks for the existence of access type', function() {
|
it('checks for the existence of access type', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
Object.defineProperty(subject, 'pants', {
|
Object.defineProperty(subject, 'pants', {
|
||||||
@@ -156,7 +156,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks if it can be spied upon', function() {
|
it('checks if it can be spied upon', function() {
|
||||||
var subject = {};
|
const subject = {};
|
||||||
|
|
||||||
Object.defineProperty(subject, 'myProp', {
|
Object.defineProperty(subject, 'myProp', {
|
||||||
get: function() {}
|
get: function() {}
|
||||||
@@ -167,7 +167,7 @@ describe('SpyRegistry', function() {
|
|||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spyRegistry.spyOnProperty(subject, 'myProp');
|
spyRegistry.spyOnProperty(subject, 'myProp');
|
||||||
@@ -179,7 +179,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('overrides the property getter on the object and returns the spy', function() {
|
it('overrides the property getter on the object and returns the spy', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: createSpy
|
createSpy: createSpy
|
||||||
}),
|
}),
|
||||||
subject = {},
|
subject = {},
|
||||||
@@ -194,8 +194,8 @@ describe('SpyRegistry', function() {
|
|||||||
|
|
||||||
expect(subject.spiedProperty).toEqual(returnValue);
|
expect(subject.spiedProperty).toEqual(returnValue);
|
||||||
|
|
||||||
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty');
|
const spy = spyRegistry.spyOnProperty(subject, 'spiedProperty');
|
||||||
var getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
const getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
||||||
.get;
|
.get;
|
||||||
|
|
||||||
expect(getter).toEqual(spy);
|
expect(getter).toEqual(spy);
|
||||||
@@ -203,7 +203,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('overrides the property setter on the object and returns the spy', function() {
|
it('overrides the property setter on the object and returns the spy', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: createSpy
|
createSpy: createSpy
|
||||||
}),
|
}),
|
||||||
subject = {},
|
subject = {},
|
||||||
@@ -217,8 +217,8 @@ describe('SpyRegistry', function() {
|
|||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set');
|
const spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set');
|
||||||
var setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
const setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
||||||
.set;
|
.set;
|
||||||
|
|
||||||
expect(subject.spiedProperty).toEqual(returnValue);
|
expect(subject.spiedProperty).toEqual(returnValue);
|
||||||
@@ -227,7 +227,7 @@ describe('SpyRegistry', function() {
|
|||||||
|
|
||||||
describe('when the property is already spied upon', function() {
|
describe('when the property is already spied upon', function() {
|
||||||
it('throws an error if respy is not allowed', function() {
|
it('throws an error if respy is not allowed', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: createSpy
|
createSpy: createSpy
|
||||||
}),
|
}),
|
||||||
subject = {};
|
subject = {};
|
||||||
@@ -247,7 +247,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns the original spy if respy is allowed', function() {
|
it('returns the original spy if respy is allowed', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: createSpy
|
createSpy: createSpy
|
||||||
}),
|
}),
|
||||||
subject = {};
|
subject = {};
|
||||||
@@ -261,7 +261,7 @@ describe('SpyRegistry', function() {
|
|||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var originalSpy = spyRegistry.spyOnProperty(subject, 'spiedProp');
|
const originalSpy = spyRegistry.spyOnProperty(subject, 'spiedProp');
|
||||||
|
|
||||||
expect(spyRegistry.spyOnProperty(subject, 'spiedProp')).toBe(
|
expect(spyRegistry.spyOnProperty(subject, 'spiedProp')).toBe(
|
||||||
originalSpy
|
originalSpy
|
||||||
@@ -272,33 +272,33 @@ describe('SpyRegistry', function() {
|
|||||||
|
|
||||||
describe('#spyOnAllFunctions', function() {
|
describe('#spyOnAllFunctions', function() {
|
||||||
it('checks for the existence of the object', function() {
|
it('checks for the existence of the object', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spyRegistry.spyOnAllFunctions(void 0);
|
spyRegistry.spyOnAllFunctions(void 0);
|
||||||
}).toThrowError(/spyOnAllFunctions could not find an object to spy upon/);
|
}).toThrowError(/spyOnAllFunctions could not find an object to spy upon/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('overrides all writable and configurable functions of the object and its parents', function() {
|
it('overrides all writable and configurable functions of the object and its parents', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var createNoop = function() {
|
const createNoop = function() {
|
||||||
return function() {
|
return function() {
|
||||||
/**/
|
/**/
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
var noop1 = createNoop();
|
const noop1 = createNoop();
|
||||||
var noop2 = createNoop();
|
const noop2 = createNoop();
|
||||||
var noop3 = createNoop();
|
const noop3 = createNoop();
|
||||||
var noop4 = createNoop();
|
const noop4 = createNoop();
|
||||||
var noop5 = createNoop();
|
const noop5 = createNoop();
|
||||||
|
|
||||||
var parent = {
|
const parent = {
|
||||||
parentSpied1: noop1
|
parentSpied1: noop1
|
||||||
};
|
};
|
||||||
var subject = Object.create(parent);
|
const subject = Object.create(parent);
|
||||||
Object.defineProperty(subject, 'spied1', {
|
Object.defineProperty(subject, 'spied1', {
|
||||||
value: noop1,
|
value: noop1,
|
||||||
writable: true,
|
writable: true,
|
||||||
@@ -311,7 +311,7 @@ describe('SpyRegistry', function() {
|
|||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
});
|
});
|
||||||
var _spied3 = noop3;
|
let _spied3 = noop3;
|
||||||
Object.defineProperty(subject, 'spied3', {
|
Object.defineProperty(subject, 'spied3', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
set: function(val) {
|
set: function(val) {
|
||||||
@@ -337,7 +337,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
Object.defineProperty(subject, 'notSpied4', {
|
Object.defineProperty(subject, 'notSpied4', {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
set: function(val) {
|
set: function() {
|
||||||
/**/
|
/**/
|
||||||
},
|
},
|
||||||
get: function() {
|
get: function() {
|
||||||
@@ -353,7 +353,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
subject.notSpied6 = 6;
|
subject.notSpied6 = 6;
|
||||||
|
|
||||||
var spiedObject = spyRegistry.spyOnAllFunctions(subject);
|
const spiedObject = spyRegistry.spyOnAllFunctions(subject);
|
||||||
|
|
||||||
expect(subject.parentSpied1).toBe('I am a spy');
|
expect(subject.parentSpied1).toBe('I am a spy');
|
||||||
expect(subject.notSpied2).toBe(noop2);
|
expect(subject.notSpied2).toBe(noop2);
|
||||||
@@ -369,21 +369,21 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('overrides prototype methods on the object', function() {
|
it('overrides prototype methods on the object', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var noop1 = function() {};
|
const noop1 = function() {};
|
||||||
var noop2 = function() {};
|
const noop2 = function() {};
|
||||||
|
|
||||||
var MyClass = function() {
|
const MyClass = function() {
|
||||||
this.spied1 = noop1;
|
this.spied1 = noop1;
|
||||||
};
|
};
|
||||||
MyClass.prototype.spied2 = noop2;
|
MyClass.prototype.spied2 = noop2;
|
||||||
|
|
||||||
var subject = new MyClass();
|
const subject = new MyClass();
|
||||||
spyRegistry.spyOnAllFunctions(subject);
|
spyRegistry.spyOnAllFunctions(subject);
|
||||||
|
|
||||||
expect(subject.spied1).toBe('I am a spy');
|
expect(subject.spied1).toBe('I am a spy');
|
||||||
@@ -392,12 +392,12 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not override non-enumerable properties (like Object.prototype methods)', function() {
|
it('does not override non-enumerable properties (like Object.prototype methods)', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var subject = {
|
const subject = {
|
||||||
spied1: function() {}
|
spied1: function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -409,12 +409,12 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
describe('when includeNonEnumerable is true', function() {
|
describe('when includeNonEnumerable is true', function() {
|
||||||
it('does not override Object.prototype methods', function() {
|
it('does not override Object.prototype methods', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var subject = {
|
const subject = {
|
||||||
spied1: function() {}
|
spied1: function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -426,12 +426,12 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('overrides non-enumerable properties', function() {
|
it('overrides non-enumerable properties', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var subject = {
|
const subject = {
|
||||||
spied1: function() {},
|
spied1: function() {},
|
||||||
spied2: function() {}
|
spied2: function() {}
|
||||||
};
|
};
|
||||||
@@ -449,12 +449,12 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not spy on non-enumerable functions named constructor', function() {
|
it('should not spy on non-enumerable functions named constructor', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var subject = {
|
const subject = {
|
||||||
constructor: function() {}
|
constructor: function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -470,12 +470,12 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should spy on enumerable functions named constructor', function() {
|
it('should spy on enumerable functions named constructor', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var subject = {
|
const subject = {
|
||||||
constructor: function() {}
|
constructor: function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -485,13 +485,13 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw an exception if we try and access strict mode restricted properties', function() {
|
it('should not throw an exception if we try and access strict mode restricted properties', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var subject = function() {};
|
const subject = function() {};
|
||||||
var fn = function() {
|
const fn = function() {
|
||||||
spyRegistry.spyOnAllFunctions(subject, true);
|
spyRegistry.spyOnAllFunctions(subject, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -499,24 +499,24 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not spy on properties which are more permissable further up the prototype chain', function() {
|
it('should not spy on properties which are more permissable further up the prototype chain', function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
createSpy: function() {
|
createSpy: function() {
|
||||||
return 'I am a spy';
|
return 'I am a spy';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var subjectParent = Object.defineProperty({}, 'sharedProp', {
|
const subjectParent = Object.defineProperty({}, 'sharedProp', {
|
||||||
value: function() {},
|
value: function() {},
|
||||||
writable: true,
|
writable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var subject = Object.create(subjectParent);
|
const subject = Object.create(subjectParent);
|
||||||
|
|
||||||
Object.defineProperty(subject, 'sharedProp', {
|
Object.defineProperty(subject, 'sharedProp', {
|
||||||
value: function() {}
|
value: function() {}
|
||||||
});
|
});
|
||||||
|
|
||||||
var fn = function() {
|
const fn = function() {
|
||||||
spyRegistry.spyOnAllFunctions(subject, true);
|
spyRegistry.spyOnAllFunctions(subject, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -528,7 +528,7 @@ describe('SpyRegistry', function() {
|
|||||||
|
|
||||||
describe('#clearSpies', function() {
|
describe('#clearSpies', function() {
|
||||||
it('restores the original functions on the spied-upon objects', function() {
|
it('restores the original functions on the spied-upon objects', function() {
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -545,7 +545,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('restores the original functions, even when that spy has been replace and re-spied upon', function() {
|
it('restores the original functions, even when that spy has been replace and re-spied upon', function() {
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -569,7 +569,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not add a property that the spied-upon object didn't originally have", function() {
|
it("does not add a property that the spied-upon object didn't originally have", function() {
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -579,7 +579,7 @@ describe('SpyRegistry', function() {
|
|||||||
originalFunction = function() {},
|
originalFunction = function() {},
|
||||||
subjectParent = { spiedFunc: originalFunction };
|
subjectParent = { spiedFunc: originalFunction };
|
||||||
|
|
||||||
var subject = Object.create(subjectParent);
|
const subject = Object.create(subjectParent);
|
||||||
|
|
||||||
expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
|
expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
|
||||||
|
|
||||||
@@ -591,7 +591,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("restores the original function when it's inherited and cannot be deleted", function() {
|
it("restores the original function when it's inherited and cannot be deleted", function() {
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -601,7 +601,7 @@ describe('SpyRegistry', function() {
|
|||||||
originalFunction = function() {},
|
originalFunction = function() {},
|
||||||
subjectParent = { spiedFunc: originalFunction };
|
subjectParent = { spiedFunc: originalFunction };
|
||||||
|
|
||||||
var subject = Object.create(subjectParent);
|
const subject = Object.create(subjectParent);
|
||||||
|
|
||||||
spyRegistry.spyOn(subject, 'spiedFunc');
|
spyRegistry.spyOn(subject, 'spiedFunc');
|
||||||
|
|
||||||
@@ -619,7 +619,7 @@ describe('SpyRegistry', function() {
|
|||||||
function FakeWindow() {}
|
function FakeWindow() {}
|
||||||
FakeWindow.prototype.onerror = function() {};
|
FakeWindow.prototype.onerror = function() {};
|
||||||
|
|
||||||
var spies = [],
|
const spies = [],
|
||||||
global = new FakeWindow(),
|
global = new FakeWindow(),
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
@@ -638,7 +638,7 @@ describe('SpyRegistry', function() {
|
|||||||
|
|
||||||
describe('spying on properties', function() {
|
describe('spying on properties', function() {
|
||||||
it('restores the original properties on the spied-upon objects', function() {
|
it('restores the original properties on the spied-upon objects', function() {
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -662,7 +662,7 @@ describe('SpyRegistry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not add a property that the spied-upon object didn't originally have", function() {
|
it("does not add a property that the spied-upon object didn't originally have", function() {
|
||||||
var spies = [],
|
const spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
currentSpies: function() {
|
currentSpies: function() {
|
||||||
return spies;
|
return spies;
|
||||||
@@ -679,7 +679,7 @@ describe('SpyRegistry', function() {
|
|||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var subject = Object.create(subjectParent);
|
const subject = Object.create(subjectParent);
|
||||||
|
|
||||||
expect(subject.hasOwnProperty('spiedProp')).toBe(false);
|
expect(subject.hasOwnProperty('spiedProp')).toBe(false);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe('Spies', function() {
|
describe('Spies', function() {
|
||||||
var env;
|
let env;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
@@ -10,7 +10,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('createSpy', function() {
|
describe('createSpy', function() {
|
||||||
var TestClass;
|
let TestClass;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
TestClass = function() {};
|
TestClass = function() {};
|
||||||
@@ -19,7 +19,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('preserves the properties of the spied function', function() {
|
it('preserves the properties of the spied function', function() {
|
||||||
var spy = env.createSpy(
|
const spy = env.createSpy(
|
||||||
TestClass.prototype,
|
TestClass.prototype,
|
||||||
TestClass.prototype.someFunction
|
TestClass.prototype.someFunction
|
||||||
);
|
);
|
||||||
@@ -28,8 +28,8 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should allow you to omit the name argument and only pass the originalFn argument', function() {
|
it('should allow you to omit the name argument and only pass the originalFn argument', function() {
|
||||||
var fn = function test() {};
|
const fn = function test() {};
|
||||||
var spy = env.createSpy(fn);
|
const spy = env.createSpy(fn);
|
||||||
|
|
||||||
expect(spy.and.identity).toEqual('test');
|
expect(spy.and.identity).toEqual('test');
|
||||||
});
|
});
|
||||||
@@ -45,7 +45,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds a spyStrategy and callTracker to the spy', function() {
|
it('adds a spyStrategy and callTracker to the spy', function() {
|
||||||
var spy = env.createSpy(
|
const spy = env.createSpy(
|
||||||
TestClass.prototype,
|
TestClass.prototype,
|
||||||
TestClass.prototype.someFunction
|
TestClass.prototype.someFunction
|
||||||
);
|
);
|
||||||
@@ -55,11 +55,11 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the argument of calls', function() {
|
it('tracks the argument of calls', function() {
|
||||||
var spy = env.createSpy(
|
const spy = env.createSpy(
|
||||||
TestClass.prototype,
|
TestClass.prototype,
|
||||||
TestClass.prototype.someFunction
|
TestClass.prototype.someFunction
|
||||||
);
|
);
|
||||||
var trackSpy = spyOn(spy.calls, 'track');
|
const trackSpy = spyOn(spy.calls, 'track');
|
||||||
|
|
||||||
spy('arg');
|
spy('arg');
|
||||||
|
|
||||||
@@ -67,24 +67,24 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the context of calls', function() {
|
it('tracks the context of calls', function() {
|
||||||
var spy = env.createSpy(
|
const spy = env.createSpy(
|
||||||
TestClass.prototype,
|
TestClass.prototype,
|
||||||
TestClass.prototype.someFunction
|
TestClass.prototype.someFunction
|
||||||
);
|
);
|
||||||
var trackSpy = spyOn(spy.calls, 'track');
|
const trackSpy = spyOn(spy.calls, 'track');
|
||||||
|
|
||||||
var contextObject = { spyMethod: spy };
|
const contextObject = { spyMethod: spy };
|
||||||
contextObject.spyMethod();
|
contextObject.spyMethod();
|
||||||
|
|
||||||
expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
|
expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the return value of calls', function() {
|
it('tracks the return value of calls', function() {
|
||||||
var spy = env.createSpy(
|
const spy = env.createSpy(
|
||||||
TestClass.prototype,
|
TestClass.prototype,
|
||||||
TestClass.prototype.someFunction
|
TestClass.prototype.someFunction
|
||||||
);
|
);
|
||||||
var trackSpy = spyOn(spy.calls, 'track');
|
const trackSpy = spyOn(spy.calls, 'track');
|
||||||
|
|
||||||
spy.and.returnValue('return value');
|
spy.and.returnValue('return value');
|
||||||
spy();
|
spy();
|
||||||
@@ -95,18 +95,24 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('preserves arity of original function', function() {
|
it('preserves arity of original function', function() {
|
||||||
var functions = [
|
const functions = [
|
||||||
function nullary() {},
|
function nullary() {},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function unary(arg) {},
|
function unary(arg) {},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function binary(arg1, arg2) {},
|
function binary(arg1, arg2) {},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function ternary(arg1, arg2, arg3) {},
|
function ternary(arg1, arg2, arg3) {},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function quaternary(arg1, arg2, arg3, arg4) {},
|
function quaternary(arg1, arg2, arg3, arg4) {},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function quinary(arg1, arg2, arg3, arg4, arg5) {},
|
function quinary(arg1, arg2, arg3, arg4, arg5) {},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function senary(arg1, arg2, arg3, arg4, arg5, arg6) {}
|
function senary(arg1, arg2, arg3, arg4, arg5, arg6) {}
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var arity = 0; arity < functions.length; arity++) {
|
for (let arity = 0; arity < functions.length; arity++) {
|
||||||
var someFunction = functions[arity],
|
const someFunction = functions[arity],
|
||||||
spy = env.createSpy(someFunction.name, someFunction);
|
spy = env.createSpy(someFunction.name, someFunction);
|
||||||
|
|
||||||
expect(spy.length).toEqual(arity);
|
expect(spy.length).toEqual(arity);
|
||||||
@@ -116,7 +122,7 @@ describe('Spies', function() {
|
|||||||
|
|
||||||
describe('createSpyObj', function() {
|
describe('createSpyObj', function() {
|
||||||
it('should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object', function() {
|
it('should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object', function() {
|
||||||
var spyObj = env.createSpyObj('BaseName', {
|
const spyObj = env.createSpyObj('BaseName', {
|
||||||
method1: 42,
|
method1: 42,
|
||||||
method2: 'special sauce'
|
method2: 'special sauce'
|
||||||
});
|
});
|
||||||
@@ -129,7 +135,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should create an object with a bunch of spy methods when you call jasmine.createSpyObj()', function() {
|
it('should create an object with a bunch of spy methods when you call jasmine.createSpyObj()', function() {
|
||||||
var spyObj = env.createSpyObj('BaseName', ['method1', 'method2']);
|
const spyObj = env.createSpyObj('BaseName', ['method1', 'method2']);
|
||||||
|
|
||||||
expect(spyObj).toEqual({
|
expect(spyObj).toEqual({
|
||||||
method1: jasmine.any(Function),
|
method1: jasmine.any(Function),
|
||||||
@@ -140,7 +146,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should allow you to omit the baseName', function() {
|
it('should allow you to omit the baseName', function() {
|
||||||
var spyObj = env.createSpyObj(['method1', 'method2']);
|
const spyObj = env.createSpyObj(['method1', 'method2']);
|
||||||
|
|
||||||
expect(spyObj).toEqual({
|
expect(spyObj).toEqual({
|
||||||
method1: jasmine.any(Function),
|
method1: jasmine.any(Function),
|
||||||
@@ -175,20 +181,20 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('creates an object with spy properties if a second list is passed', function() {
|
it('creates an object with spy properties if a second list is passed', function() {
|
||||||
var spyObj = env.createSpyObj('base', ['method1'], ['prop1']);
|
const spyObj = env.createSpyObj('base', ['method1'], ['prop1']);
|
||||||
|
|
||||||
expect(spyObj).toEqual({
|
expect(spyObj).toEqual({
|
||||||
method1: jasmine.any(Function),
|
method1: jasmine.any(Function),
|
||||||
prop1: undefined
|
prop1: undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
var descriptor = Object.getOwnPropertyDescriptor(spyObj, 'prop1');
|
const descriptor = Object.getOwnPropertyDescriptor(spyObj, 'prop1');
|
||||||
expect(descriptor.get.and.identity).toEqual('base.prop1.get');
|
expect(descriptor.get.and.identity).toEqual('base.prop1.get');
|
||||||
expect(descriptor.set.and.identity).toEqual('base.prop1.set');
|
expect(descriptor.set.and.identity).toEqual('base.prop1.set');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates an object with property names and return values if second object is passed', function() {
|
it('creates an object with property names and return values if second object is passed', function() {
|
||||||
var spyObj = env.createSpyObj('base', ['method1'], {
|
const spyObj = env.createSpyObj('base', ['method1'], {
|
||||||
prop1: 'foo',
|
prop1: 'foo',
|
||||||
prop2: 37
|
prop2: 37
|
||||||
});
|
});
|
||||||
@@ -209,7 +215,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows base name to be omitted 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 });
|
const spyObj = env.createSpyObj({ m: 3 }, { p: 4 });
|
||||||
|
|
||||||
expect(spyObj.m()).toEqual(3);
|
expect(spyObj.m()).toEqual(3);
|
||||||
expect(spyObj.p).toEqual(4);
|
expect(spyObj.p).toEqual(4);
|
||||||
@@ -220,7 +226,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can use different strategies for different arguments', function() {
|
it('can use different strategies for different arguments', function() {
|
||||||
var spy = env.createSpy('foo');
|
const spy = env.createSpy('foo');
|
||||||
spy.and.returnValue(42);
|
spy.and.returnValue(42);
|
||||||
spy.withArgs('baz', 'grault').and.returnValue(-1);
|
spy.withArgs('baz', 'grault').and.returnValue(-1);
|
||||||
spy.withArgs('thud').and.returnValue('bob');
|
spy.withArgs('thud').and.returnValue('bob');
|
||||||
@@ -232,7 +238,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('uses asymmetric equality testers when selecting a strategy', function() {
|
it('uses asymmetric equality testers when selecting a strategy', function() {
|
||||||
var spy = env.createSpy('foo');
|
const spy = env.createSpy('foo');
|
||||||
spy.and.returnValue(42);
|
spy.and.returnValue(42);
|
||||||
spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
|
spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
|
||||||
|
|
||||||
@@ -258,7 +264,7 @@ describe('Spies', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can reconfigure an argument-specific strategy', function() {
|
it('can reconfigure an argument-specific strategy', function() {
|
||||||
var spy = env.createSpy('foo');
|
const spy = env.createSpy('foo');
|
||||||
spy.withArgs('foo').and.returnValue(42);
|
spy.withArgs('foo').and.returnValue(42);
|
||||||
spy.withArgs('foo').and.returnValue(17);
|
spy.withArgs('foo').and.returnValue(17);
|
||||||
expect(spy('foo')).toEqual(17);
|
expect(spy('foo')).toEqual(17);
|
||||||
@@ -266,7 +272,7 @@ describe('Spies', function() {
|
|||||||
|
|
||||||
describe('any promise-based strategy', function() {
|
describe('any promise-based strategy', function() {
|
||||||
it('works with global Promise library', function(done) {
|
it('works with global Promise library', function(done) {
|
||||||
var spy = env.createSpy('foo').and.resolveTo(42);
|
const spy = env.createSpy('foo').and.resolveTo(42);
|
||||||
spy()
|
spy()
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
expect(result).toEqual(42);
|
expect(result).toEqual(42);
|
||||||
@@ -278,14 +284,14 @@ describe('Spies', function() {
|
|||||||
|
|
||||||
describe('when withArgs is used without a base strategy', function() {
|
describe('when withArgs is used without a base strategy', function() {
|
||||||
it('uses the matching strategy', function() {
|
it('uses the matching strategy', function() {
|
||||||
var spy = env.createSpy('foo');
|
const spy = env.createSpy('foo');
|
||||||
spy.withArgs('baz').and.returnValue(-1);
|
spy.withArgs('baz').and.returnValue(-1);
|
||||||
|
|
||||||
expect(spy('baz')).toEqual(-1);
|
expect(spy('baz')).toEqual(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws if the args don't match", function() {
|
it("throws if the args don't match", function() {
|
||||||
var spy = env.createSpy('foo');
|
const spy = env.createSpy('foo');
|
||||||
spy.withArgs('bar').and.returnValue(-1);
|
spy.withArgs('bar').and.returnValue(-1);
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
describe('SpyStrategy', function() {
|
describe('SpyStrategy', function() {
|
||||||
it('defaults its name to unknown', function() {
|
it('defaults its name to unknown', function() {
|
||||||
var spyStrategy = new jasmineUnderTest.SpyStrategy();
|
const spyStrategy = new jasmineUnderTest.SpyStrategy();
|
||||||
|
|
||||||
expect(spyStrategy.identity).toEqual('unknown');
|
expect(spyStrategy.identity).toEqual('unknown');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('takes a name', function() {
|
it('takes a name', function() {
|
||||||
var spyStrategy = new jasmineUnderTest.SpyStrategy({ name: 'foo' });
|
const spyStrategy = new jasmineUnderTest.SpyStrategy({ name: 'foo' });
|
||||||
|
|
||||||
expect(spyStrategy.identity).toEqual('foo');
|
expect(spyStrategy.identity).toEqual('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stubs an original function, if provided', function() {
|
it('stubs an original function, if provided', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyStrategy.exec();
|
spyStrategy.exec();
|
||||||
@@ -21,12 +21,11 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("allows an original function to be called, passed through the params and returns it's value", function() {
|
it("allows an original function to be called, passed through the params and returns it's value", function() {
|
||||||
var originalFn = jasmine.createSpy('original').and.returnValue(42),
|
const originalFn = jasmine.createSpy('original').and.returnValue(42),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
returnValue;
|
|
||||||
|
|
||||||
spyStrategy.callThrough();
|
spyStrategy.callThrough();
|
||||||
returnValue = spyStrategy.exec(null, ['foo']);
|
const returnValue = spyStrategy.exec(null, ['foo']);
|
||||||
|
|
||||||
expect(originalFn).toHaveBeenCalled();
|
expect(originalFn).toHaveBeenCalled();
|
||||||
expect(originalFn.calls.mostRecent().args).toEqual(['foo']);
|
expect(originalFn.calls.mostRecent().args).toEqual(['foo']);
|
||||||
@@ -34,19 +33,18 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can return a specified value when executed', function() {
|
it('can return a specified value when executed', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
returnValue;
|
|
||||||
|
|
||||||
spyStrategy.returnValue(17);
|
spyStrategy.returnValue(17);
|
||||||
returnValue = spyStrategy.exec();
|
const returnValue = spyStrategy.exec();
|
||||||
|
|
||||||
expect(originalFn).not.toHaveBeenCalled();
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
expect(returnValue).toEqual(17);
|
expect(returnValue).toEqual(17);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can return specified values in order specified when executed', function() {
|
it('can return specified values in order specified when executed', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyStrategy.returnValues('value1', 'value2', 'value3');
|
spyStrategy.returnValues('value1', 'value2', 'value3');
|
||||||
@@ -59,7 +57,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows an exception to be thrown when executed', function() {
|
it('allows an exception to be thrown when executed', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyStrategy.throwError(new TypeError('bar'));
|
spyStrategy.throwError(new TypeError('bar'));
|
||||||
@@ -71,7 +69,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a string 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'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyStrategy.throwError('bar');
|
spyStrategy.throwError('bar');
|
||||||
@@ -83,7 +81,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a non-Error to be thrown when executed', function() {
|
it('allows a non-Error to be thrown when executed', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyStrategy.throwError({ code: 'ESRCH' });
|
spyStrategy.throwError({ code: 'ESRCH' });
|
||||||
@@ -95,23 +93,22 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a fake function to be called instead', function() {
|
it('allows a fake function to be called instead', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
returnValue;
|
|
||||||
|
|
||||||
spyStrategy.callFake(fakeFn);
|
spyStrategy.callFake(fakeFn);
|
||||||
returnValue = spyStrategy.exec();
|
const returnValue = spyStrategy.exec();
|
||||||
|
|
||||||
expect(originalFn).not.toHaveBeenCalled();
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
expect(returnValue).toEqual(67);
|
expect(returnValue).toEqual(67);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows a fake async function to be called instead', function(done) {
|
it('allows a fake async function to be called instead', function(done) {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
fakeFn = jasmine
|
fakeFn = jasmine.createSpy('fake').and.callFake(async () => {
|
||||||
.createSpy('fake')
|
return 67;
|
||||||
.and.callFake(eval('async () => { return 67; }')),
|
}),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyStrategy.callFake(fakeFn);
|
spyStrategy.callFake(fakeFn);
|
||||||
@@ -130,7 +127,7 @@ describe('SpyStrategy', function() {
|
|||||||
|
|
||||||
describe('#resolveTo', function() {
|
describe('#resolveTo', function() {
|
||||||
it('allows a resolved promise to be returned', function(done) {
|
it('allows a resolved promise to be returned', function(done) {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
fn: originalFn
|
fn: originalFn
|
||||||
});
|
});
|
||||||
@@ -146,7 +143,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows an empty resolved promise to be returned', function(done) {
|
it('allows an empty resolved promise to be returned', function(done) {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
fn: originalFn
|
fn: originalFn
|
||||||
});
|
});
|
||||||
@@ -164,7 +161,7 @@ describe('SpyStrategy', function() {
|
|||||||
|
|
||||||
describe('#rejectWith', function() {
|
describe('#rejectWith', function() {
|
||||||
it('allows a rejected promise to be returned', function(done) {
|
it('allows a rejected promise to be returned', function(done) {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
fn: originalFn
|
fn: originalFn
|
||||||
});
|
});
|
||||||
@@ -181,7 +178,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows an empty rejected promise to be returned', function(done) {
|
it('allows an empty rejected promise to be returned', function(done) {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
fn: originalFn
|
fn: originalFn
|
||||||
});
|
});
|
||||||
@@ -198,7 +195,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a non-Error to be rejected', function(done) {
|
it('allows a non-Error to be rejected', function(done) {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
fn: originalFn
|
fn: originalFn
|
||||||
});
|
});
|
||||||
@@ -216,7 +213,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a custom strategy to be used', function() {
|
it('allows a custom strategy to be used', function() {
|
||||||
var plan = jasmine
|
const plan = jasmine
|
||||||
.createSpy('custom strategy')
|
.createSpy('custom strategy')
|
||||||
.and.returnValue('custom strategy result'),
|
.and.returnValue('custom strategy result'),
|
||||||
customStrategy = jasmine
|
customStrategy = jasmine
|
||||||
@@ -239,7 +236,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("throws an error if a custom strategy doesn't return a function", function() {
|
it("throws an error if a custom strategy doesn't return a function", function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
fn: originalFn,
|
fn: originalFn,
|
||||||
customStrategies: {
|
customStrategies: {
|
||||||
@@ -255,7 +252,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not allow custom strategies to overwrite existing methods', function() {
|
it('does not allow custom strategies to overwrite existing methods', function() {
|
||||||
var spyStrategy = new jasmineUnderTest.SpyStrategy({
|
const spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||||
fn: function() {},
|
fn: function() {},
|
||||||
customStrategies: {
|
customStrategies: {
|
||||||
exec: function() {}
|
exec: function() {}
|
||||||
@@ -266,7 +263,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error when a non-function is passed to callFake strategy', function() {
|
it('throws an error when a non-function is passed to callFake strategy', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
|
|
||||||
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
|
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
|
||||||
@@ -282,7 +279,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows generator functions to be passed to callFake strategy', function() {
|
it('allows generator functions to be passed to callFake strategy', function() {
|
||||||
var generator = function*() {
|
const generator = function*() {
|
||||||
yield 'ok';
|
yield 'ok';
|
||||||
},
|
},
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
|
||||||
@@ -293,13 +290,12 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a return to plan stubbing after another strategy', function() {
|
it('allows a return to plan stubbing after another strategy', function() {
|
||||||
var originalFn = jasmine.createSpy('original'),
|
const originalFn = jasmine.createSpy('original'),
|
||||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||||
returnValue;
|
|
||||||
|
|
||||||
spyStrategy.callFake(fakeFn);
|
spyStrategy.callFake(fakeFn);
|
||||||
returnValue = spyStrategy.exec();
|
let returnValue = spyStrategy.exec();
|
||||||
|
|
||||||
expect(originalFn).not.toHaveBeenCalled();
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
expect(returnValue).toEqual(67);
|
expect(returnValue).toEqual(67);
|
||||||
@@ -311,7 +307,7 @@ describe('SpyStrategy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns the spy after changing the strategy', function() {
|
it('returns the spy after changing the strategy', function() {
|
||||||
var spy = {},
|
const spy = {},
|
||||||
spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
|
spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ getSpy: spyFn });
|
spyStrategy = new jasmineUnderTest.SpyStrategy({ getSpy: spyFn });
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('StackTrace', function() {
|
describe('StackTrace', function() {
|
||||||
it('understands Chrome/Edge style traces', function() {
|
it('understands Chrome/Edge style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'Error: nope\n' +
|
'Error: nope\n' +
|
||||||
@@ -8,7 +8,7 @@ describe('StackTrace', function() {
|
|||||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.message).toEqual('Error: nope');
|
expect(result.message).toEqual('Error: nope');
|
||||||
expect(result.style).toEqual('v8');
|
expect(result.style).toEqual('v8');
|
||||||
@@ -31,7 +31,7 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('understands Chrome/Edge style traces with multiline messages', function() {
|
it('understands Chrome/Edge style traces with multiline messages', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'line 1\nline 2',
|
message: 'line 1\nline 2',
|
||||||
stack:
|
stack:
|
||||||
'Error: line 1\nline 2\n' +
|
'Error: line 1\nline 2\n' +
|
||||||
@@ -39,10 +39,10 @@ describe('StackTrace', function() {
|
|||||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.message).toEqual('Error: line 1\nline 2');
|
expect(result.message).toEqual('Error: line 1\nline 2');
|
||||||
var rawFrames = result.frames.map(function(f) {
|
const rawFrames = result.frames.map(function(f) {
|
||||||
return f.raw;
|
return f.raw;
|
||||||
});
|
});
|
||||||
expect(rawFrames).toEqual([
|
expect(rawFrames).toEqual([
|
||||||
@@ -52,7 +52,7 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('understands Node style traces', function() {
|
it('understands Node style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'Error\n' +
|
'Error\n' +
|
||||||
@@ -61,7 +61,7 @@ describe('StackTrace', function() {
|
|||||||
' at Immediate.<anonymous> (/somewhere/jasmine/lib/jasmine-core/jasmine.js:4314:12)\n' +
|
' at Immediate.<anonymous> (/somewhere/jasmine/lib/jasmine-core/jasmine.js:4314:12)\n' +
|
||||||
' at runCallback (timers.js:672:20)'
|
' at runCallback (timers.js:672:20)'
|
||||||
};
|
};
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.message).toEqual('Error');
|
expect(result.message).toEqual('Error');
|
||||||
expect(result.style).toEqual('v8');
|
expect(result.style).toEqual('v8');
|
||||||
@@ -96,13 +96,13 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('understands Safari <=14/Firefox/Phantom-OS X style traces', function() {
|
it('understands Safari <=14/Firefox/Phantom-OS X style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||||
'run@http://localhost:8888/__jasmine__/jasmine.js:4320:27'
|
'run@http://localhost:8888/__jasmine__/jasmine.js:4320:27'
|
||||||
};
|
};
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.message).toBeFalsy();
|
expect(result.message).toBeFalsy();
|
||||||
expect(result.style).toEqual('webkit');
|
expect(result.style).toEqual('webkit');
|
||||||
@@ -123,13 +123,13 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('understands Safari 15 style traces', function() {
|
it('understands Safari 15 style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'@http://localhost:8888/__spec__/core/FooSpec.js:164:24\n' +
|
'@http://localhost:8888/__spec__/core/FooSpec.js:164:24\n' +
|
||||||
'attempt@http://localhost:8888/__jasmine__/jasmine.js:8074:44\n'
|
'attempt@http://localhost:8888/__jasmine__/jasmine.js:8074:44\n'
|
||||||
};
|
};
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.message).toBeFalsy();
|
expect(result.message).toBeFalsy();
|
||||||
expect(result.style).toEqual('webkit');
|
expect(result.style).toEqual('webkit');
|
||||||
@@ -150,24 +150,24 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not mistake gibberish for Safari/Firefox/Phantom-OS X style traces', function() {
|
it('does not mistake gibberish for Safari/Firefox/Phantom-OS X style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack: 'randomcharsnotincludingwhitespace'
|
stack: 'randomcharsnotincludingwhitespace'
|
||||||
};
|
};
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
expect(result.style).toBeNull();
|
expect(result.style).toBeNull();
|
||||||
expect(result.frames).toEqual([{ raw: error.stack }]);
|
expect(result.frames).toEqual([{ raw: error.stack }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('understands Phantom-Linux style traces', function() {
|
it('understands Phantom-Linux style traces', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\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)'
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.message).toBeFalsy();
|
expect(result.message).toBeFalsy();
|
||||||
expect(result.style).toEqual('v8');
|
expect(result.style).toEqual('v8');
|
||||||
@@ -190,13 +190,13 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ignores blank lines', function() {
|
it('ignores blank lines', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n'
|
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n'
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.frames).toEqual([
|
expect(result.frames).toEqual([
|
||||||
{
|
{
|
||||||
@@ -210,7 +210,7 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("omits properties except 'raw' for frames that are not understood", function() {
|
it("omits properties except 'raw' for frames that are not understood", function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||||
@@ -218,7 +218,7 @@ describe('StackTrace', function() {
|
|||||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
expect(result.style).toEqual('v8');
|
expect(result.style).toEqual('v8');
|
||||||
expect(result.frames).toEqual([
|
expect(result.frames).toEqual([
|
||||||
{
|
{
|
||||||
@@ -242,7 +242,7 @@ describe('StackTrace', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('consideres different types of errors', function() {
|
it('consideres different types of errors', function() {
|
||||||
var error = {
|
const error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'TypeError: nope\n' +
|
'TypeError: nope\n' +
|
||||||
@@ -250,7 +250,7 @@ describe('StackTrace', function() {
|
|||||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = new jasmineUnderTest.StackTrace(error);
|
const result = new jasmineUnderTest.StackTrace(error);
|
||||||
|
|
||||||
expect(result.message).toEqual('TypeError: nope');
|
expect(result.message).toEqual('TypeError: nope');
|
||||||
expect(result.frames).toEqual([
|
expect(result.frames).toEqual([
|
||||||
@@ -270,7 +270,7 @@ describe('StackTrace', function() {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var no_error = {
|
const no_error = {
|
||||||
message: 'nope',
|
message: 'nope',
|
||||||
stack:
|
stack:
|
||||||
'Type Error: nope\n' +
|
'Type Error: nope\n' +
|
||||||
@@ -278,7 +278,7 @@ describe('StackTrace', function() {
|
|||||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||||
};
|
};
|
||||||
|
|
||||||
var result_no_error = new jasmineUnderTest.StackTrace(no_error);
|
const result_no_error = new jasmineUnderTest.StackTrace(no_error);
|
||||||
|
|
||||||
expect(result_no_error.message).not.toEqual(jasmine.anything());
|
expect(result_no_error.message).not.toEqual(jasmine.anything());
|
||||||
});
|
});
|
||||||
|
|||||||
265
spec/core/SuiteBuilderSpec.js
Normal file
265
spec/core/SuiteBuilderSpec.js
Normal file
@@ -0,0 +1,265 @@
|
|||||||
|
describe('SuiteBuilder', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
// Rethrow exceptions to ease debugging
|
||||||
|
spyOn(jasmineUnderTest.Suite.prototype, 'handleException').and.callFake(
|
||||||
|
function(e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
spyOn(jasmineUnderTest.Spec.prototype, 'handleException').and.callFake(
|
||||||
|
function(e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates the top suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
expect(suiteBuilder.topSuite).toBeInstanceOf(jasmineUnderTest.Suite);
|
||||||
|
expect(suiteBuilder.topSuite.description).toEqual(
|
||||||
|
'Jasmine__TopLevel__Suite'
|
||||||
|
);
|
||||||
|
expect(suiteBuilder.topSuite.parentSuite).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#describe', function() {
|
||||||
|
definesSuites('describe');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#fdescribe', function() {
|
||||||
|
definesSuites('fdescribe');
|
||||||
|
|
||||||
|
it('focuses the suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const suite = suiteBuilder.fdescribe('a suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.isFocused).toBeTrue();
|
||||||
|
expect(suiteBuilder.focusedRunables).toEqual([suite.id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('unfocuses any focused ancestor suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const grandparent = suiteBuilder.fdescribe('a suite', function() {
|
||||||
|
suiteBuilder.describe('another suite', function() {
|
||||||
|
suiteBuilder.fdescribe('the focused suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suiteBuilder.focusedRunables).not.toContain(grandparent.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#xdescribe', function() {
|
||||||
|
definesSuites('xdescribe');
|
||||||
|
|
||||||
|
it('excludes the suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const suite = suiteBuilder.xdescribe('a suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.markedExcluding).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('causes child suites to be marked excluded', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let suite;
|
||||||
|
suiteBuilder.xdescribe('a suite', function() {
|
||||||
|
suite = suiteBuilder.describe('another suite', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.markedExcluding).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#it', function() {
|
||||||
|
definesSpecs('it');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#fit', function() {
|
||||||
|
definesSpecs('fit');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#xit', function() {
|
||||||
|
definesSpecs('xit');
|
||||||
|
});
|
||||||
|
|
||||||
|
function definesSuites(fnName) {
|
||||||
|
it('links suites to their parents and children', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let child;
|
||||||
|
const parent = suiteBuilder[fnName]('parent', function() {
|
||||||
|
child = suiteBuilder[fnName]('child', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suiteBuilder.topSuite.children).toEqual([sameInstanceAs(parent)]);
|
||||||
|
expect(parent.children).toEqual([sameInstanceAs(child)]);
|
||||||
|
expect(child.parentSuite).toBe(parent);
|
||||||
|
expect(parent.parentSuite).toBe(suiteBuilder.topSuite);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives each suite a unique ID', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let child;
|
||||||
|
const parent = suiteBuilder[fnName]('parent', function() {
|
||||||
|
child = suiteBuilder[fnName]('child', function() {
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const ids = [suiteBuilder.topSuite.id, parent.id, child.id];
|
||||||
|
|
||||||
|
for (const id of ids) {
|
||||||
|
expect(id).toMatch(/^suite[0-9]$/);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(new Set(ids).size).toEqual(3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function definesSpecs(fnName) {
|
||||||
|
it('adds the spec to its suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
let spec;
|
||||||
|
const suite = suiteBuilder.describe('a suite', function() {
|
||||||
|
spec = suiteBuilder[fnName]('a spec', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suite.children).toEqual([sameInstanceAs(spec)]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives each spec a unique ID', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
const spec1 = suiteBuilder[fnName]('a spec', function() {});
|
||||||
|
const spec2 = suiteBuilder[fnName]('another spec', function() {});
|
||||||
|
|
||||||
|
expect(spec1.id).toMatch(/^spec[0-9]+$/);
|
||||||
|
expect(spec2.id).toMatch(/^spec[0-9]+$/);
|
||||||
|
expect(spec1.id).not.toEqual(spec2.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function sameInstanceAs(expected) {
|
||||||
|
return {
|
||||||
|
asymmetricMatch: function(actual) {
|
||||||
|
return actual === expected;
|
||||||
|
},
|
||||||
|
jasmineToString: function(pp) {
|
||||||
|
return '<same instance as ' + pp(expected) + '>';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('#parallelReset', function() {
|
||||||
|
it('resets the top suite result', function() {
|
||||||
|
jasmineUnderTest.Suite.prototype.handleException.and.callThrough();
|
||||||
|
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
suiteBuilder.topSuite.handleException(new Error('nope'));
|
||||||
|
suiteBuilder.parallelReset();
|
||||||
|
|
||||||
|
expect(suiteBuilder.topSuite.result).toEqual({
|
||||||
|
id: suiteBuilder.topSuite.id,
|
||||||
|
description: 'Jasmine__TopLevel__Suite',
|
||||||
|
fullName: '',
|
||||||
|
failedExpectations: [],
|
||||||
|
deprecationWarnings: [],
|
||||||
|
duration: null,
|
||||||
|
properties: null,
|
||||||
|
parentSuiteId: null,
|
||||||
|
filename: undefined
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes children of the top suite', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
suiteBuilder.describe('a suite', function() {
|
||||||
|
suiteBuilder.it('a nested spec');
|
||||||
|
});
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
|
||||||
|
suiteBuilder.parallelReset();
|
||||||
|
|
||||||
|
expect(suiteBuilder.topSuite.children).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves top suite befores and afters', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
|
||||||
|
function beforeAll() {}
|
||||||
|
function beforeEach() {}
|
||||||
|
function afterEach() {}
|
||||||
|
function afterAll() {}
|
||||||
|
|
||||||
|
suiteBuilder.beforeAll(beforeAll);
|
||||||
|
suiteBuilder.beforeEach(beforeEach);
|
||||||
|
suiteBuilder.afterEach(afterEach);
|
||||||
|
suiteBuilder.afterAll(afterAll);
|
||||||
|
|
||||||
|
suiteBuilder.parallelReset();
|
||||||
|
|
||||||
|
expect(suiteBuilder.topSuite.beforeAllFns).toEqual([
|
||||||
|
jasmine.objectContaining({ fn: beforeAll })
|
||||||
|
]);
|
||||||
|
expect(suiteBuilder.topSuite.beforeFns).toEqual([
|
||||||
|
jasmine.objectContaining({ fn: beforeEach })
|
||||||
|
]);
|
||||||
|
expect(suiteBuilder.topSuite.afterFns).toEqual([
|
||||||
|
jasmine.objectContaining({ fn: afterEach })
|
||||||
|
]);
|
||||||
|
expect(suiteBuilder.topSuite.afterAllFns).toEqual([
|
||||||
|
jasmine.objectContaining({ fn: afterAll })
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resets totalSpecsDefined', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
suiteBuilder.it('a spec');
|
||||||
|
|
||||||
|
suiteBuilder.parallelReset();
|
||||||
|
|
||||||
|
expect(suiteBuilder.totalSpecsDefined).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resets focusedRunables', function() {
|
||||||
|
const env = { configuration: () => ({}) };
|
||||||
|
const suiteBuilder = new jasmineUnderTest.SuiteBuilder({ env });
|
||||||
|
suiteBuilder.fit('a spec', function() {});
|
||||||
|
|
||||||
|
suiteBuilder.parallelReset();
|
||||||
|
|
||||||
|
expect(suiteBuilder.focusedRunables).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
describe('Suite', function() {
|
describe('Suite', function() {
|
||||||
var env;
|
let env;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
@@ -10,7 +10,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('keeps its id', function() {
|
it('keeps its id', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
id: 456,
|
id: 456,
|
||||||
description: 'I am a suite'
|
description: 'I am a suite'
|
||||||
@@ -20,7 +20,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns blank full name for top level suite', function() {
|
it('returns blank full name for top level suite', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a suite'
|
description: 'I am a suite'
|
||||||
});
|
});
|
||||||
@@ -29,7 +29,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns its full name when it has parent suites', function() {
|
it('returns its full name when it has parent suites', function() {
|
||||||
var parentSuite = new jasmineUnderTest.Suite({
|
const parentSuite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a parent suite',
|
description: 'I am a parent suite',
|
||||||
parentSuite: jasmine.createSpy('pretend top level suite')
|
parentSuite: jasmine.createSpy('pretend top level suite')
|
||||||
@@ -44,7 +44,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds beforeEach functions in order of needed execution', function() {
|
it('adds beforeEach functions in order of needed execution', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a suite'
|
description: 'I am a suite'
|
||||||
}),
|
}),
|
||||||
@@ -61,7 +61,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds beforeAll functions in order of needed execution', function() {
|
it('adds beforeAll functions in order of needed execution', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a suite'
|
description: 'I am a suite'
|
||||||
}),
|
}),
|
||||||
@@ -71,25 +71,14 @@ describe('Suite', function() {
|
|||||||
suite.beforeAll(outerBefore);
|
suite.beforeAll(outerBefore);
|
||||||
suite.beforeAll(innerBefore);
|
suite.beforeAll(innerBefore);
|
||||||
|
|
||||||
function sameInstance(expected) {
|
|
||||||
return {
|
|
||||||
asymmetricMatch: function(actual) {
|
|
||||||
return actual === expected;
|
|
||||||
},
|
|
||||||
jasmineToString: function() {
|
|
||||||
return `<same instance as ${expected}>`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(suite.beforeAllFns).toEqual([
|
expect(suite.beforeAllFns).toEqual([
|
||||||
{ fn: outerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) },
|
{ fn: outerBefore.fn, type: 'beforeAll', suite: jasmine.is(suite) },
|
||||||
{ fn: innerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) }
|
{ fn: innerBefore.fn, type: 'beforeAll', suite: jasmine.is(suite) }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds afterEach functions in order of needed execution', function() {
|
it('adds afterEach functions in order of needed execution', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
description: 'I am a suite'
|
description: 'I am a suite'
|
||||||
}),
|
}),
|
||||||
@@ -123,55 +112,133 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has a status of failed if any expectations have failed', function() {
|
it('has a status of failed if any expectations have failed', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
expectationResultFactory: function() {
|
|
||||||
return 'hi';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
suite.addExpectationResult(false);
|
suite.addExpectationResult(false, {});
|
||||||
expect(suite.status()).toBe('failed');
|
expect(suite.status()).toBe('failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('retrieves a result with updated status', function() {
|
it('retrieves a result with updated status', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({});
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
|
|
||||||
expect(suite.getResult().status).toBe('passed');
|
expect(suite.getResult().status).toBe('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('retrieves a result with pending status', function() {
|
it('retrieves a result with pending status', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({});
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
suite.pend();
|
suite.pend();
|
||||||
|
|
||||||
expect(suite.getResult().status).toBe('pending');
|
expect(suite.getResult().status).toBe('pending');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws an ExpectationFailed when receiving a failed expectation when throwOnExpectationFailure is set', function() {
|
it('throws an ExpectationFailed when receiving a failed expectation when throwOnExpectationFailure is set', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
expectationResultFactory: function(data) {
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
throwOnExpectationFailure: true
|
throwOnExpectationFailure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
suite.addExpectationResult(false, 'failed');
|
suite.addExpectationResult(false, { message: 'failed' });
|
||||||
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
|
||||||
|
|
||||||
expect(suite.status()).toBe('failed');
|
expect(suite.status()).toBe('failed');
|
||||||
expect(suite.result.failedExpectations).toEqual(['failed']);
|
expect(suite.result.failedExpectations).toEqual([
|
||||||
|
jasmine.objectContaining({ message: 'failed' })
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not add an additional failure when an expectation fails', function() {
|
it('does not add an additional failure when an expectation fails', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({});
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
|
|
||||||
suite.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
suite.handleException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||||
|
|
||||||
expect(suite.getResult().failedExpectations).toEqual([]);
|
expect(suite.getResult().failedExpectations).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('forwards late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({ onLateError });
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
suite.reportedDone = true;
|
||||||
|
suite.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: nope/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(suite.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late expectation failures to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
onLateError
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
matcherName: '',
|
||||||
|
passed: false,
|
||||||
|
expected: '',
|
||||||
|
actual: '',
|
||||||
|
error: new Error('nope')
|
||||||
|
};
|
||||||
|
|
||||||
|
suite.addExpectationResult(false, data, true);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
expect(suite.result.failedExpectations.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('forwards late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
onLateError
|
||||||
|
});
|
||||||
|
const error = new Error('oops');
|
||||||
|
|
||||||
|
suite.reportedDone = true;
|
||||||
|
suite.handleException(error);
|
||||||
|
|
||||||
|
expect(onLateError).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
message: jasmine.stringMatching(/^Error: oops/)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(suite.result.failedExpectations).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not forward non-late handleException calls to onLateError', function() {
|
||||||
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
onLateError
|
||||||
|
});
|
||||||
|
const error = new Error('oops');
|
||||||
|
|
||||||
|
suite.handleException(error);
|
||||||
|
|
||||||
|
expect(onLateError).not.toHaveBeenCalled();
|
||||||
|
expect(suite.result.failedExpectations.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the reportedDone flag when reset', function() {
|
||||||
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
queueableFn: { fn: function() {} }
|
||||||
|
});
|
||||||
|
suite.reportedDone = true;
|
||||||
|
|
||||||
|
suite.reset();
|
||||||
|
|
||||||
|
expect(suite.reportedDone).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
it('calls timer to compute duration', function() {
|
it('calls timer to compute duration', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
env: env,
|
||||||
id: 456,
|
id: 456,
|
||||||
description: 'I am a suite',
|
description: 'I am a suite',
|
||||||
@@ -196,7 +263,7 @@ describe('Suite', function() {
|
|||||||
|
|
||||||
describe('attr.autoCleanClosures', function() {
|
describe('attr.autoCleanClosures', function() {
|
||||||
function arrangeSuite(attrs) {
|
function arrangeSuite(attrs) {
|
||||||
var suite = new jasmineUnderTest.Suite(attrs);
|
const suite = new jasmineUnderTest.Suite(attrs);
|
||||||
suite.beforeAll(function() {});
|
suite.beforeAll(function() {});
|
||||||
suite.beforeEach(function() {});
|
suite.beforeEach(function() {});
|
||||||
suite.afterEach(function() {});
|
suite.afterEach(function() {});
|
||||||
@@ -205,7 +272,7 @@ describe('Suite', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should clean closures when "attr.autoCleanClosures" is missing', function() {
|
it('should clean closures when "attr.autoCleanClosures" is missing', function() {
|
||||||
var suite = arrangeSuite({});
|
const suite = arrangeSuite({});
|
||||||
suite.cleanupBeforeAfter();
|
suite.cleanupBeforeAfter();
|
||||||
expect(suite.beforeAllFns[0].fn).toBe(null);
|
expect(suite.beforeAllFns[0].fn).toBe(null);
|
||||||
expect(suite.beforeFns[0].fn).toBe(null);
|
expect(suite.beforeFns[0].fn).toBe(null);
|
||||||
@@ -214,7 +281,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should clean closures when "attr.autoCleanClosures" is true', function() {
|
it('should clean closures when "attr.autoCleanClosures" is true', function() {
|
||||||
var suite = arrangeSuite({ autoCleanClosures: true });
|
const suite = arrangeSuite({ autoCleanClosures: true });
|
||||||
suite.cleanupBeforeAfter();
|
suite.cleanupBeforeAfter();
|
||||||
expect(suite.beforeAllFns[0].fn).toBe(null);
|
expect(suite.beforeAllFns[0].fn).toBe(null);
|
||||||
expect(suite.beforeFns[0].fn).toBe(null);
|
expect(suite.beforeFns[0].fn).toBe(null);
|
||||||
@@ -223,7 +290,7 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT clean closures when "attr.autoCleanClosures" is false', function() {
|
it('should NOT clean closures when "attr.autoCleanClosures" is false', function() {
|
||||||
var suite = arrangeSuite({ autoCleanClosures: false });
|
const suite = arrangeSuite({ autoCleanClosures: false });
|
||||||
suite.cleanupBeforeAfter();
|
suite.cleanupBeforeAfter();
|
||||||
expect(suite.beforeAllFns[0].fn).not.toBe(null);
|
expect(suite.beforeAllFns[0].fn).not.toBe(null);
|
||||||
expect(suite.beforeFns[0].fn).not.toBe(null);
|
expect(suite.beforeFns[0].fn).not.toBe(null);
|
||||||
@@ -234,23 +301,23 @@ describe('Suite', function() {
|
|||||||
|
|
||||||
describe('#reset', function() {
|
describe('#reset', function() {
|
||||||
it('should reset the "pending" status', function() {
|
it('should reset the "pending" status', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({});
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
suite.pend();
|
suite.pend();
|
||||||
suite.reset();
|
suite.reset();
|
||||||
expect(suite.getResult().status).toBe('passed');
|
expect(suite.getResult().status).toBe('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not reset the "pending" status when the suite was excluded', function() {
|
it('should not reset the "pending" status when the suite was excluded', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({});
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
suite.exclude();
|
suite.exclude();
|
||||||
suite.reset();
|
suite.reset();
|
||||||
expect(suite.getResult().status).toBe('pending');
|
expect(suite.getResult().status).toBe('pending');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should also reset the children', function() {
|
it('should also reset the children', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({});
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
var child1 = jasmine.createSpyObj(['reset']);
|
const child1 = jasmine.createSpyObj(['reset']);
|
||||||
var child2 = jasmine.createSpyObj(['reset']);
|
const child2 = jasmine.createSpyObj(['reset']);
|
||||||
suite.addChild(child1);
|
suite.addChild(child1);
|
||||||
suite.addChild(child2);
|
suite.addChild(child2);
|
||||||
|
|
||||||
@@ -261,16 +328,12 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should reset the failedExpectations', function() {
|
it('should reset the failedExpectations', function() {
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({});
|
||||||
expectationResultFactory: function(error) {
|
suite.handleException(new Error());
|
||||||
return error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
suite.onException(new Error());
|
|
||||||
|
|
||||||
suite.reset();
|
suite.reset();
|
||||||
|
|
||||||
var result = suite.getResult();
|
const result = suite.getResult();
|
||||||
expect(result.status).toBe('passed');
|
expect(result.status).toBe('passed');
|
||||||
expect(result.failedExpectations).toHaveSize(0);
|
expect(result.failedExpectations).toHaveSize(0);
|
||||||
});
|
});
|
||||||
@@ -296,7 +359,7 @@ describe('Suite', function() {
|
|||||||
|
|
||||||
it('reports an error including the suite name when it is a normal suite', function() {
|
it('reports an error including the suite name when it is a normal suite', function() {
|
||||||
const onLateError = jasmine.createSpy('onLateError');
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
var suite = new jasmineUnderTest.Suite({
|
const suite = new jasmineUnderTest.Suite({
|
||||||
onLateError,
|
onLateError,
|
||||||
description: 'the suite',
|
description: 'the suite',
|
||||||
parentSuite: {
|
parentSuite: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('Timer', function() {
|
describe('Timer', function() {
|
||||||
it('reports the time elapsed', function() {
|
it('reports the time elapsed', function() {
|
||||||
var fakeNow = jasmine.createSpy('fake Date.now'),
|
const fakeNow = jasmine.createSpy('fake Date.now'),
|
||||||
timer = new jasmineUnderTest.Timer({ now: fakeNow });
|
timer = new jasmineUnderTest.Timer({ now: fakeNow });
|
||||||
|
|
||||||
fakeNow.and.returnValue(100);
|
fakeNow.and.returnValue(100);
|
||||||
@@ -12,7 +12,7 @@ describe('Timer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when date is stubbed, perhaps by other testing helpers', function() {
|
describe('when date is stubbed, perhaps by other testing helpers', function() {
|
||||||
var origDate = Date;
|
const origDate = Date;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
// eslint-disable-next-line no-implicit-globals
|
// eslint-disable-next-line no-implicit-globals
|
||||||
Date = jasmine.createSpy('date spy');
|
Date = jasmine.createSpy('date spy');
|
||||||
@@ -24,7 +24,7 @@ describe('Timer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not throw even though Date was taken away', function() {
|
it('does not throw even though Date was taken away', function() {
|
||||||
var timer = new jasmineUnderTest.Timer();
|
const timer = new jasmineUnderTest.Timer();
|
||||||
|
|
||||||
expect(timer.start).not.toThrow();
|
expect(timer.start).not.toThrow();
|
||||||
expect(timer.elapsed()).toEqual(jasmine.any(Number));
|
expect(timer.elapsed()).toEqual(jasmine.any(Number));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe('TreeProcessor', function() {
|
describe('TreeProcessor', function() {
|
||||||
var nodeNumber = 0,
|
let nodeNumber = 0,
|
||||||
leafNumber = 0;
|
leafNumber = 0;
|
||||||
|
|
||||||
function Node(attrs) {
|
function Node(attrs) {
|
||||||
@@ -27,7 +27,7 @@ describe('TreeProcessor', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('processes a single leaf', function() {
|
it('processes a single leaf', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: leaf,
|
tree: leaf,
|
||||||
runnableIds: [leaf.id]
|
runnableIds: [leaf.id]
|
||||||
@@ -44,7 +44,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('processes a single pending leaf', function() {
|
it('processes a single pending leaf', function() {
|
||||||
var leaf = new Leaf({ markedPending: true }),
|
const leaf = new Leaf({ markedPending: true }),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: leaf,
|
tree: leaf,
|
||||||
runnableIds: [leaf.id]
|
runnableIds: [leaf.id]
|
||||||
@@ -61,7 +61,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('processes a single non-specified leaf', function() {
|
it('processes a single non-specified leaf', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: leaf,
|
tree: leaf,
|
||||||
runnableIds: []
|
runnableIds: []
|
||||||
@@ -78,11 +78,11 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('processes a single excluded leaf', function() {
|
it('processes a single excluded leaf', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: leaf,
|
tree: leaf,
|
||||||
runnableIds: [leaf.id],
|
runnableIds: [leaf.id],
|
||||||
excludeNode: function(node) {
|
excludeNode: function() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -98,7 +98,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('processes a tree with a single leaf with the root specified', function() {
|
it('processes a tree with a single leaf with the root specified', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
parent = new Node({ children: [leaf] }),
|
parent = new Node({ children: [leaf] }),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: parent,
|
tree: parent,
|
||||||
@@ -122,7 +122,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('processes a tree with a single pending leaf, with the root specified', function() {
|
it('processes a tree with a single pending leaf, with the root specified', function() {
|
||||||
var leaf = new Leaf({ markedPending: true }),
|
const leaf = new Leaf({ markedPending: true }),
|
||||||
parent = new Node({ children: [leaf] }),
|
parent = new Node({ children: [leaf] }),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: parent,
|
tree: parent,
|
||||||
@@ -146,7 +146,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('processes a complicated tree with the root specified', function() {
|
it('processes a complicated tree with the root specified', function() {
|
||||||
var pendingLeaf = new Leaf({ markedPending: true }),
|
const pendingLeaf = new Leaf({ markedPending: true }),
|
||||||
executableLeaf = new Leaf({ markedPending: false }),
|
executableLeaf = new Leaf({ markedPending: false }),
|
||||||
parent = new Node({ children: [pendingLeaf, executableLeaf] }),
|
parent = new Node({ children: [pendingLeaf, executableLeaf] }),
|
||||||
childless = new Node(),
|
childless = new Node(),
|
||||||
@@ -218,7 +218,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('marks the run order invalid if it would re-enter a node that does not allow re-entry', function() {
|
it('marks the run order invalid if it would re-enter a node that does not allow re-entry', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
reentered = new Node({ noReenter: true, children: [leaf1, leaf2] }),
|
reentered = new Node({ noReenter: true, children: [leaf1, leaf2] }),
|
||||||
@@ -233,7 +233,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('marks the run order valid if a node being re-entered allows re-entry', function() {
|
it('marks the run order valid if a node being re-entered allows re-entry', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
reentered = new Node({ children: [leaf1, leaf2] }),
|
reentered = new Node({ children: [leaf1, leaf2] }),
|
||||||
@@ -248,7 +248,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("marks the run order valid if a node which can't be re-entered is only entered once", function() {
|
it("marks the run order valid if a node which can't be re-entered is only entered once", function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
noReentry = new Node({ noReenter: true }),
|
noReentry = new Node({ noReenter: true }),
|
||||||
@@ -263,7 +263,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("marks the run order valid if a node which can't be re-entered is run directly", function() {
|
it("marks the run order valid if a node which can't be re-entered is run directly", function() {
|
||||||
var noReentry = new Node({ noReenter: true }),
|
const noReentry = new Node({ noReenter: true }),
|
||||||
root = new Node({ children: [noReentry] }),
|
root = new Node({ children: [noReentry] }),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: root,
|
tree: root,
|
||||||
@@ -274,34 +274,36 @@ describe('TreeProcessor', function() {
|
|||||||
expect(result.valid).toBe(true);
|
expect(result.valid).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs a single leaf', function() {
|
it('runs a single leaf', async function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
node = new Node({ children: [leaf], userContext: { root: 'context' } }),
|
node = new Node({ children: [leaf], userContext: { root: 'context' } }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
processor = new jasmineUnderTest.TreeProcessor({
|
processor = new jasmineUnderTest.TreeProcessor({
|
||||||
tree: node,
|
tree: node,
|
||||||
runnableIds: [leaf.id],
|
runnableIds: [leaf.id],
|
||||||
queueRunnerFactory: queueRunner
|
queueRunnerFactory: queueRunner
|
||||||
}),
|
});
|
||||||
treeComplete = jasmine.createSpy('treeComplete');
|
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
const promise = processor.execute();
|
||||||
|
|
||||||
expect(queueRunner).toHaveBeenCalledWith({
|
expect(queueRunner).toHaveBeenCalledWith({
|
||||||
onComplete: treeComplete,
|
onComplete: jasmine.any(Function),
|
||||||
onException: jasmine.any(Function),
|
onException: jasmine.any(Function),
|
||||||
userContext: { root: 'context' },
|
userContext: { root: 'context' },
|
||||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||||
onMultipleDone: null
|
onMultipleDone: null
|
||||||
});
|
});
|
||||||
|
|
||||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
const queueRunnerArgs = queueRunner.calls.mostRecent().args[0];
|
||||||
|
queueRunnerArgs.queueableFns[0].fn('foo');
|
||||||
|
expect(leaf.execute).toHaveBeenCalledWith(queueRunner, 'foo', false, false);
|
||||||
|
|
||||||
expect(leaf.execute).toHaveBeenCalledWith('foo', false, false);
|
queueRunnerArgs.onComplete();
|
||||||
|
await expectAsync(promise).toBeResolvedTo(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs a node with no children', function() {
|
it('runs a node with no children', async function() {
|
||||||
var node = new Node({ userContext: { node: 'context' } }),
|
const node = new Node({ userContext: { node: 'context' } }),
|
||||||
root = new Node({ children: [node], userContext: { root: 'context' } }),
|
root = new Node({ children: [node], userContext: { root: 'context' } }),
|
||||||
nodeStart = jasmine.createSpy('nodeStart'),
|
nodeStart = jasmine.createSpy('nodeStart'),
|
||||||
nodeComplete = jasmine.createSpy('nodeComplete'),
|
nodeComplete = jasmine.createSpy('nodeComplete'),
|
||||||
@@ -313,21 +315,20 @@ describe('TreeProcessor', function() {
|
|||||||
nodeComplete: nodeComplete,
|
nodeComplete: nodeComplete,
|
||||||
queueRunnerFactory: queueRunner
|
queueRunnerFactory: queueRunner
|
||||||
}),
|
}),
|
||||||
treeComplete = jasmine.createSpy('treeComplete'),
|
|
||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
const promise = processor.execute();
|
||||||
|
|
||||||
expect(queueRunner).toHaveBeenCalledWith({
|
expect(queueRunner).toHaveBeenCalledWith({
|
||||||
onComplete: treeComplete,
|
onComplete: jasmine.any(Function),
|
||||||
onException: jasmine.any(Function),
|
onException: jasmine.any(Function),
|
||||||
userContext: { root: 'context' },
|
userContext: { root: 'context' },
|
||||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||||
onMultipleDone: null
|
onMultipleDone: null
|
||||||
});
|
});
|
||||||
|
|
||||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn(nodeDone);
|
const queueRunnerArgs = queueRunner.calls.mostRecent().args[0];
|
||||||
|
queueRunnerArgs.queueableFns[0].fn(nodeDone);
|
||||||
expect(queueRunner).toHaveBeenCalledWith({
|
expect(queueRunner).toHaveBeenCalledWith({
|
||||||
onComplete: jasmine.any(Function),
|
onComplete: jasmine.any(Function),
|
||||||
onMultipleDone: null,
|
onMultipleDone: null,
|
||||||
@@ -348,10 +349,13 @@ describe('TreeProcessor', function() {
|
|||||||
{ my: 'result' },
|
{ my: 'result' },
|
||||||
jasmine.any(Function)
|
jasmine.any(Function)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
queueRunnerArgs.onComplete();
|
||||||
|
await expectAsync(promise).toBeResolvedTo(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs a node with children', function() {
|
it('runs a node with children', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
node = new Node({ children: [leaf1, leaf2] }),
|
node = new Node({ children: [leaf1, leaf2] }),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
@@ -365,21 +369,31 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(3);
|
expect(queueableFns.length).toBe(3);
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', false, false);
|
expect(leaf1.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
'foo',
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
queueableFns[2].fn('bar');
|
queueableFns[2].fn('bar');
|
||||||
expect(leaf2.execute).toHaveBeenCalledWith('bar', false, false);
|
expect(leaf2.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
'bar',
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cascades errors up the tree', function() {
|
it('cascades errors up the tree', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
node = new Node({ children: [leaf] }),
|
node = new Node({ children: [leaf] }),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -394,14 +408,14 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(2);
|
expect(queueableFns.length).toBe(2);
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf.execute).toHaveBeenCalledWith('foo', false, false);
|
expect(leaf.execute).toHaveBeenCalledWith(queueRunner, 'foo', false, false);
|
||||||
|
|
||||||
queueRunner.calls.mostRecent().args[0].onComplete('things');
|
queueRunner.calls.mostRecent().args[0].onComplete('things');
|
||||||
expect(nodeComplete).toHaveBeenCalled();
|
expect(nodeComplete).toHaveBeenCalled();
|
||||||
@@ -410,7 +424,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs an excluded node with leaf', function() {
|
it('runs an excluded node with leaf', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
node = new Node({ children: [leaf1] }),
|
node = new Node({ children: [leaf1] }),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -427,7 +441,7 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
@@ -437,7 +451,7 @@ describe('TreeProcessor', function() {
|
|||||||
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
|
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', true, false);
|
expect(leaf1.execute).toHaveBeenCalledWith(queueRunner, 'foo', true, false);
|
||||||
|
|
||||||
node.getResult.and.returnValue({ im: 'disabled' });
|
node.getResult.and.returnValue({ im: 'disabled' });
|
||||||
|
|
||||||
@@ -450,7 +464,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should execute node with correct arguments when failSpecWithNoExpectations option is set', function() {
|
it('should execute node with correct arguments when failSpecWithNoExpectations option is set', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
node = new Node({ children: [leaf] }),
|
node = new Node({ children: [leaf] }),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -468,18 +482,18 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(2);
|
expect(queueableFns.length).toBe(2);
|
||||||
|
|
||||||
queueableFns[1].fn('foo');
|
queueableFns[1].fn('foo');
|
||||||
expect(leaf.execute).toHaveBeenCalledWith('foo', true, true);
|
expect(leaf.execute).toHaveBeenCalledWith(queueRunner, 'foo', true, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs beforeAlls for a node with children', function() {
|
it('runs beforeAlls for a node with children', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
node = new Node({
|
node = new Node({
|
||||||
children: [leaf],
|
children: [leaf],
|
||||||
beforeAllFns: [
|
beforeAllFns: [
|
||||||
@@ -498,7 +512,7 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
@@ -512,7 +526,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs afterAlls for a node with children', function() {
|
it('runs afterAlls for a node with children', function() {
|
||||||
var leaf = new Leaf(),
|
const leaf = new Leaf(),
|
||||||
afterAllFns = [{ fn: 'afterAll1' }, { fn: 'afterAll2' }],
|
afterAllFns = [{ fn: 'afterAll1' }, { fn: 'afterAll2' }],
|
||||||
node = new Node({
|
node = new Node({
|
||||||
children: [leaf],
|
children: [leaf],
|
||||||
@@ -529,7 +543,7 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
@@ -543,7 +557,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not run beforeAlls or afterAlls for a node with no children', function() {
|
it('does not run beforeAlls or afterAlls for a node with no children', function() {
|
||||||
var node = new Node({
|
const node = new Node({
|
||||||
beforeAllFns: [{ fn: 'before' }],
|
beforeAllFns: [{ fn: 'before' }],
|
||||||
afterAllFns: [{ fn: 'after' }]
|
afterAllFns: [{ fn: 'after' }]
|
||||||
}),
|
}),
|
||||||
@@ -558,7 +572,7 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
@@ -567,7 +581,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not run beforeAlls or afterAlls for a node with only pending children', function() {
|
it('does not run beforeAlls or afterAlls for a node with only pending children', function() {
|
||||||
var leaf = new Leaf({ markedPending: true }),
|
const leaf = new Leaf({ markedPending: true }),
|
||||||
node = new Node({
|
node = new Node({
|
||||||
children: [leaf],
|
children: [leaf],
|
||||||
beforeAllFns: [{ fn: 'before' }],
|
beforeAllFns: [{ fn: 'before' }],
|
||||||
@@ -585,7 +599,7 @@ describe('TreeProcessor', function() {
|
|||||||
nodeDone = jasmine.createSpy('nodeDone');
|
nodeDone = jasmine.createSpy('nodeDone');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn(nodeDone);
|
queueableFns[0].fn(nodeDone);
|
||||||
|
|
||||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
@@ -597,7 +611,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs leaves in the order specified', function() {
|
it('runs leaves in the order specified', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
root = new Node({ children: [leaf1, leaf2] }),
|
root = new Node({ children: [leaf1, leaf2] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -609,7 +623,7 @@ describe('TreeProcessor', function() {
|
|||||||
treeComplete = jasmine.createSpy('treeComplete');
|
treeComplete = jasmine.createSpy('treeComplete');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
|
|
||||||
expect(leaf1.execute).not.toHaveBeenCalled();
|
expect(leaf1.execute).not.toHaveBeenCalled();
|
||||||
@@ -621,7 +635,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs specified leaves before non-specified leaves within a parent node', function() {
|
it('runs specified leaves before non-specified leaves within a parent node', function() {
|
||||||
var specified = new Leaf(),
|
const specified = new Leaf(),
|
||||||
nonSpecified = new Leaf(),
|
nonSpecified = new Leaf(),
|
||||||
root = new Node({ children: [nonSpecified, specified] }),
|
root = new Node({ children: [nonSpecified, specified] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -633,19 +647,29 @@ describe('TreeProcessor', function() {
|
|||||||
treeComplete = jasmine.createSpy('treeComplete');
|
treeComplete = jasmine.createSpy('treeComplete');
|
||||||
|
|
||||||
processor.execute(treeComplete);
|
processor.execute(treeComplete);
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
|
|
||||||
expect(nonSpecified.execute).not.toHaveBeenCalled();
|
expect(nonSpecified.execute).not.toHaveBeenCalled();
|
||||||
expect(specified.execute).toHaveBeenCalledWith(undefined, false, false);
|
expect(specified.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
undefined,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
queueableFns[1].fn();
|
queueableFns[1].fn();
|
||||||
|
|
||||||
expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, true, false);
|
expect(nonSpecified.execute).toHaveBeenCalledWith(
|
||||||
|
queueRunner,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('runs nodes and leaves with a specified order', function() {
|
it('runs nodes and leaves with a specified order', function() {
|
||||||
var specifiedLeaf = new Leaf(),
|
const specifiedLeaf = new Leaf(),
|
||||||
childLeaf = new Leaf(),
|
childLeaf = new Leaf(),
|
||||||
specifiedNode = new Node({ children: [childLeaf] }),
|
specifiedNode = new Node({ children: [childLeaf] }),
|
||||||
root = new Node({ children: [specifiedLeaf, specifiedNode] }),
|
root = new Node({ children: [specifiedLeaf, specifiedNode] }),
|
||||||
@@ -657,11 +681,12 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
processor.execute();
|
processor.execute();
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
|
|
||||||
expect(specifiedLeaf.execute).not.toHaveBeenCalled();
|
expect(specifiedLeaf.execute).not.toHaveBeenCalled();
|
||||||
var nodeQueueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const nodeQueueableFns = queueRunner.calls.mostRecent().args[0]
|
||||||
|
.queueableFns;
|
||||||
nodeQueueableFns[1].fn();
|
nodeQueueableFns[1].fn();
|
||||||
|
|
||||||
expect(childLeaf.execute).toHaveBeenCalled();
|
expect(childLeaf.execute).toHaveBeenCalled();
|
||||||
@@ -672,7 +697,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs a node multiple times if the order specified leaves and re-enters it', function() {
|
it('runs a node multiple times if the order specified leaves and re-enters it', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
leaf4 = new Leaf(),
|
leaf4 = new Leaf(),
|
||||||
@@ -687,7 +712,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
processor.execute();
|
processor.execute();
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(5);
|
expect(queueableFns.length).toBe(5);
|
||||||
|
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
@@ -715,7 +740,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs a parent of a node with segments correctly', function() {
|
it('runs a parent of a node with segments correctly', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
leaf4 = new Leaf(),
|
leaf4 = new Leaf(),
|
||||||
@@ -731,7 +756,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
processor.execute();
|
processor.execute();
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(5);
|
expect(queueableFns.length).toBe(5);
|
||||||
|
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
@@ -772,7 +797,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs nodes in the order they were declared', function() {
|
it('runs nodes in the order they were declared', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
parent = new Node({ children: [leaf2, leaf3] }),
|
parent = new Node({ children: [leaf2, leaf3] }),
|
||||||
@@ -785,7 +810,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
processor.execute();
|
processor.execute();
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(2);
|
expect(queueableFns.length).toBe(2);
|
||||||
|
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
@@ -793,7 +818,7 @@ describe('TreeProcessor', function() {
|
|||||||
|
|
||||||
queueableFns[1].fn();
|
queueableFns[1].fn();
|
||||||
|
|
||||||
var childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(childFns.length).toBe(3);
|
expect(childFns.length).toBe(3);
|
||||||
childFns[1].fn();
|
childFns[1].fn();
|
||||||
expect(leaf2.execute).toHaveBeenCalled();
|
expect(leaf2.execute).toHaveBeenCalled();
|
||||||
@@ -803,7 +828,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs large segments of nodes in the order they were declared', function() {
|
it('runs large segments of nodes in the order they were declared', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
leaf4 = new Leaf(),
|
leaf4 = new Leaf(),
|
||||||
@@ -837,7 +862,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
processor.execute();
|
processor.execute();
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(11);
|
expect(queueableFns.length).toBe(11);
|
||||||
|
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
@@ -875,7 +900,7 @@ describe('TreeProcessor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs nodes in a custom order when orderChildren is overridden', function() {
|
it('runs nodes in a custom order when orderChildren is overridden', function() {
|
||||||
var leaf1 = new Leaf(),
|
const leaf1 = new Leaf(),
|
||||||
leaf2 = new Leaf(),
|
leaf2 = new Leaf(),
|
||||||
leaf3 = new Leaf(),
|
leaf3 = new Leaf(),
|
||||||
leaf4 = new Leaf(),
|
leaf4 = new Leaf(),
|
||||||
@@ -907,13 +932,13 @@ describe('TreeProcessor', function() {
|
|||||||
runnableIds: [root.id],
|
runnableIds: [root.id],
|
||||||
queueRunnerFactory: queueRunner,
|
queueRunnerFactory: queueRunner,
|
||||||
orderChildren: function(node) {
|
orderChildren: function(node) {
|
||||||
var children = node.children.slice();
|
const children = node.children.slice();
|
||||||
return children.reverse();
|
return children.reverse();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
processor.execute();
|
processor.execute();
|
||||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||||
expect(queueableFns.length).toBe(11);
|
expect(queueableFns.length).toBe(11);
|
||||||
|
|
||||||
queueableFns[0].fn();
|
queueableFns[0].fn();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
describe('UserContext', function() {
|
describe('UserContext', function() {
|
||||||
it('Behaves just like an plain object', function() {
|
it('Behaves just like an plain object', function() {
|
||||||
var context = new jasmineUnderTest.UserContext(),
|
const context = new jasmineUnderTest.UserContext(),
|
||||||
properties = [];
|
properties = [];
|
||||||
|
|
||||||
for (var prop in context) {
|
for (const prop in context) {
|
||||||
if (obj.hasOwnProperty(prop)) {
|
if (obj.hasOwnProperty(prop)) {
|
||||||
properties.push(prop);
|
properties.push(prop);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
describe('jasmineUnderTest.util', function() {
|
describe('util', function() {
|
||||||
describe('isArray_', function() {
|
describe('isArray_', function() {
|
||||||
it('should return true if the argument is an array', function() {
|
it('should return true if the argument is an array', function() {
|
||||||
expect(jasmineUnderTest.isArray_([])).toBe(true);
|
expect(jasmineUnderTest.isArray_([])).toBe(true);
|
||||||
@@ -32,14 +32,14 @@ describe('jasmineUnderTest.util', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('promise utils', function() {
|
describe('promise utils', function() {
|
||||||
var mockNativePromise, mockPromiseLikeObject;
|
let mockNativePromise, mockPromiseLikeObject;
|
||||||
|
|
||||||
var mockPromiseLike = function() {
|
const mockPromiseLike = function() {
|
||||||
this.then = function() {};
|
this.then = function() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
mockNativePromise = new Promise(function(res, rej) {});
|
mockNativePromise = new Promise(function() {});
|
||||||
mockPromiseLikeObject = new mockPromiseLike();
|
mockPromiseLikeObject = new mockPromiseLike();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,18 +130,44 @@ describe('jasmineUnderTest.util', function() {
|
|||||||
|
|
||||||
describe('isUndefined', function() {
|
describe('isUndefined', function() {
|
||||||
it('reports if a variable is defined', function() {
|
it('reports if a variable is defined', function() {
|
||||||
var a;
|
let a;
|
||||||
expect(jasmineUnderTest.util.isUndefined(a)).toBe(true);
|
expect(jasmineUnderTest.util.isUndefined(a)).toBe(true);
|
||||||
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(true);
|
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(true);
|
||||||
|
|
||||||
var undefined = 'diz be undefined yo';
|
const defined = 'diz be undefined yo';
|
||||||
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(false);
|
expect(jasmineUnderTest.util.isUndefined(defined)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('cloneArgs', function() {
|
||||||
|
it('clones primitives as-is', function() {
|
||||||
|
expect(jasmineUnderTest.util.cloneArgs([true, false])).toEqual([
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
]);
|
||||||
|
expect(jasmineUnderTest.util.cloneArgs([0, 1])).toEqual([0, 1]);
|
||||||
|
expect(jasmineUnderTest.util.cloneArgs(['str'])).toEqual(['str']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clones Regexp objects as-is', function() {
|
||||||
|
const regex = /match/;
|
||||||
|
expect(jasmineUnderTest.util.cloneArgs([regex])).toEqual([regex]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clones Date objects as-is', function() {
|
||||||
|
const date = new Date(2022, 1, 1);
|
||||||
|
expect(jasmineUnderTest.util.cloneArgs([date])).toEqual([date]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clones null and undefined', function() {
|
||||||
|
expect(jasmineUnderTest.util.cloneArgs([null])).toEqual([null]);
|
||||||
|
expect(jasmineUnderTest.util.cloneArgs([undefined])).toEqual([undefined]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getPropertyDescriptor', function() {
|
describe('getPropertyDescriptor', function() {
|
||||||
it('get property descriptor from object', function() {
|
it('get property descriptor from object', function() {
|
||||||
var obj = { prop: 1 },
|
const obj = { prop: 1 },
|
||||||
actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
|
actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
|
||||||
expected = Object.getOwnPropertyDescriptor(obj, 'prop');
|
expected = Object.getOwnPropertyDescriptor(obj, 'prop');
|
||||||
|
|
||||||
@@ -149,7 +175,7 @@ describe('jasmineUnderTest.util', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get property descriptor from object property', function() {
|
it('get property descriptor from object property', function() {
|
||||||
var proto = { prop: 1 },
|
const proto = { prop: 1 },
|
||||||
actual = jasmineUnderTest.util.getPropertyDescriptor(proto, 'prop'),
|
actual = jasmineUnderTest.util.getPropertyDescriptor(proto, 'prop'),
|
||||||
expected = Object.getOwnPropertyDescriptor(proto, 'prop');
|
expected = Object.getOwnPropertyDescriptor(proto, 'prop');
|
||||||
|
|
||||||
@@ -157,42 +183,6 @@ describe('jasmineUnderTest.util', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('objectDifference', function() {
|
|
||||||
it('given two objects A and B, returns the properties in A not present in B', function() {
|
|
||||||
var a = {
|
|
||||||
foo: 3,
|
|
||||||
bar: 4,
|
|
||||||
baz: 5
|
|
||||||
};
|
|
||||||
|
|
||||||
var b = {
|
|
||||||
bar: 6,
|
|
||||||
quux: 7
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({
|
|
||||||
foo: 3,
|
|
||||||
baz: 5
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('only looks at own properties of both objects', function() {
|
|
||||||
function Foo() {}
|
|
||||||
|
|
||||||
Foo.prototype.x = 1;
|
|
||||||
Foo.prototype.y = 2;
|
|
||||||
|
|
||||||
var a = new Foo();
|
|
||||||
a.x = 1;
|
|
||||||
|
|
||||||
var b = new Foo();
|
|
||||||
b.y = 2;
|
|
||||||
|
|
||||||
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({ x: 1 });
|
|
||||||
expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual({ y: 2 });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('jasmineFile', function() {
|
describe('jasmineFile', function() {
|
||||||
it('returns the file containing jasmine.util', function() {
|
it('returns the file containing jasmine.util', function() {
|
||||||
// Chrome sometimes reports foo.js as foo.js/, so tolerate
|
// Chrome sometimes reports foo.js as foo.js/, so tolerate
|
||||||
|
|||||||
@@ -1,73 +1,73 @@
|
|||||||
describe('Any', function() {
|
describe('Any', function() {
|
||||||
it('matches a string', function() {
|
it('matches a string', function() {
|
||||||
var any = new jasmineUnderTest.Any(String);
|
const 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);
|
const any = new jasmineUnderTest.Any(Number);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(1)).toBe(true);
|
expect(any.asymmetricMatch(1)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a function', function() {
|
it('matches a function', function() {
|
||||||
var any = new jasmineUnderTest.Any(Function);
|
const 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);
|
const any = new jasmineUnderTest.Any(Object);
|
||||||
|
|
||||||
expect(any.asymmetricMatch({})).toBe(true);
|
expect(any.asymmetricMatch({})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a Boolean', function() {
|
it('matches a Boolean', function() {
|
||||||
var any = new jasmineUnderTest.Any(Boolean);
|
const any = new jasmineUnderTest.Any(Boolean);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(true)).toBe(true);
|
expect(any.asymmetricMatch(true)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a Map', function() {
|
it('matches a Map', function() {
|
||||||
var any = new jasmineUnderTest.Any(Map);
|
const any = new jasmineUnderTest.Any(Map);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Map())).toBe(true);
|
expect(any.asymmetricMatch(new Map())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a Set', function() {
|
it('matches a Set', function() {
|
||||||
var any = new jasmineUnderTest.Any(Set);
|
const any = new jasmineUnderTest.Any(Set);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Set())).toBe(true);
|
expect(any.asymmetricMatch(new Set())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a TypedArray', function() {
|
it('matches a TypedArray', function() {
|
||||||
var any = new jasmineUnderTest.Any(Uint32Array);
|
const any = new jasmineUnderTest.Any(Uint32Array);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a Symbol', function() {
|
it('matches a Symbol', function() {
|
||||||
var any = new jasmineUnderTest.Any(Symbol);
|
const any = new jasmineUnderTest.Any(Symbol);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(Symbol())).toBe(true);
|
expect(any.asymmetricMatch(Symbol())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches another constructed object', function() {
|
it('matches another constructed object', function() {
|
||||||
var Thing = function() {},
|
const Thing = function() {},
|
||||||
any = new jasmineUnderTest.Any(Thing);
|
any = new jasmineUnderTest.Any(Thing);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not treat null as an Object', function() {
|
it('does not treat null as an Object', function() {
|
||||||
var any = new jasmineUnderTest.Any(Object);
|
const any = new jasmineUnderTest.Any(Object);
|
||||||
|
|
||||||
expect(any.asymmetricMatch(null)).toBe(false);
|
expect(any.asymmetricMatch(null)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var any = new jasmineUnderTest.Any(Number);
|
const any = new jasmineUnderTest.Any(Number);
|
||||||
|
|
||||||
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
||||||
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
||||||
|
|||||||
@@ -1,67 +1,67 @@
|
|||||||
describe('Anything', function() {
|
describe('Anything', function() {
|
||||||
it('matches a string', function() {
|
it('matches a string', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch('foo')).toBe(true);
|
expect(anything.asymmetricMatch('foo')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a number', function() {
|
it('matches a number', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(42)).toBe(true);
|
expect(anything.asymmetricMatch(42)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches an object', function() {
|
it('matches an object', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches an array', function() {
|
it('matches an array', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const 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() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(new Map())).toBe(true);
|
expect(anything.asymmetricMatch(new Map())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a Set', function() {
|
it('matches a Set', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(new Set())).toBe(true);
|
expect(anything.asymmetricMatch(new Set())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a TypedArray', function() {
|
it('matches a TypedArray', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a Symbol', function() {
|
it('matches a Symbol', function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(Symbol())).toBe(true);
|
expect(anything.asymmetricMatch(Symbol())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't match undefined", function() {
|
it("doesn't match undefined", function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch()).toBe(false);
|
expect(anything.asymmetricMatch()).toBe(false);
|
||||||
expect(anything.asymmetricMatch(undefined)).toBe(false);
|
expect(anything.asymmetricMatch(undefined)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't match null", function() {
|
it("doesn't match null", function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.asymmetricMatch(null)).toBe(false);
|
expect(anything.asymmetricMatch(null)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var anything = new jasmineUnderTest.Anything();
|
const anything = new jasmineUnderTest.Anything();
|
||||||
|
|
||||||
expect(anything.jasmineToString()).toEqual('<jasmine.anything>');
|
expect(anything.jasmineToString()).toEqual('<jasmine.anything>');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
describe('ArrayContaining', function() {
|
describe('ArrayContaining', function() {
|
||||||
it('matches any actual to an empty array', function() {
|
it('matches any actual to an empty array', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining([]);
|
const containing = new jasmineUnderTest.ArrayContaining([]);
|
||||||
|
|
||||||
expect(containing.asymmetricMatch('foo')).toBe(true);
|
expect(containing.asymmetricMatch('foo')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not work when not passed an array', function() {
|
it('does not work when not passed an array', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining('foo');
|
const containing = new jasmineUnderTest.ArrayContaining('foo');
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
containing.asymmetricMatch([]);
|
containing.asymmetricMatch([]);
|
||||||
@@ -14,35 +14,35 @@ describe('ArrayContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches when the item is in the actual', function() {
|
it('matches when the item is in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(['foo'], matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(['foo'], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches when additional items are in the actual', function() {
|
it('matches when additional items are in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(['foo', 'bar'], matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(['foo', 'bar'], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when the item is not in the actual', function() {
|
it('does not match when the item is not in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(['bar'], matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(['bar'], matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when the actual is not an array', function() {
|
it('does not match when the actual is not an array', function() {
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch('foo', matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch('foo', matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('jasmineToStrings itself', function() {
|
it('jasmineToStrings itself', function() {
|
||||||
var sample = [],
|
const sample = [],
|
||||||
matcher = new jasmineUnderTest.ArrayContaining(sample),
|
matcher = new jasmineUnderTest.ArrayContaining(sample),
|
||||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
@@ -53,19 +53,19 @@ describe('ArrayContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('uses custom equality testers', function() {
|
it('uses custom equality testers', function() {
|
||||||
var tester = function(a, b) {
|
const tester = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (
|
if (
|
||||||
typeof a == 'string' &&
|
typeof a == 'string' &&
|
||||||
typeof b == 'string' &&
|
typeof b == 'string' &&
|
||||||
a.substr(0, 3) == 'foo' &&
|
a.slice(0, 3) == 'foo' &&
|
||||||
b.substr(0, 3) == 'foo'
|
b.slice(0, 3) == 'foo'
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var containing = new jasmineUnderTest.ArrayContaining(['fooVal']);
|
const containing = new jasmineUnderTest.ArrayContaining(['fooVal']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
customTesters: [tester]
|
customTesters: [tester]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
describe('ArrayWithExactContents', function() {
|
describe('ArrayWithExactContents', function() {
|
||||||
it('matches an array with the same items in a different order', function() {
|
it('matches an array with the same items in a different order', function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch([2, 'a', /a/], matchersUtil)).toBe(true);
|
expect(matcher.asymmetricMatch([2, 'a', /a/], matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not work when not passed an array', function() {
|
it('does not work when not passed an array', function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents('foo');
|
const matcher = new jasmineUnderTest.ArrayWithExactContents('foo');
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
matcher.asymmetricMatch([]);
|
matcher.asymmetricMatch([]);
|
||||||
@@ -15,8 +15,8 @@ describe('ArrayWithExactContents', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when an item is missing', function() {
|
it('does not match when an item is missing', function() {
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||||
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(
|
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(
|
||||||
@@ -25,14 +25,14 @@ describe('ArrayWithExactContents', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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']);
|
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('jasmineToStrings itself', function() {
|
it('jasmineToStrings itself', function() {
|
||||||
var sample = [],
|
const sample = [],
|
||||||
matcher = new jasmineUnderTest.ArrayWithExactContents(sample),
|
matcher = new jasmineUnderTest.ArrayWithExactContents(sample),
|
||||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
@@ -43,19 +43,19 @@ describe('ArrayWithExactContents', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('uses custom equality testers', function() {
|
it('uses custom equality testers', function() {
|
||||||
var tester = function(a, b) {
|
const tester = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (
|
if (
|
||||||
typeof a == 'string' &&
|
typeof a == 'string' &&
|
||||||
typeof b == 'string' &&
|
typeof b == 'string' &&
|
||||||
a.substr(0, 3) == 'foo' &&
|
a.slice(0, 3) == 'foo' &&
|
||||||
b.substr(0, 3) == 'foo'
|
b.slice(0, 3) == 'foo'
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['fooVal']);
|
const matcher = new jasmineUnderTest.ArrayWithExactContents(['fooVal']);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
customTesters: [tester]
|
customTesters: [tester]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
describe('Empty', function() {
|
describe('Empty', function() {
|
||||||
it('matches an empty object', function() {
|
it('matches an empty object', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
const empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch({})).toBe(true);
|
expect(empty.asymmetricMatch({})).toBe(true);
|
||||||
expect(empty.asymmetricMatch({ undefined: false })).toBe(false);
|
expect(empty.asymmetricMatch({ undefined: false })).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches an empty array', function() {
|
it('matches an empty array', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
const empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch([])).toBe(true);
|
expect(empty.asymmetricMatch([])).toBe(true);
|
||||||
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
|
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches an empty string', function() {
|
it('matches an empty string', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
const empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch('')).toBe(true);
|
expect(empty.asymmetricMatch('')).toBe(true);
|
||||||
expect(empty.asymmetricMatch('')).toBe(true);
|
expect(empty.asymmetricMatch('')).toBe(true);
|
||||||
@@ -22,8 +22,8 @@ describe('Empty', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches an empty map', function() {
|
it('matches an empty map', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
const empty = new jasmineUnderTest.Empty();
|
||||||
var fullMap = new Map();
|
const fullMap = new Map();
|
||||||
fullMap.set('thing', 2);
|
fullMap.set('thing', 2);
|
||||||
|
|
||||||
expect(empty.asymmetricMatch(new Map())).toBe(true);
|
expect(empty.asymmetricMatch(new Map())).toBe(true);
|
||||||
@@ -31,8 +31,8 @@ describe('Empty', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches an empty set', function() {
|
it('matches an empty set', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
const empty = new jasmineUnderTest.Empty();
|
||||||
var fullSet = new Set();
|
const fullSet = new Set();
|
||||||
fullSet.add(3);
|
fullSet.add(3);
|
||||||
|
|
||||||
expect(empty.asymmetricMatch(new Set())).toBe(true);
|
expect(empty.asymmetricMatch(new Set())).toBe(true);
|
||||||
@@ -40,7 +40,7 @@ describe('Empty', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches an empty typed array', function() {
|
it('matches an empty typed array', function() {
|
||||||
var empty = new jasmineUnderTest.Empty();
|
const empty = new jasmineUnderTest.Empty();
|
||||||
|
|
||||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
|
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
|
||||||
expect(empty.asymmetricMatch(new Int16Array([1, 2]))).toBe(false);
|
expect(empty.asymmetricMatch(new Int16Array([1, 2]))).toBe(false);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('Falsy', function() {
|
describe('Falsy', function() {
|
||||||
it('is true for an empty string', function() {
|
it('is true for an empty string', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy();
|
const falsy = new jasmineUnderTest.Falsy();
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||||
@@ -8,7 +8,7 @@ describe('Falsy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('is false for a number that is 0', function() {
|
it('is false for a number that is 0', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Number);
|
const falsy = new jasmineUnderTest.Falsy(Number);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(1)).toBe(false);
|
expect(falsy.asymmetricMatch(1)).toBe(false);
|
||||||
expect(falsy.asymmetricMatch(0)).toBe(true);
|
expect(falsy.asymmetricMatch(0)).toBe(true);
|
||||||
@@ -17,20 +17,20 @@ describe('Falsy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('is true for a null or undefined', function() {
|
it('is true for a null or undefined', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Function);
|
const falsy = new jasmineUnderTest.Falsy(Function);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(null)).toBe(true);
|
expect(falsy.asymmetricMatch(null)).toBe(true);
|
||||||
expect(falsy.asymmetricMatch(undefined)).toBe(true);
|
expect(falsy.asymmetricMatch(undefined)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for NaN', function() {
|
it('is true for NaN', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Object);
|
const falsy = new jasmineUnderTest.Falsy(Object);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(NaN)).toBe(true);
|
expect(falsy.asymmetricMatch(NaN)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for a false Boolean', function() {
|
it('is true for a false Boolean', function() {
|
||||||
var falsy = new jasmineUnderTest.Falsy(Boolean);
|
const falsy = new jasmineUnderTest.Falsy(Boolean);
|
||||||
|
|
||||||
expect(falsy.asymmetricMatch(false)).toBe(true);
|
expect(falsy.asymmetricMatch(false)).toBe(true);
|
||||||
expect(falsy.asymmetricMatch(true)).toBe(false);
|
expect(falsy.asymmetricMatch(true)).toBe(false);
|
||||||
|
|||||||
30
spec/core/asymmetric_equality/IsSpec.js
Normal file
30
spec/core/asymmetric_equality/IsSpec.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
describe('Is', function() {
|
||||||
|
it('passes for primitives that are ===', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is(17);
|
||||||
|
expect(exactly.asymmetricMatch(17)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for primitives that are not ===', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is(42);
|
||||||
|
expect(exactly.asymmetricMatch('42')).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for the same object instance', function() {
|
||||||
|
const obj = {};
|
||||||
|
const exactly = new jasmineUnderTest.Is(obj);
|
||||||
|
expect(exactly.asymmetricMatch(obj)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for different object instances, even if they are deep value equal', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is({});
|
||||||
|
expect(exactly.asymmetricMatch({})).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('describes itself for use in diffs and pretty printing', function() {
|
||||||
|
const exactly = new jasmineUnderTest.Is({ foo: ['bar'] });
|
||||||
|
const pp = jasmineUnderTest.basicPrettyPrinter_;
|
||||||
|
expect(exactly.jasmineToString(pp)).toEqual(
|
||||||
|
"<jasmine.is(Object({ foo: [ 'bar' ] }))>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,104 +1,110 @@
|
|||||||
describe('MapContaining', function() {
|
describe('MapContaining', function() {
|
||||||
it('matches any actual map to an empty map', function() {
|
it('matches any actual map to an empty map', function() {
|
||||||
var actualMap = new Map([['foo', 'bar']]);
|
const actualMap = new Map([['foo', 'bar']]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(new Map());
|
const containing = new jasmineUnderTest.MapContaining(new Map());
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches when all the key/value pairs in sample have matches in actual', function() {
|
it('matches when all the key/value pairs in sample have matches in actual', function() {
|
||||||
var actualMap = new Map([
|
const actualMap = new Map([
|
||||||
['foo', [1, 2, 3]],
|
['foo', [1, 2, 3]],
|
||||||
[{ foo: 'bar' }, 'baz'],
|
[{ foo: 'bar' }, 'baz'],
|
||||||
['other', 'any']
|
['other', 'any']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
|
const containingMap = new Map([
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
[{ foo: 'bar' }, 'baz'],
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
['foo', [1, 2, 3]]
|
||||||
|
]);
|
||||||
|
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a key is not in actual', function() {
|
it('does not match when a key is not in actual', function() {
|
||||||
var actualMap = new Map([
|
const actualMap = new Map([
|
||||||
['foo', [1, 2, 3]],
|
['foo', [1, 2, 3]],
|
||||||
[{ foo: 'not a bar' }, 'baz']
|
[{ foo: 'not a bar' }, 'baz']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2, 3]]]);
|
const containingMap = new Map([
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
[{ foo: 'bar' }, 'baz'],
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
['foo', [1, 2, 3]]
|
||||||
|
]);
|
||||||
|
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value is not in actual', function() {
|
it('does not match when a value is not in actual', function() {
|
||||||
var actualMap = new Map([['foo', [1, 2, 3]], [{ foo: 'bar' }, 'baz']]);
|
const actualMap = new Map([['foo', [1, 2, 3]], [{ foo: 'bar' }, 'baz']]);
|
||||||
|
|
||||||
var containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2]]]);
|
const containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2]]]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches when all the key/value pairs in sample have asymmetric matches in actual', function() {
|
it('matches when all the key/value pairs in sample have asymmetric matches in actual', function() {
|
||||||
var actualMap = new Map([
|
const actualMap = new Map([
|
||||||
['foo1', 'not a bar'],
|
['foo1', 'not a bar'],
|
||||||
['foo2', 'bar'],
|
['foo2', 'bar'],
|
||||||
['baz', [1, 2, 3, 4]]
|
['baz', [1, 2, 3, 4]]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new Map([
|
const containingMap = new Map([
|
||||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||||
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a key in sample has no asymmetric matches in actual', function() {
|
it('does not match when a key in sample has no asymmetric matches in actual', function() {
|
||||||
var actualMap = new Map([['a-foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
const actualMap = new Map([['a-foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||||
|
|
||||||
var containingMap = new Map([
|
const containingMap = new Map([
|
||||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||||
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
||||||
var actualMap = new Map([['foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
const actualMap = new Map([['foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||||
|
|
||||||
var containingMap = new Map([
|
const containingMap = new Map([
|
||||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||||
['baz', jasmineUnderTest.arrayContaining([4, 5])]
|
['baz', jasmineUnderTest.arrayContaining([4, 5])]
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches recursively', function() {
|
it('matches recursively', function() {
|
||||||
var actualMap = new Map([
|
const actualMap = new Map([
|
||||||
['foo', new Map([['foo1', 1], ['foo2', 2]])],
|
['foo', new Map([['foo1', 1], ['foo2', 2]])],
|
||||||
[new Map([[1, 'bar1'], [2, 'bar2']]), 'bar'],
|
[new Map([[1, 'bar1'], [2, 'bar2']]), 'bar'],
|
||||||
['other', 'any']
|
['other', 'any']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var containingMap = new Map([
|
const containingMap = new Map([
|
||||||
['foo', new jasmineUnderTest.MapContaining(new Map([['foo1', 1]]))],
|
['foo', new jasmineUnderTest.MapContaining(new Map([['foo1', 1]]))],
|
||||||
[new jasmineUnderTest.MapContaining(new Map([[2, 'bar2']])), 'bar']
|
[new jasmineUnderTest.MapContaining(new Map([[2, 'bar2']])), 'bar']
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -110,9 +116,11 @@ describe('MapContaining', function() {
|
|||||||
? a < 0 && b < 0
|
? a < 0 && b < 0
|
||||||
: a === b;
|
: a === b;
|
||||||
}
|
}
|
||||||
var actualMap = new Map([['foo', -1]]);
|
const actualMap = new Map([['foo', -1]]);
|
||||||
var containing = new jasmineUnderTest.MapContaining(new Map([['foo', -2]]));
|
const containing = new jasmineUnderTest.MapContaining(
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
new Map([['foo', -2]])
|
||||||
|
);
|
||||||
|
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
customTesters: [tester]
|
customTesters: [tester]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -120,7 +128,7 @@ describe('MapContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when actual is not a map', function() {
|
it('does not match when actual is not a map', function() {
|
||||||
var containingMap = new Map([['foo', 'bar']]);
|
const containingMap = new Map([['foo', 'bar']]);
|
||||||
expect(
|
expect(
|
||||||
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')
|
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
@@ -143,7 +151,7 @@ describe('MapContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('defines a `jasmineToString` method', function() {
|
it('defines a `jasmineToString` method', function() {
|
||||||
var sample = new Map(),
|
const sample = new Map(),
|
||||||
containing = new jasmineUnderTest.MapContaining(sample),
|
containing = new jasmineUnderTest.MapContaining(sample),
|
||||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
describe('NotEmpty', function() {
|
describe('NotEmpty', function() {
|
||||||
it('matches a non empty object', function() {
|
it('matches a non empty object', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch({ undefined: false })).toBe(true);
|
expect(notEmpty.asymmetricMatch({ undefined: false })).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch({})).toBe(false);
|
expect(notEmpty.asymmetricMatch({})).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a non empty array', function() {
|
it('matches a non empty array', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
|
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch([])).toBe(false);
|
expect(notEmpty.asymmetricMatch([])).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a non empty string', function() {
|
it('matches a non empty string', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
|
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||||
@@ -22,27 +22,27 @@ describe('NotEmpty', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches a non empty map', function() {
|
it('matches a non empty map', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
var fullMap = new Map();
|
const fullMap = new Map();
|
||||||
fullMap.set('one', 1);
|
fullMap.set('one', 1);
|
||||||
var emptyMap = new Map();
|
const emptyMap = new Map();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
|
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a non empty set', function() {
|
it('matches a non empty set', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
var filledSet = new Set();
|
const filledSet = new Set();
|
||||||
filledSet.add(1);
|
filledSet.add(1);
|
||||||
var emptySet = new Set();
|
const emptySet = new Set();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
|
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
|
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a non empty typed array', function() {
|
it('matches a non empty typed array', function() {
|
||||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||||
|
|
||||||
expect(notEmpty.asymmetricMatch(new Int16Array([1, 2, 3]))).toBe(true);
|
expect(notEmpty.asymmetricMatch(new Int16Array([1, 2, 3]))).toBe(true);
|
||||||
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false);
|
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
describe('ObjectContaining', function() {
|
describe('ObjectContaining', function() {
|
||||||
it('matches any object actual to an empty object', function() {
|
it('matches any object actual to an empty object', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
const containing = new jasmineUnderTest.ObjectContaining({});
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({ foo: 1 }, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch({ foo: 1 }, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when the actual is not an object', function() {
|
it('does not match when the actual is not an object', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
const containing = new jasmineUnderTest.ObjectContaining({});
|
||||||
|
|
||||||
[1, true, undefined, 'a string'].forEach(function(actual) {
|
[1, true, undefined, 'a string'].forEach(function(actual) {
|
||||||
expect(containing.asymmetricMatch(actual)).toBe(false);
|
expect(containing.asymmetricMatch(actual)).toBe(false);
|
||||||
@@ -15,7 +15,7 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match an empty object actual', function() {
|
it('does not match an empty object actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining('foo');
|
const containing = new jasmineUnderTest.ObjectContaining('foo');
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
containing.asymmetricMatch({});
|
containing.asymmetricMatch({});
|
||||||
@@ -23,8 +23,8 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches when the key/value pair is present in the actual', function() {
|
it('matches when the key/value pair is present in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
||||||
@@ -32,8 +32,8 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when the key/value pair is not present in the actual', function() {
|
it('does not match when the key/value pair is not present in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
containing.asymmetricMatch(
|
containing.asymmetricMatch(
|
||||||
@@ -44,8 +44,8 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when the key is present but the value is different in the actual', function() {
|
it('does not match when the key is present but the value is different in the actual', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'other' });
|
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'other' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
||||||
@@ -53,7 +53,7 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var sample = {},
|
const sample = {},
|
||||||
matcher = new jasmineUnderTest.ObjectContaining(sample),
|
matcher = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
@@ -64,10 +64,10 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches recursively', function() {
|
it('matches recursively', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({
|
const containing = new jasmineUnderTest.ObjectContaining({
|
||||||
one: new jasmineUnderTest.ObjectContaining({ two: {} })
|
one: new jasmineUnderTest.ObjectContaining({ two: {} })
|
||||||
});
|
});
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({ one: { two: {} } }, matchersUtil)).toBe(
|
expect(containing.asymmetricMatch({ one: { two: {} } }, matchersUtil)).toBe(
|
||||||
true
|
true
|
||||||
@@ -75,8 +75,10 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 });
|
const containing = new jasmineUnderTest.ObjectContaining({
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
one: undefined
|
||||||
|
});
|
||||||
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({ one: undefined }, matchersUtil)).toBe(
|
expect(containing.asymmetricMatch({ one: undefined }, matchersUtil)).toBe(
|
||||||
true
|
true
|
||||||
@@ -84,17 +86,19 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 });
|
const containing = new jasmineUnderTest.ObjectContaining({
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
one: undefined
|
||||||
|
});
|
||||||
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch({}, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch({}, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches defined properties', function() {
|
it('matches defined properties', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
var definedPropertyObject = {};
|
const definedPropertyObject = {};
|
||||||
Object.defineProperty(definedPropertyObject, 'foo', {
|
Object.defineProperty(definedPropertyObject, 'foo', {
|
||||||
get: function() {
|
get: function() {
|
||||||
return 'fooVal';
|
return 'fooVal';
|
||||||
@@ -106,29 +110,29 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches prototype properties', function() {
|
it('matches prototype properties', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
var prototypeObject = { foo: 'fooVal' };
|
const prototypeObject = { foo: 'fooVal' };
|
||||||
var obj = Object.create(prototypeObject);
|
const obj = Object.create(prototypeObject);
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(obj, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(obj, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses custom equality testers', function() {
|
it('uses custom equality testers', function() {
|
||||||
var tester = function(a, b) {
|
const tester = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (
|
if (
|
||||||
typeof a == 'string' &&
|
typeof a == 'string' &&
|
||||||
typeof b == 'string' &&
|
typeof b == 'string' &&
|
||||||
a.substr(0, 3) == 'foo' &&
|
a.slice(0, 3) == 'foo' &&
|
||||||
b.substr(0, 3) == 'foo'
|
b.slice(0, 3) == 'foo'
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
customTesters: [tester]
|
customTesters: [tester]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -140,7 +144,7 @@ describe('ObjectContaining', function() {
|
|||||||
describe('valuesForDiff_', function() {
|
describe('valuesForDiff_', function() {
|
||||||
describe('when other is not an object', function() {
|
describe('when other is not an object', function() {
|
||||||
it('sets self to jasmineToString()', function() {
|
it('sets self to jasmineToString()', function() {
|
||||||
var containing = new jasmineUnderTest.ObjectContaining({}),
|
const containing = new jasmineUnderTest.ObjectContaining({}),
|
||||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||||
result = containing.valuesForDiff_('a', pp);
|
result = containing.valuesForDiff_('a', pp);
|
||||||
|
|
||||||
@@ -153,7 +157,7 @@ describe('ObjectContaining', function() {
|
|||||||
|
|
||||||
describe('when other is an object', function() {
|
describe('when other is an object', function() {
|
||||||
it('includes keys that are present in both other and sample', function() {
|
it('includes keys that are present in both other and sample', function() {
|
||||||
var sample = { a: 1, b: 2 },
|
const sample = { a: 1, b: 2 },
|
||||||
other = { a: 3, b: 4 },
|
other = { a: 3, b: 4 },
|
||||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
result = containing.valuesForDiff_(other);
|
result = containing.valuesForDiff_(other);
|
||||||
@@ -168,7 +172,7 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('includes keys that are present only in sample', function() {
|
it('includes keys that are present only in sample', function() {
|
||||||
var sample = { a: 1, b: 2 },
|
const sample = { a: 1, b: 2 },
|
||||||
other = { a: 3 },
|
other = { a: 3 },
|
||||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
result = containing.valuesForDiff_(other);
|
result = containing.valuesForDiff_(other);
|
||||||
@@ -186,7 +190,7 @@ describe('ObjectContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('omits keys that are present only in other', function() {
|
it('omits keys that are present only in other', function() {
|
||||||
var sample = { a: 1, b: 2 },
|
const sample = { a: 1, b: 2 },
|
||||||
other = { a: 3, b: 4, c: 5 },
|
other = { a: 3, b: 4, c: 5 },
|
||||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||||
result = containing.valuesForDiff_(other);
|
result = containing.valuesForDiff_(other);
|
||||||
|
|||||||
@@ -1,66 +1,66 @@
|
|||||||
describe('SetContaining', function() {
|
describe('SetContaining', function() {
|
||||||
it('matches any actual set to an empty set', function() {
|
it('matches any actual set to an empty set', function() {
|
||||||
var actualSet = new Set(['foo', 'bar']);
|
const actualSet = new Set(['foo', 'bar']);
|
||||||
var containing = new jasmineUnderTest.SetContaining(new Set());
|
const containing = new jasmineUnderTest.SetContaining(new Set());
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches when all the values in sample have matches in actual', function() {
|
it('matches when all the values in sample have matches in actual', function() {
|
||||||
var actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
const actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||||
|
|
||||||
var containingSet = new Set([[1, 2, 3], { foo: 'bar' }]);
|
const containingSet = new Set([[1, 2, 3], { foo: 'bar' }]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value is not in actual', function() {
|
it('does not match when a value is not in actual', function() {
|
||||||
var actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
const actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||||
|
|
||||||
var containingSet = new Set([[1, 2], { foo: 'bar' }]);
|
const containingSet = new Set([[1, 2], { foo: 'bar' }]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches when all the values in sample have asymmetric matches in actual', function() {
|
it('matches when all the values in sample have asymmetric matches in actual', function() {
|
||||||
var actualSet = new Set([[1, 2, 3, 4], 'other', 'foo1']);
|
const actualSet = new Set([[1, 2, 3, 4], 'other', 'foo1']);
|
||||||
|
|
||||||
var containingSet = new Set([
|
const containingSet = new Set([
|
||||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||||
jasmineUnderTest.arrayContaining([2, 3])
|
jasmineUnderTest.arrayContaining([2, 3])
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
||||||
var actualSet = new Set(['a-foo1', [1, 2, 3, 4], 'other']);
|
const actualSet = new Set(['a-foo1', [1, 2, 3, 4], 'other']);
|
||||||
|
|
||||||
var containingSet = new Set([
|
const containingSet = new Set([
|
||||||
jasmine.stringMatching(/^foo\d/),
|
jasmine.stringMatching(/^foo\d/),
|
||||||
jasmine.arrayContaining([2, 3])
|
jasmine.arrayContaining([2, 3])
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches recursively', function() {
|
it('matches recursively', function() {
|
||||||
var actualSet = new Set(['foo', new Set([1, 'bar', 2]), 'other']);
|
const actualSet = new Set(['foo', new Set([1, 'bar', 2]), 'other']);
|
||||||
|
|
||||||
var containingSet = new Set([
|
const containingSet = new Set([
|
||||||
new jasmineUnderTest.SetContaining(new Set(['bar'])),
|
new jasmineUnderTest.SetContaining(new Set(['bar'])),
|
||||||
'foo'
|
'foo'
|
||||||
]);
|
]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -72,9 +72,9 @@ describe('SetContaining', function() {
|
|||||||
? a < 0 && b < 0
|
? a < 0 && b < 0
|
||||||
: a === b;
|
: a === b;
|
||||||
}
|
}
|
||||||
var actualSet = new Set(['foo', -1]);
|
const actualSet = new Set(['foo', -1]);
|
||||||
var containing = new jasmineUnderTest.SetContaining(new Set([-2, 'foo']));
|
const containing = new jasmineUnderTest.SetContaining(new Set([-2, 'foo']));
|
||||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||||
customTesters: [tester]
|
customTesters: [tester]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not match when actual is not a set', function() {
|
it('does not match when actual is not a set', function() {
|
||||||
var containingSet = new Set(['foo']);
|
const containingSet = new Set(['foo']);
|
||||||
expect(
|
expect(
|
||||||
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')
|
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
@@ -103,7 +103,7 @@ describe('SetContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('defines a `jasmineToString` method', function() {
|
it('defines a `jasmineToString` method', function() {
|
||||||
var sample = new Set(),
|
const sample = new Set(),
|
||||||
containing = new jasmineUnderTest.SetContaining(sample),
|
containing = new jasmineUnderTest.SetContaining(sample),
|
||||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('StringContaining', function() {
|
describe('StringContaining', function() {
|
||||||
it('searches for a provided substring when the expected is a String', function() {
|
it('searches for a provided substring when the expected is a String', function() {
|
||||||
var matcher = new jasmineUnderTest.StringContaining('foo');
|
const matcher = new jasmineUnderTest.StringContaining('foo');
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||||
@@ -13,12 +13,12 @@ describe('StringContaining', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('fails when the actual is not a String', function() {
|
it('fails when the actual is not a String', function() {
|
||||||
var matcher = new jasmineUnderTest.StringContaining('x');
|
const matcher = new jasmineUnderTest.StringContaining('x');
|
||||||
expect(matcher.asymmetricMatch(['x'])).toBe(false);
|
expect(matcher.asymmetricMatch(['x'])).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var matching = new jasmineUnderTest.StringContaining('foo');
|
const matching = new jasmineUnderTest.StringContaining('foo');
|
||||||
|
|
||||||
expect(matching.jasmineToString()).toEqual(
|
expect(matching.jasmineToString()).toEqual(
|
||||||
'<jasmine.stringContaining("foo")>'
|
'<jasmine.stringContaining("foo")>'
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
describe('StringMatching', function() {
|
describe('StringMatching', function() {
|
||||||
it('matches a string against a provided regexp', function() {
|
it('matches a string against a provided regexp', function() {
|
||||||
var matcher = new jasmineUnderTest.StringMatching(/foo/);
|
const matcher = new jasmineUnderTest.StringMatching(/foo/);
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches a string against provided string', function() {
|
it('matches a string against provided string', function() {
|
||||||
var matcher = new jasmineUnderTest.StringMatching('foo');
|
const matcher = new jasmineUnderTest.StringMatching('foo');
|
||||||
|
|
||||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||||
@@ -20,7 +20,7 @@ describe('StringMatching', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("jasmineToString's itself", function() {
|
it("jasmineToString's itself", function() {
|
||||||
var matching = new jasmineUnderTest.StringMatching(/^foo/);
|
const matching = new jasmineUnderTest.StringMatching(/^foo/);
|
||||||
|
|
||||||
expect(matching.jasmineToString()).toEqual(
|
expect(matching.jasmineToString()).toEqual(
|
||||||
'<jasmine.stringMatching(/^foo/)>'
|
'<jasmine.stringMatching(/^foo/)>'
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
describe('Truthy', function() {
|
describe('Truthy', function() {
|
||||||
it('is true for a non empty string', function() {
|
it('is true for a non empty string', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch('foo')).toBe(true);
|
expect(truthy.asymmetricMatch('foo')).toBe(true);
|
||||||
expect(truthy.asymmetricMatch('')).toBe(false);
|
expect(truthy.asymmetricMatch('')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for a number that is not 0', function() {
|
it('is true for a number that is not 0', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(1)).toBe(true);
|
expect(truthy.asymmetricMatch(1)).toBe(true);
|
||||||
expect(truthy.asymmetricMatch(0)).toBe(false);
|
expect(truthy.asymmetricMatch(0)).toBe(false);
|
||||||
@@ -16,44 +16,44 @@ describe('Truthy', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('is true for a function', function() {
|
it('is true for a function', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const 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();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for a truthful Boolean', function() {
|
it('is true for a truthful Boolean', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(true)).toBe(true);
|
expect(truthy.asymmetricMatch(true)).toBe(true);
|
||||||
expect(truthy.asymmetricMatch(false)).toBe(false);
|
expect(truthy.asymmetricMatch(false)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for an empty object', function() {
|
it('is true for an empty object', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch({})).toBe(true);
|
expect(truthy.asymmetricMatch({})).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for an empty array', function() {
|
it('is true for an empty array', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch([])).toBe(true);
|
expect(truthy.asymmetricMatch([])).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for a date', function() {
|
it('is true for a date', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(new Date())).toBe(true);
|
expect(truthy.asymmetricMatch(new Date())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is true for a infiniti', function() {
|
it('is true for a infiniti', function() {
|
||||||
var truthy = new jasmineUnderTest.Truthy();
|
const truthy = new jasmineUnderTest.Truthy();
|
||||||
|
|
||||||
expect(truthy.asymmetricMatch(Infinity)).toBe(true);
|
expect(truthy.asymmetricMatch(Infinity)).toBe(true);
|
||||||
expect(truthy.asymmetricMatch(-Infinity)).toBe(true);
|
expect(truthy.asymmetricMatch(-Infinity)).toBe(true);
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ describe('base helpers', function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj = (function() {
|
const obj = (function() {
|
||||||
var sock = new WebSocket('ws://localhost');
|
const sock = new WebSocket('ws://localhost');
|
||||||
var event;
|
let event;
|
||||||
sock.onerror = function(e) {
|
sock.onerror = function(e) {
|
||||||
event = e;
|
event = e;
|
||||||
};
|
};
|
||||||
@@ -16,11 +16,11 @@ describe('base helpers', function() {
|
|||||||
return event;
|
return event;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
var left = 20;
|
let left = 20;
|
||||||
|
|
||||||
var int = setInterval(function() {
|
const int = setInterval(function() {
|
||||||
if (obj() || left === 0) {
|
if (obj() || left === 0) {
|
||||||
var result = jasmineUnderTest.isError_(obj());
|
const result = jasmineUnderTest.isError_(obj());
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
clearInterval(int);
|
clearInterval(int);
|
||||||
done();
|
done();
|
||||||
@@ -41,18 +41,16 @@ describe('base helpers', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns true for an Error that originated from another frame', function() {
|
it('returns true for an Error that originated from another frame', function() {
|
||||||
var iframe, error;
|
|
||||||
|
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
pending('This test only runs in browsers.');
|
pending('This test only runs in browsers.');
|
||||||
}
|
}
|
||||||
|
|
||||||
iframe = document.createElement('iframe');
|
const iframe = document.createElement('iframe');
|
||||||
iframe.style.display = 'none';
|
iframe.style.display = 'none';
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
error = iframe.contentWindow.eval('new Error()');
|
const error = iframe.contentWindow.eval('new Error()');
|
||||||
expect(jasmineUnderTest.isError_(error)).toBe(true);
|
expect(jasmineUnderTest.isError_(error)).toBe(true);
|
||||||
} finally {
|
} finally {
|
||||||
document.body.removeChild(iframe);
|
document.body.removeChild(iframe);
|
||||||
@@ -74,17 +72,17 @@ describe('base helpers', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns false when the argument does not have a asymmetricMatch property', function() {
|
it('returns false when the argument does not have a asymmetricMatch property', function() {
|
||||||
var obj = {};
|
const obj = {};
|
||||||
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns false when the argument's asymmetricMatch is not a function", function() {
|
it("returns false when the argument's asymmetricMatch is not a function", function() {
|
||||||
var obj = { asymmetricMatch: 'yes' };
|
const obj = { asymmetricMatch: 'yes' };
|
||||||
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns true when the argument's asymmetricMatch is a function", function() {
|
it("returns true when the argument's asymmetricMatch is a function", function() {
|
||||||
var obj = { asymmetricMatch: function() {} };
|
const obj = { asymmetricMatch: function() {} };
|
||||||
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(true);
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -133,21 +131,21 @@ describe('base helpers', function() {
|
|||||||
|
|
||||||
describe('isPending_', function() {
|
describe('isPending_', function() {
|
||||||
it('returns a promise that resolves to true when the promise is pending', function() {
|
it('returns a promise that resolves to true when the promise is pending', function() {
|
||||||
var promise = new Promise(function() {});
|
const promise = new Promise(function() {});
|
||||||
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a promise that resolves to false when the promise is resolved', function() {
|
it('returns a promise that resolves to false when the promise is resolved', function() {
|
||||||
var promise = Promise.resolve();
|
const promise = Promise.resolve();
|
||||||
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a promise that resolves to false when the promise is rejected', function() {
|
it('returns a promise that resolves to false when the promise is rejected', function() {
|
||||||
var promise = Promise.reject();
|
const promise = Promise.reject(new Error('nope'));
|
||||||
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
return expectAsync(jasmineUnderTest.isPending_(promise)).toBeResolvedTo(
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@@ -155,7 +153,7 @@ describe('base helpers', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('DEFAULT_TIMEOUT_INTERVAL setter', function() {
|
describe('DEFAULT_TIMEOUT_INTERVAL setter', function() {
|
||||||
var max = 2147483647;
|
const max = 2147483647;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.initialValue = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;
|
this.initialValue = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
@@ -177,14 +175,13 @@ describe('base helpers', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('is consistent with setTimeout in this environment', function(done) {
|
it('is consistent with setTimeout in this environment', function(done) {
|
||||||
var f1 = jasmine.createSpy('setTimeout callback for ' + max),
|
const f1 = jasmine.createSpy('setTimeout callback for ' + max),
|
||||||
f2 = jasmine.createSpy('setTimeout callback for ' + (max + 1)),
|
f2 = jasmine.createSpy('setTimeout callback for ' + (max + 1));
|
||||||
id;
|
|
||||||
|
|
||||||
// Suppress printing of TimeoutOverflowWarning in node
|
// Suppress printing of TimeoutOverflowWarning in node
|
||||||
spyOn(console, 'error');
|
spyOn(console, 'error');
|
||||||
|
|
||||||
id = setTimeout(f1, max);
|
let id = setTimeout(f1, max);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
clearTimeout(id);
|
clearTimeout(id);
|
||||||
expect(f1).not.toHaveBeenCalled();
|
expect(f1).not.toHaveBeenCalled();
|
||||||
|
|||||||
112
spec/core/buildExpectationResultSpec.js
Normal file
112
spec/core/buildExpectationResultSpec.js
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
describe('buildExpectationResult', function() {
|
||||||
|
it('defaults to passed', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: 'some-value'
|
||||||
|
});
|
||||||
|
expect(result.passed).toBe('some-value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('message defaults to Passed for passing specs', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: true,
|
||||||
|
message: 'some-value'
|
||||||
|
});
|
||||||
|
expect(result.message).toBe('Passed.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('message returns the message for failing expectations', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: false,
|
||||||
|
message: 'some-value'
|
||||||
|
});
|
||||||
|
expect(result.message).toBe('some-value');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When the error property is provided', function() {
|
||||||
|
it('sets the message to the formatted error', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: false,
|
||||||
|
error: { message: 'foo', fileName: 'somefile.js' }
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.message).toEqual('foo in somefile.js');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('delegates stack formatting to the provided formatter', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: false,
|
||||||
|
error: { stack: 'foo', extra: 'wombat' }
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.stack).toEqual(
|
||||||
|
"error properties: Object({ extra: 'wombat' })\nfoo"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When the errorForStack property is provided', function() {
|
||||||
|
it('builds the stack trace using errorForStack instead of Error', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
passed: false,
|
||||||
|
errorForStack: { stack: 'foo' },
|
||||||
|
error: { stack: 'bar' }
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.stack).toEqual('bar');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('matcherName returns passed matcherName', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
matcherName: 'some-value'
|
||||||
|
});
|
||||||
|
expect(result.matcherName).toBe('some-value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('expected returns passed expected', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
expected: 'some-value'
|
||||||
|
});
|
||||||
|
expect(result.expected).toBe('some-value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('actual returns passed actual', function() {
|
||||||
|
const result = jasmineUnderTest.buildExpectationResult({
|
||||||
|
actual: 'some-value'
|
||||||
|
});
|
||||||
|
expect(result.actual).toBe('some-value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles nodejs assertions', function() {
|
||||||
|
if (typeof require === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const assert = require('assert');
|
||||||
|
const value = 8421;
|
||||||
|
const expectedValue = 'JasmineExpectationTestValue';
|
||||||
|
let error;
|
||||||
|
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('==');
|
||||||
|
|
||||||
|
const 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 ==');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
describe('formatErrorMsg', function() {
|
describe('formatErrorMsg', function() {
|
||||||
it('should format an error with a domain', function() {
|
it('should format an error with a domain', function() {
|
||||||
var formator = jasmineUnderTest.formatErrorMsg('api');
|
const formator = jasmineUnderTest.formatErrorMsg('api');
|
||||||
expect(formator('message')).toBe('api : message');
|
expect(formator('message')).toBe('api : message');
|
||||||
expect(formator('message2')).toBe('api : message2');
|
expect(formator('message2')).toBe('api : message2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format an error with a domain and usage', function() {
|
it('should format an error with a domain and usage', function() {
|
||||||
var formator = jasmineUnderTest.formatErrorMsg('api', 'with a param');
|
const formator = jasmineUnderTest.formatErrorMsg('api', 'with a param');
|
||||||
expect(formator('message')).toBe('api : message\nUsage: with a param');
|
expect(formator('message')).toBe('api : message\nUsage: with a param');
|
||||||
expect(formator('message2')).toBe('api : message2\nUsage: with a param');
|
expect(formator('message2')).toBe('api : message2\nUsage: with a param');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,55 +1,57 @@
|
|||||||
describe('Asymmetric equality testers (Integration)', function() {
|
describe('Asymmetric equality testers (Integration)', function() {
|
||||||
function verifyPasses(expectations, setup) {
|
function verifyPasses(expectations) {
|
||||||
it('passes', function(done) {
|
it('passes', async function() {
|
||||||
var env = new jasmineUnderTest.Env();
|
const env = new jasmineUnderTest.Env();
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
expect(result.passedExpectations.length)
|
await env.execute();
|
||||||
.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 });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
|
||||||
|
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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFails(expectations) {
|
function verifyFails(expectations) {
|
||||||
it('fails', function(done) {
|
it('fails', async function() {
|
||||||
var env = new jasmineUnderTest.Env();
|
const env = new jasmineUnderTest.Env();
|
||||||
env.it('a spec', function() {
|
env.it('a spec', function() {
|
||||||
expectations(env);
|
expectations(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations.length)
|
await env.execute();
|
||||||
.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 });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
|
||||||
|
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('');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,9 +125,9 @@ describe('Asymmetric equality testers (Integration)', function() {
|
|||||||
|
|
||||||
describe('mapContaining', function() {
|
describe('mapContaining', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
var actual = new Map();
|
const actual = new Map();
|
||||||
actual.set('a', '2');
|
actual.set('a', '2');
|
||||||
var expected = new Map();
|
const expected = new Map();
|
||||||
expected.set('a', 2);
|
expected.set('a', 2);
|
||||||
|
|
||||||
env.addCustomEqualityTester(function(a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
@@ -170,9 +172,9 @@ describe('Asymmetric equality testers (Integration)', function() {
|
|||||||
|
|
||||||
describe('setContaining', function() {
|
describe('setContaining', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
var actual = new Set();
|
const actual = new Set();
|
||||||
actual.add('1');
|
actual.add('1');
|
||||||
var expected = new Set();
|
const expected = new Set();
|
||||||
actual.add(1);
|
actual.add(1);
|
||||||
|
|
||||||
env.addCustomEqualityTester(function(a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
describe('Custom Async Matchers (Integration)', function() {
|
describe('Custom Async Matchers (Integration)', function() {
|
||||||
var env;
|
let env;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
@@ -10,7 +10,7 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the spec if the custom async matcher passes', function(done) {
|
it('passes the spec if the custom async matcher passes', async function() {
|
||||||
env.it('spec using custom async matcher', function() {
|
env.it('spec using custom async matcher', function() {
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -25,15 +25,15 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
return env.expectAsync(true).toBeReal();
|
return env.expectAsync(true).toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
it('uses the negative compare function for a negative comparison, if provided', async function() {
|
||||||
env.it('spec with custom negative comparison matcher', function() {
|
env.it('spec with custom negative comparison matcher', function() {
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -51,15 +51,15 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
return env.expectAsync(true).not.toBeReal();
|
return env.expectAsync(true).not.toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const specExpectations = function(result) {
|
||||||
expect(result.status).toEqual('passed');
|
expect(result.status).toEqual('passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
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', async function() {
|
||||||
env.it('spec with an expectation', function() {
|
env.it('spec with an expectation', function() {
|
||||||
env.addAsyncMatchers({
|
env.addAsyncMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -74,18 +74,18 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
return env.expectAsync('a').toBeReal();
|
return env.expectAsync('a').toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const specExpectations = function(result) {
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
"Expected 'a' to be real."
|
"Expected 'a' to be real."
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the jasmine utility to the matcher factory', function(done) {
|
it('passes the jasmine utility to the matcher factory', async function() {
|
||||||
var matcherFactory = function(util) {
|
const matcherFactory = function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
return Promise.resolve({ pass: true });
|
return Promise.resolve({ pass: true });
|
||||||
@@ -105,18 +105,18 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
return env.expectAsync(true).toBeReal();
|
return env.expectAsync(true).toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function() {
|
const specExpectations = function() {
|
||||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||||
jasmine.any(jasmineUnderTest.MatchersUtil)
|
jasmine.any(jasmineUnderTest.MatchersUtil)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
it('provides custom equality testers to the matcher factory via matchersUtil', async function() {
|
||||||
var matcherFactory = function(matchersUtil) {
|
const matcherFactory = function(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
@@ -140,12 +140,12 @@ describe('Custom Async Matchers (Integration)', function() {
|
|||||||
return env.expectAsync([1, 2]).toBeArrayWithFirstElement('1');
|
return env.expectAsync([1, 2]).toBeArrayWithFirstElement('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const specExpectations = function(result) {
|
||||||
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
||||||
expect(result.failedExpectations).toEqual([]);
|
expect(result.failedExpectations).toEqual([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
env.addReporter({ specDone: specExpectations });
|
||||||
env.execute(null, done);
|
await env.execute();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
describe('Custom Matchers (Integration)', function() {
|
describe('Custom Matchers (Integration)', function() {
|
||||||
var env;
|
let env;
|
||||||
var fakeTimer;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
@@ -11,7 +10,7 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.cleanup_();
|
env.cleanup_();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows adding more matchers local to a spec', function(done) {
|
it('allows adding more matchers local to a spec', async function() {
|
||||||
env.it('spec defining a custom matcher', function() {
|
env.it('spec defining a custom matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
matcherForSpec: function() {
|
matcherForSpec: function() {
|
||||||
@@ -37,21 +36,19 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
expect(env.expect('zzz').matcherForSpec).toBeUndefined();
|
expect(env.expect('zzz').matcherForSpec).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specDoneSpy = jasmine.createSpy('specDoneSpy');
|
const 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'
|
|
||||||
);
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
env.addReporter({ specDone: specDoneSpy });
|
env.addReporter({ specDone: specDoneSpy });
|
||||||
|
|
||||||
env.execute(null, expectations);
|
await env.execute();
|
||||||
|
|
||||||
|
const firstSpecResult = specDoneSpy.calls.first().args[0];
|
||||||
|
expect(firstSpecResult.status).toEqual('failed');
|
||||||
|
expect(firstSpecResult.failedExpectations[0].message).toEqual(
|
||||||
|
'matcherForSpec: actual: zzz; expected: yyy'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the spec if the custom matcher passes', function(done) {
|
it('passes the spec if the custom matcher passes', async function() {
|
||||||
env.it('spec using custom matcher', function() {
|
env.it('spec using custom matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -66,23 +63,24 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).toBeReal();
|
env.expect(true).toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
};
|
await env.execute();
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', function(done) {
|
it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', async function() {
|
||||||
env.it('spec using custom equality matcher', function() {
|
env.it('spec using custom equality matcher', function() {
|
||||||
var customEqualityFn = function(a, b) {
|
const customEqualityFn = function(a, b) {
|
||||||
// All "foo*" strings match each other.
|
// All "foo*" strings match each other.
|
||||||
if (
|
if (
|
||||||
typeof a == 'string' &&
|
typeof a == 'string' &&
|
||||||
typeof b == 'string' &&
|
typeof b == 'string' &&
|
||||||
a.substr(0, 3) == 'foo' &&
|
a.slice(0, 3) == 'foo' &&
|
||||||
b.substr(0, 3) == 'foo'
|
b.slice(0, 3) == 'foo'
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -100,17 +98,18 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
};
|
await env.execute();
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays an appropriate failure message if a custom equality matcher fails', function(done) {
|
it('displays an appropriate failure message if a custom equality matcher fails', async function() {
|
||||||
env.it('spec using custom equality matcher', function() {
|
env.it('spec using custom equality matcher', function() {
|
||||||
var customEqualityFn = function(a, b) {
|
const customEqualityFn = function(a, b) {
|
||||||
// "foo" is not equal to anything
|
// "foo" is not equal to anything
|
||||||
if (a === 'foo' || b === 'foo') {
|
if (a === 'foo' || b === 'foo') {
|
||||||
return false;
|
return false;
|
||||||
@@ -121,18 +120,19 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
|
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('failed');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
await env.execute();
|
||||||
"Expected $.foo = 'foo' to equal 'foo'."
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('failed');
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
"Expected $.foo = 'foo' to equal 'foo'."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the negative compare function for a negative comparison, if provided', function(done) {
|
it('uses the negative compare function for a negative comparison, if provided', async function() {
|
||||||
env.it('spec with custom negative comparison matcher', function() {
|
env.it('spec with custom negative comparison matcher', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -150,15 +150,16 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).not.toBeReal();
|
env.expect(true).not.toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.status).toEqual('passed');
|
env.addReporter(reporter);
|
||||||
};
|
await env.execute();
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.status).toEqual('passed');
|
||||||
});
|
});
|
||||||
|
|
||||||
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', async function() {
|
||||||
env.it('spec with an expectation', function() {
|
env.it('spec with an expectation', function() {
|
||||||
env.addMatchers({
|
env.addMatchers({
|
||||||
toBeReal: function() {
|
toBeReal: function() {
|
||||||
@@ -173,18 +174,19 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect('a').toBeReal();
|
env.expect('a').toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(result.failedExpectations[0].message).toEqual(
|
env.addReporter(reporter);
|
||||||
"Expected 'a' to be real."
|
await env.execute();
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(result.failedExpectations[0].message).toEqual(
|
||||||
|
"Expected 'a' to be real."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the expected and actual arguments to the comparison function', function(done) {
|
it('passes the expected and actual arguments to the comparison function', async function() {
|
||||||
var argumentSpy = jasmine
|
const argumentSpy = jasmine
|
||||||
.createSpy('argument spy')
|
.createSpy('argument spy')
|
||||||
.and.returnValue({ pass: true });
|
.and.returnValue({ pass: true });
|
||||||
|
|
||||||
@@ -200,18 +202,14 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).toBeReal('arg1', 'arg2');
|
env.expect(true).toBeReal('arg1', 'arg2');
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function() {
|
await env.execute();
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true);
|
expect(argumentSpy).toHaveBeenCalledWith(true);
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
|
||||||
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
|
||||||
env.execute(null, done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the jasmine utility to the matcher factory', function(done) {
|
it('passes the jasmine utility to the matcher factory', async function() {
|
||||||
var matcherFactory = function(util) {
|
const matcherFactory = function() {
|
||||||
return {
|
return {
|
||||||
compare: function() {
|
compare: function() {
|
||||||
return { pass: true };
|
return { pass: true };
|
||||||
@@ -230,18 +228,14 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect(true).toBeReal();
|
env.expect(true).toBeReal();
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function() {
|
await env.execute();
|
||||||
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
expect(matcherFactorySpy).toHaveBeenCalledWith(
|
||||||
jasmine.any(jasmineUnderTest.MatchersUtil)
|
jasmine.any(jasmineUnderTest.MatchersUtil)
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
|
||||||
env.execute(null, done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) {
|
it('provides custom equality testers to the matcher factory via matchersUtil', async function() {
|
||||||
var matcherFactory = function(matchersUtil) {
|
const matcherFactory = function(matchersUtil) {
|
||||||
return {
|
return {
|
||||||
compare: function(actual, expected) {
|
compare: function(actual, expected) {
|
||||||
return { pass: matchersUtil.equals(actual[0], expected) };
|
return { pass: matchersUtil.equals(actual[0], expected) };
|
||||||
@@ -263,12 +257,13 @@ describe('Custom Matchers (Integration)', function() {
|
|||||||
env.expect([1, 2]).toBeArrayWithFirstElement('1');
|
env.expect([1, 2]).toBeArrayWithFirstElement('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
var specExpectations = function(result) {
|
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||||
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
env.addReporter(reporter);
|
||||||
expect(result.failedExpectations).toEqual([]);
|
await env.execute();
|
||||||
};
|
|
||||||
|
|
||||||
env.addReporter({ specDone: specExpectations });
|
expect(reporter.specDone).toHaveBeenCalledTimes(1);
|
||||||
env.execute(null, done);
|
const result = reporter.specDone.calls.argsFor(0)[0];
|
||||||
|
expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
|
||||||
|
expect(result.failedExpectations).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user