Compare commits
358 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
98c2f019c6 | ||
|
|
507dad6d87 | ||
|
|
6da7a32442 | ||
|
|
58d13570ac | ||
|
|
005648acd8 | ||
|
|
ff14c03a40 | ||
|
|
ff848c812a | ||
|
|
d963be5eec | ||
|
|
8444faab72 | ||
|
|
883f400074 | ||
|
|
3c16caa413 | ||
|
|
5d0be2e6cf | ||
|
|
c56631175f | ||
|
|
cef738966c | ||
|
|
5fd0e49ccf | ||
|
|
c431590d65 | ||
|
|
656e6614da | ||
|
|
24408a16ed | ||
|
|
ca90c76d12 | ||
|
|
57c294b307 | ||
|
|
e73eb18753 | ||
|
|
0411b0567d | ||
|
|
30b93ccdbb | ||
|
|
067b91b3ef | ||
|
|
0b1385c3d3 | ||
|
|
f1cf6ee419 | ||
|
|
b37d989f13 | ||
|
|
89151d6e64 | ||
|
|
75e3e14861 | ||
|
|
ce7460d8d4 | ||
|
|
b8dabf96ff | ||
|
|
40fac8b6a2 | ||
|
|
5eb42d67a7 | ||
|
|
d739c23401 | ||
|
|
42e6c45efa | ||
|
|
5942654856 | ||
|
|
f3b26a0688 | ||
|
|
8804ddb8cf | ||
|
|
439be97c34 | ||
|
|
871ba99a30 | ||
|
|
7a685b16f6 | ||
|
|
2a049015b0 | ||
|
|
c48fb0b0e7 | ||
|
|
4c47bf6c0b | ||
|
|
e86a7f00a6 | ||
|
|
504ef27899 | ||
|
|
2a39339755 | ||
|
|
2c440b8e44 | ||
|
|
8e74529631 | ||
|
|
b13329114c | ||
|
|
ab34f272da | ||
|
|
1af0e62ef7 | ||
|
|
572452a15a | ||
|
|
896412367a | ||
|
|
503a7409f0 | ||
|
|
c1db8f2f82 | ||
|
|
bb9175cb66 | ||
|
|
41f5c53959 | ||
|
|
25c3f06839 | ||
|
|
976928c7ae | ||
|
|
36a4ddf433 | ||
|
|
53b1cd37b6 | ||
|
|
8cadfbd829 | ||
|
|
86aeb5c88a | ||
|
|
469b557828 | ||
|
|
503715c275 | ||
|
|
d4c15b8df4 | ||
|
|
6f0c51260f | ||
|
|
4482355885 | ||
|
|
6542364381 | ||
|
|
1fc911e0fa | ||
|
|
15710937b8 | ||
|
|
1a9d16715d | ||
|
|
b67a3043c7 | ||
|
|
5f1ef5ac2b | ||
|
|
5eaeeb0b6c | ||
|
|
457a2727ba | ||
|
|
a1f14efac6 | ||
|
|
b2067d9ce0 | ||
|
|
47081258cd | ||
|
|
9c03d4d3e9 | ||
|
|
7f0087b805 | ||
|
|
fdad8849df | ||
|
|
7a289f1de7 | ||
|
|
ef981bb794 | ||
|
|
c3fb3e985a | ||
|
|
7fc3408051 | ||
|
|
af1b43eeff | ||
|
|
4c043717a9 | ||
|
|
35064cf60e | ||
|
|
fb4c16b23e | ||
|
|
3b28ee7c29 | ||
|
|
40be00310d | ||
|
|
3a77ae3dfe | ||
|
|
1332f01ca4 | ||
|
|
64d58ed1f0 | ||
|
|
497a7fc3e5 | ||
|
|
1f318c3c93 | ||
|
|
be29aa95eb | ||
|
|
e3c9a59c6c | ||
|
|
b312ed4940 | ||
|
|
8d302d8dca | ||
|
|
00f6708e1f | ||
|
|
760f2d9003 | ||
|
|
6e10f22403 | ||
|
|
d092a59bd1 | ||
|
|
af5984d5d6 | ||
|
|
15f7013f85 | ||
|
|
be23836c9d | ||
|
|
7944250290 | ||
|
|
3a47a3bd04 | ||
|
|
1c9382c990 | ||
|
|
394be99832 | ||
|
|
bbcb5ff42f | ||
|
|
6603ed7ddc | ||
|
|
d61800c5c8 | ||
|
|
37b9f8e420 | ||
|
|
a63b0b0368 | ||
|
|
de9815f436 | ||
|
|
62a667a8e3 | ||
|
|
d277827d5e | ||
|
|
644c175338 | ||
|
|
a6d7eb2a06 | ||
|
|
2fd9d7b13f | ||
|
|
dd8a65cb60 | ||
|
|
e72d161fab | ||
|
|
4e96514634 | ||
|
|
d8862aa583 | ||
|
|
2480a0a93a | ||
|
|
9c9836c5b3 | ||
|
|
20b914c554 | ||
|
|
058e77b824 | ||
|
|
dcaac62a6c | ||
|
|
b696bec9e3 | ||
|
|
13dfcacbb0 | ||
|
|
6d002d22af | ||
|
|
799d9897fd | ||
|
|
2a2a671b65 | ||
|
|
a0b4f3748d | ||
|
|
43073b3bc5 | ||
|
|
09d2ce9bc9 | ||
|
|
e9bddc7a06 | ||
|
|
310e4d5e6c | ||
|
|
0424d4ae99 | ||
|
|
0720c88252 | ||
|
|
f26b005807 | ||
|
|
1206952ca6 | ||
|
|
286524959b | ||
|
|
c73df57720 | ||
|
|
0170005015 | ||
|
|
6f04044417 | ||
|
|
70d49e5b57 | ||
|
|
ed9363f477 | ||
|
|
fe0a83ba87 | ||
|
|
623eecdcec | ||
|
|
2c32dd5703 | ||
|
|
a27280e9e7 | ||
|
|
10601f5af6 | ||
|
|
c10ab4e704 | ||
|
|
c1d1d69be2 | ||
|
|
3513249d73 | ||
|
|
21bfbbb721 | ||
|
|
88b90ec258 | ||
|
|
e399953174 | ||
|
|
4edac7d3d1 | ||
|
|
9b3d4a2bf2 | ||
|
|
17826cd044 | ||
|
|
6cb9507f62 | ||
|
|
50c88e7774 | ||
|
|
3e64ce3310 | ||
|
|
00586e50e0 | ||
|
|
dc80a282ba | ||
|
|
27c650ec08 | ||
|
|
56daa6f461 | ||
|
|
e4c7d8af45 | ||
|
|
ee88ecc614 | ||
|
|
ec038273f1 | ||
|
|
c5bdd79a1e | ||
|
|
dbc1a0aa56 | ||
|
|
5862b22aef | ||
|
|
163f93d6ff | ||
|
|
1893bf6c16 | ||
|
|
095745ab12 | ||
|
|
68db3f6fcf | ||
|
|
1e4f0d1545 | ||
|
|
c546d2cb6d | ||
|
|
6e097528f5 | ||
|
|
4e1f36cbb0 | ||
|
|
0aee81cfb9 | ||
|
|
1e50b49092 | ||
|
|
6aecf16cde | ||
|
|
f2de1be96a | ||
|
|
a0f6b77c3e | ||
|
|
3f3fb38cf1 | ||
|
|
00c1e3d608 | ||
|
|
6a2a30d540 | ||
|
|
5f4a1c4276 | ||
|
|
a4ef3687ee | ||
|
|
e4e232864d | ||
|
|
5acddcda4a | ||
|
|
61fb353197 | ||
|
|
9065b4c3b7 | ||
|
|
752441a66f | ||
|
|
3e2872a1df | ||
|
|
140225e7c3 | ||
|
|
8b38389d56 | ||
|
|
b7c2a2f6fb | ||
|
|
c5d4a40219 | ||
|
|
c7c8b6b93e | ||
|
|
8a42437059 | ||
|
|
cacc6f4278 | ||
|
|
d815e99456 | ||
|
|
5e3f937221 | ||
|
|
1b97795684 | ||
|
|
5504965bea | ||
|
|
d666f1efbb | ||
|
|
4515b76f07 | ||
|
|
0897e31a2d | ||
|
|
c2a714f168 | ||
|
|
c2b558a2da | ||
|
|
235efe52f1 | ||
|
|
1e8619df88 | ||
|
|
4b2a14f1f3 | ||
|
|
66189d742b | ||
|
|
fb05da1fc3 | ||
|
|
9555cb9842 | ||
|
|
d6fa9dd1a0 | ||
|
|
25fbe0646a | ||
|
|
316ce1e2d3 | ||
|
|
82cc1083b6 | ||
|
|
c2f04ba627 | ||
|
|
97a46f4560 | ||
|
|
113134cdbd | ||
|
|
dad5f5fd6b | ||
|
|
fa72544974 | ||
|
|
e303de52ed | ||
|
|
5f9315731e | ||
|
|
ce850c472a | ||
|
|
8b3a6561b1 | ||
|
|
2fc5182ddc | ||
|
|
6be2102b64 | ||
|
|
c6a79d3ab7 | ||
|
|
3f232fba80 | ||
|
|
cde6ea79a3 | ||
|
|
0782a73a98 | ||
|
|
37073e2768 | ||
|
|
f7f928fdd3 | ||
|
|
503b653a10 | ||
|
|
cb044aa273 | ||
|
|
5c17456925 | ||
|
|
592fba22b8 | ||
|
|
58ef707bc6 | ||
|
|
050c1f051c | ||
|
|
8d0c52e2ec | ||
|
|
de91427356 | ||
|
|
324bc201c2 | ||
|
|
76f34e90dc | ||
|
|
46e7158c77 | ||
|
|
9ab039e330 | ||
|
|
3234d475cd | ||
|
|
3f5c47dff3 | ||
|
|
1320b0614f | ||
|
|
905e3fc3f9 | ||
|
|
89331bb1bb | ||
|
|
88de272c89 | ||
|
|
60bbe68148 | ||
|
|
623e638cd4 | ||
|
|
b1bcd6e825 | ||
|
|
204acf7297 | ||
|
|
cd1131354b | ||
|
|
c24aef15b1 | ||
|
|
d5d5d1965f | ||
|
|
d27bb8fa96 | ||
|
|
7d5ca27b9d | ||
|
|
7a38db2e32 | ||
|
|
a1f1b4ae0f | ||
|
|
795651d3b6 | ||
|
|
e7daa429a1 | ||
|
|
51ad18cb28 | ||
|
|
0b81705c11 | ||
|
|
00feef8632 | ||
|
|
5a715aecee | ||
|
|
8cb44582bc | ||
|
|
53d8073707 | ||
|
|
e0eb4755cb | ||
|
|
6277046213 | ||
|
|
6b9739030d | ||
|
|
b0d949e0d5 | ||
|
|
dfdcfc5be5 | ||
|
|
e5bb89847f | ||
|
|
1f68ed836e | ||
|
|
c4e65e4a9a | ||
|
|
0cfeb0b9c3 | ||
|
|
c39c110eca | ||
|
|
18b2646d1d | ||
|
|
9aed55bb91 | ||
|
|
90d6f9d73c | ||
|
|
2369c8dba7 | ||
|
|
2745d7d515 |
142
.circleci/config.yml
Normal file
142
.circleci/config.yml
Normal file
@@ -0,0 +1,142 @@
|
||||
# Run tests against supported Node versions, and (except for pull requests)
|
||||
# against supported browsers.
|
||||
|
||||
version: 2.1
|
||||
|
||||
executors:
|
||||
node18:
|
||||
docker:
|
||||
- image: cimg/node:18.0.0 # Latest 18.x
|
||||
working_directory: ~/workspace
|
||||
node16:
|
||||
docker:
|
||||
- image: cimg/node:16.14.2 # Latest 16.x
|
||||
working_directory: ~/workspace
|
||||
node14:
|
||||
docker:
|
||||
- image: cimg/node:14.17.4 # Latest 14.x
|
||||
working_directory: ~/workspace
|
||||
node12_latest:
|
||||
docker:
|
||||
- image: cimg/node:12.22.10 # Latest 12.x
|
||||
working_directory: ~/workspace
|
||||
node12_17:
|
||||
docker:
|
||||
- image: cimg/node:12.17.0 # Oldest version supported by Jasmine
|
||||
working_directory: ~/workspace
|
||||
|
||||
jobs:
|
||||
build:
|
||||
parameters:
|
||||
executor:
|
||||
type: executor
|
||||
executor: << parameters.executor >>
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Report Node and NPM versions
|
||||
command: echo "Using Node $(node --version) and NPM $(npm --version)"
|
||||
- run:
|
||||
name: Install dependencies
|
||||
command: npm install
|
||||
- run:
|
||||
name: Build
|
||||
command: npm run build
|
||||
- persist_to_workspace:
|
||||
root: .
|
||||
paths:
|
||||
- .
|
||||
|
||||
test_node: &test_node
|
||||
parameters:
|
||||
executor:
|
||||
type: executor
|
||||
executor: << parameters.executor >>
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Run tests
|
||||
command: npm test
|
||||
|
||||
test_browsers: &test_browsers
|
||||
executor: node14
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run:
|
||||
name: Install Sauce Connect
|
||||
command: |
|
||||
cd /tmp
|
||||
curl https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz | tar zxf -
|
||||
chmod +x sc-4.7.1-linux/bin/sc
|
||||
mkdir ~/workspace/bin
|
||||
cp sc-4.7.1-linux/bin/sc ~/workspace/bin
|
||||
~/workspace/bin/sc --version
|
||||
- run:
|
||||
name: Run tests
|
||||
command: |
|
||||
# Do everything in one step because Sauce Connect won't exit
|
||||
# cleanly if we kill it from a different step than it started in.
|
||||
|
||||
export PATH=$PATH:$HOME/workspace/bin
|
||||
export SAUCE_TUNNEL_IDENTIFIER=$CIRCLE_BUILD_NUM
|
||||
scripts/start-sauce-connect sauce-pidfile
|
||||
set +o errexit
|
||||
scripts/run-all-browsers
|
||||
exitcode=$?
|
||||
set -o errexit
|
||||
scripts/stop-sauce-connect $(cat sauce-pidfile)
|
||||
exit $exitcode
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
|
||||
push:
|
||||
jobs:
|
||||
- build:
|
||||
executor: node18
|
||||
name: build_node_18
|
||||
- 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: node18
|
||||
name: test_node_18
|
||||
requires:
|
||||
- build_node_18
|
||||
- test_node:
|
||||
executor: node16
|
||||
name: test_node_16
|
||||
requires:
|
||||
- build_node_16
|
||||
- test_node:
|
||||
executor: node14
|
||||
name: test_node_14
|
||||
requires:
|
||||
- build_node_14
|
||||
- test_node:
|
||||
executor: node12_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.
|
||||
@@ -3,14 +3,6 @@ charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{js, json, sh, yml, gemspec}]
|
||||
[*.{js, json, sh, yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[{Rakefile, .jshintrc}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{py}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
130
.github/CONTRIBUTING.md
vendored
130
.github/CONTRIBUTING.md
vendored
@@ -1,29 +1,34 @@
|
||||
# Developing for Jasmine Core
|
||||
|
||||
We welcome your contributions! Thanks for helping make Jasmine a better project for everyone. Please review the backlog and discussion lists before starting work. What you're looking for may already have been done. If it hasn't, the community can help make your contribution better. If you want to contribute but don't know what to work on, [issues tagged ready for work](https://github.com/jasmine/jasmine/labels/ready%20for%20work) should have enough detail to get started.
|
||||
We welcome your contributions! Thanks for helping make Jasmine a better project
|
||||
for everyone. Please review the backlog and discussion lists before starting
|
||||
work. What you're looking for may already have been done. If it hasn't, the
|
||||
community can help make your contribution better. If you want to contribute but
|
||||
don't know what to work on,
|
||||
[issues tagged help needed](https://github.com/jasmine/jasmine/labels/help%20needed)
|
||||
should have enough detail to get started.
|
||||
|
||||
## Links
|
||||
|
||||
- [Jasmine Google Group](http://groups.google.com/group/jasmine-js)
|
||||
- [Jasmine-dev Google Group](http://groups.google.com/group/jasmine-js-dev)
|
||||
- [Jasmine on PivotalTracker](https://www.pivotaltracker.com/n/projects/10606)
|
||||
- [Jasmine backlog](https://www.pivotaltracker.com/n/projects/10606)
|
||||
|
||||
## General Workflow
|
||||
## Before Submitting a Pull Request
|
||||
|
||||
Please submit pull requests via feature branches using the semi-standard workflow of:
|
||||
1. Ensure all specs are green in browsers *and* node.
|
||||
* Use `npm test` to test in Node.
|
||||
* Use `npm run serve` to test in browsers.
|
||||
2. Fix any eslint or prettier errors reported at the end of `npm test`. Prettier
|
||||
errors can be automatically fixed by running `npm run cleanup`.
|
||||
3. Build `jasmine.js` with `npm run build` and run all specs again. This
|
||||
ensures that your changes self-test well.
|
||||
5. Revert your changes to `jasmine.js` and `jasmine-html.js`. When we accept
|
||||
your pull request, we will generate these files as a separate commit and
|
||||
merge the entire branch into master.
|
||||
|
||||
```bash
|
||||
git clone git@github.com:yourUserName/jasmine.git # Clone your fork
|
||||
cd jasmine # Change directory
|
||||
git remote add upstream https://github.com/jasmine/jasmine.git # Assign original repository to a remote named 'upstream'
|
||||
git fetch upstream # Fetch changes not present in your local repository
|
||||
git merge upstream/main # Sync local main with upstream repository
|
||||
git checkout -b my-new-feature # Create your feature branch
|
||||
git commit -am 'Add some feature' # Commit your changes
|
||||
git push origin my-new-feature # Push to the branch
|
||||
```
|
||||
|
||||
Once you've pushed a feature branch to your forked repo, you're ready to open a pull request. We favor pull requests with very small, single commits with a single purpose.
|
||||
We only accept green pull requests. If you see that the CI build failed, please
|
||||
fix it. Feel free to ask for help if you're stuck.
|
||||
|
||||
## Background
|
||||
|
||||
@@ -32,51 +37,43 @@ Once you've pushed a feature branch to your forked repo, you're ready to open a
|
||||
* `/src` contains all of the source files
|
||||
* `/src/core` - generic source files
|
||||
* `/src/html` - browser-specific files
|
||||
* `/src/boot` - sources for boot files (see below)
|
||||
* `/spec` contains all of the tests
|
||||
* mirrors the source directory
|
||||
* there are some additional files
|
||||
* `/dist` contains the standalone distributions as zip files
|
||||
* `/lib` contains the generated files for distribution as the Jasmine Rubygem and the Python package
|
||||
* `/lib` contains the compiled copy of Jasmine. This is used to self-test and
|
||||
distributed as the `jasmine-core` Node, and Ruby packages.
|
||||
|
||||
### Self-testing
|
||||
|
||||
Note that Jasmine tests itself. The files in `lib` are loaded first, defining the reference `jasmine`. Then the files in `src` are loaded, defining the reference `jasmineUnderTest`. So there are two copies of the code loaded under test.
|
||||
Jasmine tests itself. The files in `lib` are loaded first, defining the reference `jasmine`. Then the files in `src` are loaded, defining the reference `jasmineUnderTest`. So there are two copies of the code loaded under test.
|
||||
|
||||
The tests should always use `jasmineUnderTest` to refer to the objects and functions that are being tested. But the tests can use functions on `jasmine` as needed. _Be careful how you structure any new test code_. Copy the patterns you see in the existing code - this ensures that the code you're testing is not leaking into the `jasmine` reference and vice-versa.
|
||||
|
||||
### `boot.js`
|
||||
### `boot0.js` and `boot1.js`
|
||||
|
||||
This file does all of the setup necessary for Jasmine to work. It loads all of the code, creates an `Env`, attaches the global functions, and builds the reporter. It also sets up the execution of the `Env` - for browsers this is in `window.onload`. While the default in `lib` is appropriate for browsers, projects may wish to customize this file.
|
||||
|
||||
For example, for Jasmine development there is a different `dev_boot.js` for Jasmine development that does more work.
|
||||
These files file does all of the setup necessary for Jasmine to work in a
|
||||
browser. They load all of the code, create an `Env`, attach the global
|
||||
functions, and build the reporter. It also sets up the execution of the
|
||||
`Env` - for browsers this is in `window.onload`. While the default in `lib`
|
||||
is appropriate for browsers, projects may wish to customize this file.
|
||||
|
||||
### Compatibility
|
||||
|
||||
Jasmine supports the following environments:
|
||||
|
||||
* Browsers
|
||||
* IE10+
|
||||
* Edge Latest
|
||||
* Firefox Latest
|
||||
* Chrome Latest
|
||||
* Safari 8+
|
||||
|
||||
* Node.js
|
||||
* 8
|
||||
* 10
|
||||
* 12
|
||||
Jasmine runs in both Node and a variety of browsers. See the README for the
|
||||
list of currently supported environments.
|
||||
|
||||
## Development
|
||||
|
||||
All source code belongs in `src/`. The `core/` directory contains the bulk of Jasmine's functionality. This code should remain browser- and environment-agnostic. If your feature or fix cannot be, as mentioned above, please degrade gracefully. Any code that depends on a browser (specifically, it expects `window` to be the global or `document` is present) should live in `src/html/`.
|
||||
|
||||
### Install Dependencies
|
||||
### Install Dev Dependencies
|
||||
|
||||
Jasmine Core relies on Node.js.
|
||||
|
||||
To install the Node dependencies, you will need Node.js, Npm, and [Grunt](http://gruntjs.com/), the [grunt-cli](https://github.com/gruntjs/grunt-cli) and ensure that `grunt` is on your path.
|
||||
To install the Node dependencies, you will need Node.js and npm.
|
||||
|
||||
$ npm install --local
|
||||
$ npm install
|
||||
|
||||
...will install all of the node modules locally. Now run
|
||||
|
||||
@@ -88,40 +85,37 @@ To install the Node dependencies, you will need Node.js, Npm, and [Grunt](http:/
|
||||
|
||||
Or, How to make a successful pull request
|
||||
|
||||
* _Do not change the public interface_. Lots of projects depend on Jasmine and if you aren't careful you'll break them
|
||||
* _Be environment agnostic_ - server-side developers are just as important as browser developers
|
||||
* _Be browser agnostic_ - if you must rely on browser-specific functionality, please write it in a way that degrades gracefully
|
||||
* _Write specs_ - Jasmine's a testing framework; don't add functionality without test-driving it
|
||||
* _Write code in the style of the rest of the repo_ - Jasmine should look like a cohesive whole
|
||||
* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and ESLint - your contribution shouldn't break Jasmine for other users
|
||||
* _Do not change the public interface_. Lots of projects depend on Jasmine and
|
||||
if you aren't careful you'll break them.
|
||||
* _Be environment agnostic_. Some people run their specs in browsers, others in
|
||||
Node. Jasmine should support them all as much as possible.
|
||||
* _Be browser agnostic_ - if you must rely on browser-specific functionality,
|
||||
please write it in a way that degrades gracefully.
|
||||
* _Write specs_ - Jasmine's a testing framework. Don't add functionality
|
||||
without test-driving it.
|
||||
* _Write code in the style of the rest of the repo_ - Jasmine should look like
|
||||
a cohesive whole.
|
||||
|
||||
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
|
||||
ESLint/Prettier. Your contribution shouldn't break Jasmine for other users.
|
||||
|
||||
Follow these tips and your pull request, patch, or suggestion is much more likely to be integrated.
|
||||
|
||||
### Running Specs
|
||||
|
||||
Jasmine uses some internal tooling to test itself in browser on Travis. This tooling _should_ work locally as well.
|
||||
Be sure to run the tests in at least one supported Node version and at least a
|
||||
couple of supported browsers. To run the tests in Node, simply use `npm test`
|
||||
as described above. To run the tests in a browser, run `npm run serve` and then
|
||||
visit `http://localhost:8888`.
|
||||
|
||||
$ node ci.js
|
||||
If you have the necessary Selenium drivers installed (e.g. geckodriver or
|
||||
chromedriver), you can also use Jasmine's CI tooling:
|
||||
|
||||
You can also set the `JASMINE_BROWSER` environment variable to specify which browser should be used.
|
||||
|
||||
The easiest way to run the tests in **Internet Explorer** is to run a VM that has IE installed. It's easy to do this with VirtualBox.
|
||||
|
||||
1. Download and install [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
|
||||
1. Download a VM image [from Microsoft](https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/). Select "VirtualBox" as the platform.
|
||||
1. Unzip the downloaded archive. There should be an OVA file inside.
|
||||
1. In VirtualBox, choose `File > Import Appliance` and select the OVA file. Accept the default settings in the dialog that appears. Now you have a Windows VM!
|
||||
1. Run the VM and start IE.
|
||||
1. With `npm run serve` running on your host machine, navigate to `http://10.0.2.2:8888` in IE.
|
||||
|
||||
## Before Committing or Submitting a Pull Request
|
||||
|
||||
1. Ensure all specs are green in browser *and* node
|
||||
1. Ensure eslint and prettier are clean as part of your `npm test` command. You can run `npm run cleanup` to have prettier re-write the files.
|
||||
1. Build `jasmine.js` with `npm run build` and run all specs again - this ensures that your changes self-test well
|
||||
1. Revert your changes to `jasmine.js` and `jasmine-html.js`
|
||||
* We do this because `jasmine.js` and `jasmine-html.js` are auto-generated (as you've seen in the previous steps) and accepting multiple pull requests when this auto-generated file changes causes lots of headaches
|
||||
* When we accept your pull request, we will generate these files as a separate commit and merge the entire branch into main
|
||||
|
||||
Note that we use Travis for Continuous Integration. We only accept green pull requests.
|
||||
$ JASMINE_BROWSER=<name of browser> npm run ci
|
||||
|
||||
|
||||
3
.github/ISSUE_TEMPLATE.md
vendored
3
.github/ISSUE_TEMPLATE.md
vendored
@@ -3,9 +3,12 @@
|
||||
- When in doubt, create an issue here.
|
||||
- If you have an issue with the Jasmine docs, file an issue in the docs repo
|
||||
here: https://github.com/jasmine/jasmine.github.io
|
||||
- If you have an issue with TypeScript typings, start a discussion at
|
||||
[DefinitelyTpyed](https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/new?category=issues-with-a-types-package)
|
||||
- This repository is for the core Jasmine framework
|
||||
- If you are using a test runner that wraps Jasmine, consider filing an issue with that library if appropriate:
|
||||
- [Jasmine npm](https://github.com/jasmine/jasmine-npm/issues)
|
||||
- [Jasmine browser runner](https://github.com/jasmine/jasmine-browser/issues)
|
||||
- [Jasmine gem](https://github.com/jasmine/jasmine-gem/issues)
|
||||
- [Jasmine py](https://github.com/jasmine/jasmine-py/issues)
|
||||
- [Gulp Jasmine Browser](https://github.com/jasmine/gulp-jasmine-browser/issues)
|
||||
|
||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -24,7 +24,7 @@
|
||||
- [ ] My code follows the code style of this project.
|
||||
- [ ] My change requires a change to the documentation.
|
||||
- [ ] I have updated the documentation accordingly.
|
||||
- [ ] I have read the **CONTRIBUTING** document.
|
||||
- [ ] I have read the [**CONTRIBUTING**](https://github.com/jasmine/jasmine/blob/main/.github/CONTRIBUTING.md) guide.
|
||||
- [ ] I have added tests to cover my changes.
|
||||
- [ ] All new and existing tests passed.
|
||||
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -17,11 +17,10 @@ pkg/*
|
||||
.sass-cache/*
|
||||
src/html/.sass-cache/*
|
||||
node_modules/
|
||||
*.pyc
|
||||
sauce_connect.log
|
||||
*.swp
|
||||
build/
|
||||
*.egg-info/
|
||||
dist
|
||||
nbproject/
|
||||
*.iml
|
||||
.envrc
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "pages"]
|
||||
path = pages
|
||||
url = https://github.com/pivotal/jasmine.git
|
||||
29
.npmignore
29
.npmignore
@@ -1,29 +0,0 @@
|
||||
dist/
|
||||
grunt/
|
||||
node_modules
|
||||
pkg/
|
||||
release_notes/
|
||||
spec/
|
||||
src/
|
||||
Gemfile
|
||||
Gemfile.lock
|
||||
Rakefile
|
||||
jasmine-core.gemspec
|
||||
.bundle/
|
||||
.gitignore
|
||||
.gitmodules
|
||||
.idea
|
||||
.jshintrc
|
||||
.rspec
|
||||
.sass-cache/
|
||||
.travis.yml
|
||||
*.sh
|
||||
*.py
|
||||
Gruntfile.js
|
||||
lib/jasmine-core.rb
|
||||
lib/jasmine-core/boot/
|
||||
lib/jasmine-core/spec
|
||||
lib/jasmine-core/version.rb
|
||||
lib/jasmine-core/*.py
|
||||
sauce_connect.log
|
||||
ci.js
|
||||
52
.travis.yml
52
.travis.yml
@@ -1,52 +0,0 @@
|
||||
language: node_js
|
||||
node_js: 10
|
||||
|
||||
script: $TEST_COMMAND
|
||||
|
||||
env:
|
||||
global:
|
||||
- USE_SAUCE=true
|
||||
- TEST_COMMAND="bash travis-core-script.sh"
|
||||
- secure: WSPWhlnC4mWSnSPquX+m1/BCu5ch5NygkaHuM2Nea7lD8oS3XLX8QncZZAsQ4lnNfqoDDuBOizG0AESiqNvE4y6x5qvLLTS6q+ce255ZEMZ71TBdZgDEEvGMEjOPPsVXiXyTQOP1lwOPlrbZvaPgWV7e11KIBab6DfFcQpnvDgo=
|
||||
- secure: SW7CJhZnwaNT749Gdnhvqb5rbXlAOsygUAzh9qhtyvbqXKkmJdBIEsO01YF6pbju1X2twE9JvWCOxeZju43NgQChJlPsGbjY2j3k/TdQeTAJesQe2K7ytwghunI30gjEovtRH0T3w1EmcKPH8yj5eBIcB2OYoJHx8KEC7e68q1g=
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- node_js: "10"
|
||||
env: JASMINE_LONG_PROPERTY_TESTS="y" TEST_COMMAND="npm test"
|
||||
- node_js: "12"
|
||||
env: TEST_COMMAND="npm test"
|
||||
- node_js: "8"
|
||||
env: TEST_COMMAND="npm test"
|
||||
- env: JASMINE_BROWSER="internet explorer" SAUCE_BROWSER_VERSION=11 SAUCE_OS="Windows 8.1"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="internet explorer" SAUCE_BROWSER_VERSION=10 SAUCE_OS="Windows 8"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="firefox" SAUCE_BROWSER_VERSION='' SAUCE_OS="Windows 10"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="firefox" SAUCE_BROWSER_VERSION='68' SAUCE_OS="Windows 10"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="chrome" SAUCE_BROWSER_VERSION='' SAUCE_OS="Windows 10"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="safari" SAUCE_BROWSER_VERSION="13" SAUCE_OS="OS X 10.13"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="safari" SAUCE_BROWSER_VERSION="8" SAUCE_OS="OS X 10.10"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
- env: JASMINE_BROWSER="MicrosoftEdge" SAUCE_BROWSER_VERSION="" SAUCE_OS="Windows 10"
|
||||
if: type != pull_request
|
||||
addons:
|
||||
sauce_connect: true
|
||||
33
Gruntfile.js
33
Gruntfile.js
@@ -16,12 +16,6 @@ module.exports = function(grunt) {
|
||||
|
||||
grunt.registerTask('default', ['sass:dist', "cssUrlEmbed"]);
|
||||
|
||||
var version = require('./grunt/tasks/version.js');
|
||||
|
||||
grunt.registerTask('build:copyVersionToGem',
|
||||
"Propagates the version from package.json to version.rb",
|
||||
version.copyToGem);
|
||||
|
||||
grunt.registerTask('buildDistribution',
|
||||
'Builds and lints jasmine.js, jasmine-html.js, jasmine.css',
|
||||
[
|
||||
@@ -34,17 +28,21 @@ module.exports = function(grunt) {
|
||||
grunt.registerTask("execSpecsInNode",
|
||||
"Run Jasmine core specs in Node.js",
|
||||
function() {
|
||||
var done = this.async(),
|
||||
verifyNoGlobals(() => require('./lib/jasmine-core.js').noGlobals());
|
||||
const done = this.async(),
|
||||
Jasmine = require('jasmine'),
|
||||
jasmineCore = require('./lib/jasmine-core.js'),
|
||||
jasmine = new Jasmine({jasmineCore: jasmineCore});
|
||||
|
||||
jasmine.loadConfigFile('./spec/support/jasmine.json');
|
||||
jasmine.onComplete(function(passed) {
|
||||
done(passed);
|
||||
});
|
||||
|
||||
jasmine.execute();
|
||||
jasmine.exitOnCompletion = false;
|
||||
jasmine.execute().then(
|
||||
result => done(result.overallStatus === 'passed'),
|
||||
err => {
|
||||
console.error(err);
|
||||
exit(1);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -55,3 +53,14 @@ module.exports = function(grunt) {
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
function verifyNoGlobals(fn) {
|
||||
const initialGlobals = Object.keys(global);
|
||||
fn();
|
||||
|
||||
const extras = Object.keys(global).filter(k => !initialGlobals.includes(k));
|
||||
|
||||
if (extras.length !== 0) {
|
||||
throw new Error('Globals were unexpectedly created: ' + extras.join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
recursive-include . *.py
|
||||
prune node_modules
|
||||
include lib/jasmine-core/*.js
|
||||
include lib/jasmine-core/*.css
|
||||
include images/*.png
|
||||
include package.json
|
||||
68
README.md
68
README.md
@@ -1,6 +1,6 @@
|
||||
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/main/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
|
||||
|
||||
[](https://travis-ci.org/jasmine/jasmine)
|
||||
[](https://circleci.com/gh/jasmine/jasmine)
|
||||
[](https://www.codetriage.com/jasmine/jasmine)
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fjasmine%2Fjasmine?ref=badge_shield)
|
||||
|
||||
@@ -11,7 +11,8 @@ Jasmine is a Behavior Driven Development testing framework for JavaScript. It do
|
||||
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
|
||||
For a quick start guide of Jasmine, see the beginning of [http://jasmine.github.io/edge/introduction.html](http://jasmine.github.io/edge/introduction.html).
|
||||
|
||||
Upgrading from Jasmine 2.x? Check out the [3.0 release notes](https://github.com/jasmine/jasmine/blob/v3.0.0/release_notes/3.0.md) for a list of what's new (including breaking changes).
|
||||
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
|
||||
|
||||
@@ -19,54 +20,36 @@ Please read the [contributors' guide](https://github.com/jasmine/jasmine/blob/ma
|
||||
|
||||
## Installation
|
||||
|
||||
For the Jasmine NPM module:<br>
|
||||
[https://github.com/jasmine/jasmine-npm](https://github.com/jasmine/jasmine-npm).
|
||||
There are several different ways to install Jasmine, depending on your
|
||||
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 Ruby Gem:<br>
|
||||
[https://github.com/jasmine/jasmine-gem](https://github.com/jasmine/jasmine-gem).
|
||||
## Usage
|
||||
|
||||
For the Jasmine Python Egg:<br>
|
||||
[https://github.com/jasmine/jasmine-py](https://github.com/jasmine/jasmine-py).
|
||||
|
||||
For the Jasmine headless browser gulp plugin:<br>
|
||||
[https://github.com/jasmine/gulp-jasmine-browser](https://github.com/jasmine/gulp-jasmine-browser).
|
||||
|
||||
To install Jasmine standalone on your local box (where **_{#.#.#}_** below is substituted by the release number downloaded):
|
||||
|
||||
* Download the standalone distribution for your desired release from the [releases page](https://github.com/jasmine/jasmine/releases).
|
||||
* Create a Jasmine directory in your project. - `mkdir my-project/jasmine`
|
||||
* Move the dist to your project directory. - `mv jasmine/dist/jasmine-standalone-{#.#.#}.zip my-project/jasmine`
|
||||
* Change directory. - `cd my-project/jasmine`
|
||||
* Unzip the dist. - `unzip jasmine-standalone-{#.#.#}.zip`
|
||||
|
||||
Add the following to your HTML file:
|
||||
|
||||
```html
|
||||
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-{#.#.#}/jasmine_favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-{#.#.#}/jasmine.css">
|
||||
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine.js"></script>
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine-html.js"></script>
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/boot.js"></script>
|
||||
```
|
||||
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)
|
||||
for information on writing specs.
|
||||
|
||||
## Supported environments
|
||||
|
||||
Jasmine tests itself across many browsers (Safari, Chrome, Firefox, Microsoft Edge, and Internet Explorer) as well as nodejs.
|
||||
Jasmine tests itself across popular browsers (Safari, Chrome, Firefox, and
|
||||
Microsoft Edge) as well as Node.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 8, 10, 12 |
|
||||
| Safari | 8-13 |
|
||||
| Node | 12.17+, 14, 16, 18 |
|
||||
| Safari | 14-15 |
|
||||
| Chrome | Evergreen |
|
||||
| Firefox | Evergreen, 68 |
|
||||
| Firefox | Evergreen, 91 |
|
||||
| Edge | Evergreen |
|
||||
| Internet Explorer | 10, 11 |
|
||||
|
||||
For evergreen browsers, each version of Jasmine is tested against the version of the browser that is available to us
|
||||
at the time of release. Other browsers, as well as older & newer versions of some supported browsers, are likely to work.
|
||||
However, Jasmine isn't tested against them and they aren't actively supported.
|
||||
|
||||
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).
|
||||
@@ -76,18 +59,19 @@ However, Jasmine isn't tested against them and they aren't actively supported.
|
||||
|
||||
## 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
|
||||
|
||||
* [Davis W. Frank](mailto:dwfrank@pivotal.io), Pivotal Labs
|
||||
* [Rajan Agaskar](mailto:rajan@pivotal.io), Pivotal Labs
|
||||
* [Greg Cobb](mailto:gcobb@pivotal.io), Pivotal Labs
|
||||
* [Chris Amavisca](mailto:camavisca@pivotal.io), Pivotal Labs
|
||||
* [Christian Williams](mailto:antixian666@gmail.com), Cloud Foundry
|
||||
* [Davis W. Frank](mailto:dwfrank@pivotal.io)
|
||||
* [Rajan Agaskar](mailto:rajan@pivotal.io)
|
||||
* [Greg Cobb](mailto:gcobb@pivotal.io)
|
||||
* [Chris Amavisca](mailto:camavisca@pivotal.io)
|
||||
* [Christian Williams](mailto:antixian666@gmail.com)
|
||||
* Sheel Choksi
|
||||
|
||||
Copyright (c) 2008-2018 Pivotal Labs. This software is licensed under the MIT License.
|
||||
Copyright (c) 2008-2022 Jasmine Maintainers. This software is licensed under the MIT License.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
70
RELEASE.md
70
RELEASE.md
@@ -13,13 +13,14 @@ Please attempt to keep commits to `main` small, but cohesive. If a feature is co
|
||||
|
||||
We attempt to stick to [Semantic Versioning](http://semver.org/). Most of the time, development should be against a new minor version - fixing bugs and adding new features that are backwards compatible.
|
||||
|
||||
The current version lives in the file `/package.json`. This version will be the version number that is currently released. When releasing a new version, update `package.json` with the new version and `grunt build:copyVersionToGem` to update the gem version number.
|
||||
|
||||
This version is used by both `jasmine.js` and the `jasmine-core` Ruby gem.
|
||||
The current version lives in the file `/package.json`. This version will be
|
||||
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
|
||||
update the gem version number.
|
||||
|
||||
Note that Jasmine should only use the "patch" version number in the following cases:
|
||||
|
||||
* Changes related to packaging for a specific platform (npm, gem, or pip).
|
||||
* Changes related to packaging for a specific binding library (npm or browser-runner)
|
||||
* Fixes for regressions.
|
||||
|
||||
When jasmine-core revs its major or minor version, the binding libraries should also rev to that version.
|
||||
@@ -28,31 +29,25 @@ When jasmine-core revs its major or minor version, the binding libraries should
|
||||
|
||||
When ready to release - specs are all green and the stories are done:
|
||||
|
||||
1. Update the release notes in `release_notes` - use the Anchorman gem to generate the markdown file and edit accordingly
|
||||
1. Update the version in `package.json` to a release candidate
|
||||
1. Update any links or top-level landing page for the Github Pages
|
||||
1. Update the release notes in `release_notes` - use the Anchorman gem to generate the markdown file and edit accordingly. Include a list of supported environments.
|
||||
1. Update the version in `package.json`
|
||||
1. Run `npm run build`.
|
||||
|
||||
### 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. Push
|
||||
1. Wait for Circle CI to go green
|
||||
|
||||
### Build standalone distribution
|
||||
|
||||
1. Build the standalone distribution with `grunt buildStandaloneDist`
|
||||
1. This will generate `dist/jasmine-standalone-<version>.zip`, which you will upload later (see "Finally" below).
|
||||
|
||||
### Release the Python egg
|
||||
|
||||
Install [twine](https://github.com/pypa/twine)
|
||||
|
||||
1. `python setup.py sdist`
|
||||
1. `twine upload dist/jasmine-core-<version>.tar.gz` You will need pypi credentials to upload the egg.
|
||||
|
||||
### Release the Ruby gem
|
||||
|
||||
1. Copy version to the Ruby gem with `grunt build:copyVersionToGem`
|
||||
1. __NOTE__: You will likely need to point to a local jasmine gem in order to run tests locally. _Do not_ push this version of the Gemfile.
|
||||
1. __NOTE__: You will likely need to push a new jasmine gem with a dependent version right after this release.
|
||||
1. Push these changes to GitHub and verify that this SHA is green
|
||||
1. `rake release` - tags the repo with the version, builds the `jasmine-core` gem, pushes the gem to Rubygems.org. In order to release you will have to ensure you have rubygems creds locally.
|
||||
|
||||
### Release the NPM
|
||||
### Release the core NPM module
|
||||
|
||||
1. Run the tests on Windows. (CI only tests on Linux.)
|
||||
1. `npm adduser` to save your credentials locally
|
||||
1. `npm publish .` to publish what's in `package.json`
|
||||
|
||||
@@ -60,15 +55,26 @@ Install [twine](https://github.com/pypa/twine)
|
||||
|
||||
Probably only need to do this when releasing a minor version, and not a patch version.
|
||||
|
||||
1. `cp -R edge ${version}` to copy the current edge docs to the new version
|
||||
1. Add a link to the new version in `index.html`
|
||||
1. `rake update_edge_jasmine`
|
||||
1. `npm run jsdoc`
|
||||
1. `rake release[${version}]` to copy the current edge docs to the new version
|
||||
1. Commit and push.
|
||||
|
||||
### Release the binding libraries
|
||||
|
||||
#### NPM
|
||||
|
||||
1. Create release notes using Anchorman as above
|
||||
1. In `package.json`, update both the package version and the jasmine-core dependency version
|
||||
1. Commit and push.
|
||||
1. Wait for Circle CI to go green again.
|
||||
1. Run the tests on Windows locally.
|
||||
1. `grunt release `. (Note: This will publish the package by running `npm publish`.)
|
||||
|
||||
### Finally
|
||||
|
||||
1. Visit the [Releases page for Jasmine](https://github.com/jasmine/jasmine/releases), find the tag just pushed.
|
||||
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
|
||||
1. If it is a pre-release, mark it as such.
|
||||
1. Attach the standalone zipfile
|
||||
|
||||
|
||||
There should be a post to Pivotal Labs blog and a tweet to that link.
|
||||
For each of the above GitHub repos:
|
||||
1. Visit the releases page and find the tag just published.
|
||||
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
|
||||
1. If it is a pre-release, mark it as such.
|
||||
1. For core, attach the standalone zipfile.
|
||||
|
||||
40
bower.json
40
bower.json
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"name": "jasmine-core",
|
||||
"homepage": "https://jasmine.github.io",
|
||||
"authors": [
|
||||
"slackersoft <gregg@slackersoft.net>"
|
||||
],
|
||||
"description": "Official packaging of Jasmine's core files",
|
||||
"keywords": [
|
||||
"test",
|
||||
"jasmine",
|
||||
"tdd",
|
||||
"bdd"
|
||||
],
|
||||
"license": "MIT",
|
||||
"moduleType": "globals",
|
||||
"main": "lib/jasmine-core/jasmine.js",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"dist",
|
||||
"grunt",
|
||||
"node_modules",
|
||||
"pkg",
|
||||
"release_notes",
|
||||
"spec",
|
||||
"src",
|
||||
"Gemfile",
|
||||
"Gemfile.lock",
|
||||
"Rakefile",
|
||||
"jasmine-core.gemspec",
|
||||
"*.sh",
|
||||
"*.py",
|
||||
"Gruntfile.js",
|
||||
"lib/jasmine-core.rb",
|
||||
"lib/jasmine-core/boot/",
|
||||
"lib/jasmine-core/spec",
|
||||
"lib/jasmine-core/version.rb",
|
||||
"lib/jasmine-core/*.py",
|
||||
"sauce_connect.log"
|
||||
]
|
||||
}
|
||||
@@ -29,10 +29,10 @@ module.exports = {
|
||||
cwd: libJasmineCore("")
|
||||
},
|
||||
{
|
||||
src: [ "boot.js" ],
|
||||
src: [ "boot0.js", "boot1.js" ],
|
||||
dest: standaloneLibDir,
|
||||
expand: true,
|
||||
cwd: libJasmineCore("boot")
|
||||
cwd: libJasmineCore("")
|
||||
},
|
||||
{
|
||||
src: [ "SpecRunner.html" ],
|
||||
|
||||
@@ -37,12 +37,16 @@ module.exports = {
|
||||
],
|
||||
dest: 'lib/jasmine-core/jasmine.js'
|
||||
},
|
||||
boot: {
|
||||
src: ['lib/jasmine-core/boot/boot.js'],
|
||||
dest: 'lib/jasmine-core/boot.js'
|
||||
boot0: {
|
||||
src: ['src/boot/boot0.js'],
|
||||
dest: 'lib/jasmine-core/boot0.js'
|
||||
},
|
||||
boot1: {
|
||||
src: ['src/boot/boot1.js'],
|
||||
dest: 'lib/jasmine-core/boot1.js'
|
||||
},
|
||||
nodeBoot: {
|
||||
src: ['lib/jasmine-core/boot/node_boot.js'],
|
||||
src: ['src/boot/node_boot.js'],
|
||||
dest: 'lib/jasmine-core/node_boot.js'
|
||||
},
|
||||
options: {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
const sass = require('node-sass');
|
||||
const sass = require('sass');
|
||||
|
||||
module.exports = {
|
||||
options: {
|
||||
implementation: sass,
|
||||
outputStyle: 'compact',
|
||||
sourceComments: false
|
||||
},
|
||||
dist: {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
var grunt = require("grunt");
|
||||
|
||||
function gemLib(path) { return './lib/jasmine-core/' + path; }
|
||||
function nodeToRuby(version) { return version.replace('-', '.'); }
|
||||
|
||||
module.exports = {
|
||||
copyToGem: function() {
|
||||
var versionRb = grunt.template.process(
|
||||
grunt.file.read("grunt/templates/version.rb.jst"),
|
||||
{ data: { jasmineVersion: nodeToRuby(global.jasmineVersion) }});
|
||||
|
||||
grunt.file.write(gemLib("version.rb"), versionRb);
|
||||
}
|
||||
};
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/jasmine.js"></script>
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/jasmine-html.js"></script>
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/boot.js"></script>
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/boot0.js"></script>
|
||||
<!-- optional: include a file here that configures the Jasmine env -->
|
||||
<script src="lib/jasmine-<%= jasmineVersion %>/boot1.js"></script>
|
||||
|
||||
<!-- include source files here... -->
|
||||
<script src="src/Player.js"></script>
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#
|
||||
# DO NOT Edit this file. Canonical version of Jasmine lives in the repo's package.json. This file is generated
|
||||
# by a grunt task when the standalone release is built.
|
||||
#
|
||||
module Jasmine
|
||||
module Core
|
||||
VERSION = "<%= jasmineVersion %>"
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
$:.push File.expand_path("../lib", __FILE__)
|
||||
require "jasmine-core/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "jasmine-core"
|
||||
s.version = Jasmine::Core::VERSION
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["Gregg Van Hove"]
|
||||
s.summary = %q{JavaScript BDD framework}
|
||||
s.description = %q{Test your JavaScript without any framework dependencies, in any environment, and with a nice descriptive syntax.}
|
||||
s.email = %q{jasmine-js@googlegroups.com}
|
||||
s.homepage = "http://jasmine.github.io"
|
||||
s.license = "MIT"
|
||||
|
||||
s.files = Dir.glob("./lib/**/*")
|
||||
s.require_paths = ["lib"]
|
||||
s.add_development_dependency "rake"
|
||||
end
|
||||
@@ -1,15 +1,52 @@
|
||||
module.exports = require("./jasmine-core/jasmine.js");
|
||||
/**
|
||||
* Note: Only available on Node.
|
||||
* @module jasmine-core
|
||||
*/
|
||||
|
||||
const jasmineRequire = require('./jasmine-core/jasmine.js');
|
||||
module.exports = jasmineRequire;
|
||||
|
||||
/**
|
||||
* Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
|
||||
* @type {function}
|
||||
* @return {jasmine}
|
||||
*/
|
||||
module.exports.boot = require('./jasmine-core/node_boot.js');
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* 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 });
|
||||
jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
}
|
||||
|
||||
return jasmineInterface;
|
||||
};
|
||||
}());
|
||||
|
||||
var path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
var rootPath = path.join(__dirname, "jasmine-core"),
|
||||
bootFiles = ['boot.js'],
|
||||
bootFiles = ['boot0.js', 'boot1.js'],
|
||||
legacyBootFiles = ['boot.js'],
|
||||
nodeBootFiles = ['node_boot.js'],
|
||||
cssFiles = [],
|
||||
jsFiles = [],
|
||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, nodeBootFiles);
|
||||
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles, nodeBootFiles);
|
||||
|
||||
fs.readdirSync(rootPath).forEach(function(file) {
|
||||
if(fs.statSync(path.join(rootPath, file)).isFile()) {
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
module Jasmine
|
||||
module Core
|
||||
class << self
|
||||
def path
|
||||
File.join(File.dirname(__FILE__), "jasmine-core")
|
||||
end
|
||||
|
||||
def js_files
|
||||
(["jasmine.js"] + Dir.glob(File.join(path, "*.js"))).map { |f| File.basename(f) }.uniq - boot_files - node_boot_files
|
||||
end
|
||||
|
||||
SPEC_TYPES = ["core", "html", "node"]
|
||||
|
||||
def core_spec_files
|
||||
spec_files("core")
|
||||
end
|
||||
|
||||
def html_spec_files
|
||||
spec_files("html")
|
||||
end
|
||||
|
||||
def node_spec_files
|
||||
spec_files("node")
|
||||
end
|
||||
|
||||
def boot_files
|
||||
["boot.js"]
|
||||
end
|
||||
|
||||
def node_boot_files
|
||||
["node_boot.js"]
|
||||
end
|
||||
|
||||
def boot_dir
|
||||
path
|
||||
end
|
||||
|
||||
def spec_files(type)
|
||||
raise ArgumentError.new("Unrecognized spec type") unless SPEC_TYPES.include?(type)
|
||||
(Dir.glob(File.join(path, "spec", type, "*.js"))).map { |f| File.join("spec", type, File.basename(f)) }.uniq
|
||||
end
|
||||
|
||||
def css_files
|
||||
Dir.glob(File.join(path, "*.css")).map { |f| File.basename(f) }
|
||||
end
|
||||
|
||||
def images_dir
|
||||
File.join(File.dirname(__FILE__), '../images')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1 +0,0 @@
|
||||
from .core import Core
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2008-2020 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.
|
||||
*/
|
||||
/**
|
||||
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
|
||||
|
||||
The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
|
||||
|
||||
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||
*/
|
||||
var jasmine = jasmineRequire.core(jasmineRequire),
|
||||
global = jasmine.getGlobal();
|
||||
global.jasmine = jasmine;
|
||||
|
||||
/**
|
||||
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
||||
*/
|
||||
jasmineRequire.html(jasmine);
|
||||
|
||||
/**
|
||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||
*/
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## The Global Interface
|
||||
*
|
||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||
*/
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
/**
|
||||
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||
*/
|
||||
extend(global, jasmineInterface);
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
*
|
||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() { return window.location; }
|
||||
});
|
||||
|
||||
var filterSpecs = !!queryString.getParam("spec");
|
||||
|
||||
var config = {
|
||||
failFast: queryString.getParam("failFast"),
|
||||
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
|
||||
hideDisabled: queryString.getParam("hideDisabled")
|
||||
};
|
||||
|
||||
var random = queryString.getParam("random");
|
||||
|
||||
if (random !== undefined && random !== "") {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam("seed");
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
|
||||
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
|
||||
getContainer: function() { return document.body; },
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||
timer: new jasmine.Timer(),
|
||||
filterSpecs: filterSpecs
|
||||
});
|
||||
|
||||
/**
|
||||
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
|
||||
*/
|
||||
env.addReporter(jasmineInterface.jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() { return queryString.getParam("spec"); }
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
env.configure(config);
|
||||
|
||||
/**
|
||||
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
|
||||
*/
|
||||
window.setTimeout = window.setTimeout;
|
||||
window.setInterval = window.setInterval;
|
||||
window.clearTimeout = window.clearTimeout;
|
||||
window.clearInterval = window.clearInterval;
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
*
|
||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function for readability above.
|
||||
*/
|
||||
function extend(destination, source) {
|
||||
for (var property in source) destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
}());
|
||||
@@ -1,139 +0,0 @@
|
||||
/**
|
||||
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
|
||||
|
||||
The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
|
||||
|
||||
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||
*/
|
||||
var jasmine = jasmineRequire.core(jasmineRequire),
|
||||
global = jasmine.getGlobal();
|
||||
global.jasmine = jasmine;
|
||||
|
||||
/**
|
||||
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
||||
*/
|
||||
jasmineRequire.html(jasmine);
|
||||
|
||||
/**
|
||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||
*/
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## The Global Interface
|
||||
*
|
||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||
*/
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
/**
|
||||
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||
*/
|
||||
extend(global, jasmineInterface);
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
*
|
||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() { return window.location; }
|
||||
});
|
||||
|
||||
var filterSpecs = !!queryString.getParam("spec");
|
||||
|
||||
var config = {
|
||||
failFast: queryString.getParam("failFast"),
|
||||
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
|
||||
hideDisabled: queryString.getParam("hideDisabled")
|
||||
};
|
||||
|
||||
var random = queryString.getParam("random");
|
||||
|
||||
if (random !== undefined && random !== "") {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam("seed");
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
|
||||
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
|
||||
getContainer: function() { return document.body; },
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||
timer: new jasmine.Timer(),
|
||||
filterSpecs: filterSpecs
|
||||
});
|
||||
|
||||
/**
|
||||
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
|
||||
*/
|
||||
env.addReporter(jasmineInterface.jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() { return queryString.getParam("spec"); }
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
env.configure(config);
|
||||
|
||||
/**
|
||||
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
|
||||
*/
|
||||
window.setTimeout = window.setTimeout;
|
||||
window.setInterval = window.setInterval;
|
||||
window.clearTimeout = window.clearTimeout;
|
||||
window.clearInterval = window.clearInterval;
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
*
|
||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function for readability above.
|
||||
*/
|
||||
function extend(destination, source) {
|
||||
for (var property in source) destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
}());
|
||||
64
lib/jasmine-core/boot0.js
Normal file
64
lib/jasmine-core/boot0.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright (c) 2008-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.
|
||||
*/
|
||||
/**
|
||||
This file starts the process of "booting" Jasmine. It initializes Jasmine,
|
||||
makes its globals available, and creates the env. This file should be loaded
|
||||
after `jasmine.js` and `jasmine_html.js`, but before `boot1.js` or any project
|
||||
source files or spec files are loaded.
|
||||
*/
|
||||
(function() {
|
||||
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||
*/
|
||||
var jasmine = jasmineRequire.core(jasmineRequire),
|
||||
global = jasmine.getGlobal();
|
||||
global.jasmine = jasmine;
|
||||
|
||||
/**
|
||||
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
||||
*/
|
||||
jasmineRequire.html(jasmine);
|
||||
|
||||
/**
|
||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||
*/
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## The Global Interface
|
||||
*
|
||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||
*/
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
/**
|
||||
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||
*/
|
||||
for (var property in jasmineInterface) {
|
||||
global[property] = jasmineInterface[property];
|
||||
}
|
||||
})();
|
||||
132
lib/jasmine-core/boot1.js
Normal file
132
lib/jasmine-core/boot1.js
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
/**
|
||||
This file finishes 'booting' Jasmine, performing all of the necessary
|
||||
initialization before executing the loaded environment and all of a project's
|
||||
specs. This file should be loaded after `boot0.js` but before any project
|
||||
source files or spec files are loaded. Thus this file can also be used to
|
||||
customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can
|
||||
be customized directly. If you only wish to configure the Jasmine env, you
|
||||
can load another file that calls `jasmine.getEnv().configure({...})`
|
||||
after `boot0.js` is loaded and before this file is loaded.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
*
|
||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
|
||||
var filterSpecs = !!queryString.getParam('spec');
|
||||
|
||||
var config = {
|
||||
stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'),
|
||||
stopSpecOnExpectationFailure: queryString.getParam(
|
||||
'stopSpecOnExpectationFailure'
|
||||
),
|
||||
hideDisabled: queryString.getParam('hideDisabled')
|
||||
};
|
||||
|
||||
var random = queryString.getParam('random');
|
||||
|
||||
if (random !== undefined && random !== '') {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam('seed');
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) {
|
||||
return queryString.navigateWithNewParam(key, value);
|
||||
},
|
||||
addToExistingQueryString: function(key, value) {
|
||||
return queryString.fullStringWithNewParam(key, value);
|
||||
},
|
||||
getContainer: function() {
|
||||
return document.body;
|
||||
},
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
},
|
||||
timer: new jasmine.Timer(),
|
||||
filterSpecs: filterSpecs
|
||||
});
|
||||
|
||||
/**
|
||||
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
|
||||
*/
|
||||
env.addReporter(jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() {
|
||||
return queryString.getParam('spec');
|
||||
}
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
env.configure(config);
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
*
|
||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
};
|
||||
})();
|
||||
@@ -1,60 +0,0 @@
|
||||
import pkg_resources
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from ordereddict import OrderedDict
|
||||
|
||||
class Core(object):
|
||||
@classmethod
|
||||
def js_package(cls):
|
||||
return __package__
|
||||
|
||||
@classmethod
|
||||
def css_package(cls):
|
||||
return __package__
|
||||
|
||||
@classmethod
|
||||
def image_package(cls):
|
||||
return __package__ + ".images"
|
||||
|
||||
@classmethod
|
||||
def js_files(cls):
|
||||
js_files = sorted(list(filter(lambda x: '.js' in x, pkg_resources.resource_listdir(cls.js_package(), '.'))))
|
||||
|
||||
# jasmine.js needs to be first
|
||||
js_files.insert(0, 'jasmine.js')
|
||||
|
||||
# boot needs to be last
|
||||
js_files.remove('boot.js')
|
||||
js_files.append('boot.js')
|
||||
|
||||
return cls._uniq(js_files)
|
||||
|
||||
@classmethod
|
||||
def css_files(cls):
|
||||
return cls._uniq(sorted(filter(lambda x: '.css' in x, pkg_resources.resource_listdir(cls.css_package(), '.'))))
|
||||
|
||||
@classmethod
|
||||
def favicon(cls):
|
||||
return 'jasmine_favicon.png'
|
||||
|
||||
@classmethod
|
||||
def _uniq(self, items, idfun=None):
|
||||
# order preserving
|
||||
|
||||
if idfun is None:
|
||||
def idfun(x): return x
|
||||
seen = {}
|
||||
result = []
|
||||
for item in items:
|
||||
marker = idfun(item)
|
||||
# in old Python versions:
|
||||
# if seen.has_key(marker)
|
||||
# but in new ones:
|
||||
if marker in seen:
|
||||
continue
|
||||
|
||||
seen[marker] = 1
|
||||
result.append(item)
|
||||
return result
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2020 Pivotal Labs
|
||||
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
|
||||
@@ -72,6 +72,12 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
ResultsStateBuilder.prototype.jasmineDone = function(result) {
|
||||
if (result.failedExpectations) {
|
||||
this.failureCount += result.failedExpectations.length;
|
||||
}
|
||||
};
|
||||
|
||||
function HtmlReporter(options) {
|
||||
var config = function() {
|
||||
return (options.env && options.env.configuration()) || {};
|
||||
@@ -132,7 +138,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
if (result.status === 'failed') {
|
||||
failures.push(failureDom(result));
|
||||
}
|
||||
addDeprecationWarnings(result);
|
||||
addDeprecationWarnings(result, 'suite');
|
||||
};
|
||||
|
||||
this.specStarted = function(result) {
|
||||
@@ -168,7 +174,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
failures.push(failureDom(result));
|
||||
}
|
||||
|
||||
addDeprecationWarnings(result);
|
||||
addDeprecationWarnings(result, 'spec');
|
||||
};
|
||||
|
||||
this.displaySpecInCorrectFormat = function(result) {
|
||||
@@ -187,6 +193,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
};
|
||||
|
||||
this.jasmineDone = function(doneResult) {
|
||||
stateBuilder.jasmineDone(doneResult);
|
||||
var banner = find('.jasmine-banner');
|
||||
var alert = find('.jasmine-alert');
|
||||
var order = doneResult && doneResult.order;
|
||||
@@ -208,7 +215,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
' of ' +
|
||||
totalSpecsDefined +
|
||||
' specs - run all';
|
||||
var skippedLink = addToExistingQueryString('spec', '');
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
var skippedLink =
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('spec', '');
|
||||
alert.appendChild(
|
||||
createDom(
|
||||
'span',
|
||||
@@ -300,21 +310,47 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
} else {
|
||||
return prefix;
|
||||
}
|
||||
} else {
|
||||
} else if (failure.globalErrorType === 'afterAll') {
|
||||
return afterAllMessagePrefix + failure.message;
|
||||
} else {
|
||||
return failure.message;
|
||||
}
|
||||
}
|
||||
|
||||
addDeprecationWarnings(doneResult);
|
||||
|
||||
var warningBarClassName = 'jasmine-bar jasmine-warning';
|
||||
for (i = 0; i < deprecationWarnings.length; i++) {
|
||||
var warning = deprecationWarnings[i];
|
||||
var children = [],
|
||||
context;
|
||||
|
||||
switch (deprecationWarnings[i].runnableType) {
|
||||
case 'spec':
|
||||
context = '(in spec: ' + deprecationWarnings[i].runnableName + ')';
|
||||
break;
|
||||
case 'suite':
|
||||
context = '(in suite: ' + deprecationWarnings[i].runnableName + ')';
|
||||
break;
|
||||
default:
|
||||
context = '';
|
||||
}
|
||||
|
||||
deprecationWarnings[i].message.split('\n').forEach(function(line) {
|
||||
children.push(line);
|
||||
children.push(createDom('br'));
|
||||
});
|
||||
|
||||
children[0] = 'DEPRECATION: ' + children[0];
|
||||
children.push(context);
|
||||
|
||||
if (deprecationWarnings[i].stack) {
|
||||
children.push(createExpander(deprecationWarnings[i].stack));
|
||||
}
|
||||
|
||||
alert.appendChild(
|
||||
createDom(
|
||||
'span',
|
||||
{ className: warningBarClassName },
|
||||
'DEPRECATION: ' + warning
|
||||
{ className: 'jasmine-bar jasmine-warning' },
|
||||
children
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -407,9 +443,53 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
);
|
||||
}
|
||||
|
||||
if (result.debugLogs) {
|
||||
messages.appendChild(debugLogTable(result.debugLogs));
|
||||
}
|
||||
|
||||
return failure;
|
||||
}
|
||||
|
||||
function debugLogTable(debugLogs) {
|
||||
var tbody = createDom('tbody');
|
||||
|
||||
debugLogs.forEach(function(entry) {
|
||||
tbody.appendChild(
|
||||
createDom(
|
||||
'tr',
|
||||
{},
|
||||
createDom('td', {}, entry.timestamp.toString()),
|
||||
createDom('td', {}, entry.message)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-debug-log' },
|
||||
createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-debug-log-header' },
|
||||
'Debug logs'
|
||||
),
|
||||
createDom(
|
||||
'table',
|
||||
{},
|
||||
createDom(
|
||||
'thead',
|
||||
{},
|
||||
createDom(
|
||||
'tr',
|
||||
{},
|
||||
createDom('th', {}, 'Time (ms)'),
|
||||
createDom('th', {}, 'Message')
|
||||
)
|
||||
),
|
||||
tbody
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function summaryList(resultsTree, domParent) {
|
||||
var specListNode;
|
||||
for (var i = 0; i < resultsTree.children.length; i++) {
|
||||
@@ -542,17 +622,20 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
);
|
||||
|
||||
var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast');
|
||||
failFastCheckbox.checked = config.failFast;
|
||||
failFastCheckbox.checked = config.stopOnSpecFailure;
|
||||
failFastCheckbox.onclick = function() {
|
||||
navigateWithNewParam('failFast', !config.failFast);
|
||||
navigateWithNewParam('stopOnSpecFailure', !config.stopOnSpecFailure);
|
||||
};
|
||||
|
||||
var throwCheckbox = optionsMenuDom.querySelector(
|
||||
'#jasmine-throw-failures'
|
||||
);
|
||||
throwCheckbox.checked = config.oneFailurePerSpec;
|
||||
throwCheckbox.checked = config.stopSpecOnExpectationFailure;
|
||||
throwCheckbox.onclick = function() {
|
||||
navigateWithNewParam('throwFailures', !config.oneFailurePerSpec);
|
||||
navigateWithNewParam(
|
||||
'stopSpecOnExpectationFailure',
|
||||
!config.stopSpecOnExpectationFailure
|
||||
);
|
||||
};
|
||||
|
||||
var randomCheckbox = optionsMenuDom.querySelector(
|
||||
@@ -622,20 +705,55 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
suite = suite.parent;
|
||||
}
|
||||
|
||||
return addToExistingQueryString('spec', els.join(' '));
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
return (
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('spec', els.join(' '))
|
||||
);
|
||||
}
|
||||
|
||||
function addDeprecationWarnings(result) {
|
||||
function addDeprecationWarnings(result, runnableType) {
|
||||
if (result && result.deprecationWarnings) {
|
||||
for (var i = 0; i < result.deprecationWarnings.length; i++) {
|
||||
var warning = result.deprecationWarnings[i].message;
|
||||
if (!j$.util.arrayContains(warning)) {
|
||||
deprecationWarnings.push(warning);
|
||||
}
|
||||
deprecationWarnings.push({
|
||||
message: warning,
|
||||
stack: result.deprecationWarnings[i].stack,
|
||||
runnableName: result.fullName,
|
||||
runnableType: runnableType
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createExpander(stackTrace) {
|
||||
var expandLink = createDom('a', { href: '#' }, 'Show stack trace');
|
||||
var root = createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-expander' },
|
||||
expandLink,
|
||||
createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-expander-contents jasmine-stack-trace' },
|
||||
stackTrace
|
||||
)
|
||||
);
|
||||
|
||||
expandLink.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (root.classList.contains('jasmine-expanded')) {
|
||||
root.classList.remove('jasmine-expanded');
|
||||
expandLink.textContent = 'Show stack trace';
|
||||
} else {
|
||||
root.classList.add('jasmine-expanded');
|
||||
expandLink.textContent = 'Hide stack trace';
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
function find(selector) {
|
||||
return getContainer().querySelector('.jasmine_html-reporter ' + selector);
|
||||
}
|
||||
@@ -649,11 +767,23 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
function createDom(type, attrs, childrenVarArgs) {
|
||||
var el = createElement(type);
|
||||
function createDom(type, attrs, childrenArrayOrVarArgs) {
|
||||
var el = createElement(type),
|
||||
children,
|
||||
i;
|
||||
|
||||
for (var i = 2; i < arguments.length; i++) {
|
||||
var child = arguments[i];
|
||||
if (j$.isArray_(childrenArrayOrVarArgs)) {
|
||||
children = childrenArrayOrVarArgs;
|
||||
} else {
|
||||
children = [];
|
||||
|
||||
for (i = 2; i < arguments.length; i++) {
|
||||
children.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
|
||||
if (typeof child === 'string') {
|
||||
el.appendChild(createTextNode(child));
|
||||
@@ -682,11 +812,19 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function specHref(result) {
|
||||
return addToExistingQueryString('spec', result.fullName);
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
return (
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('spec', result.fullName)
|
||||
);
|
||||
}
|
||||
|
||||
function seedHref(seed) {
|
||||
return addToExistingQueryString('seed', seed);
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
return (
|
||||
(window.location.pathname || '') +
|
||||
addToExistingQueryString('seed', seed)
|
||||
);
|
||||
}
|
||||
|
||||
function defaultQueryString(key, value) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -1,489 +0,0 @@
|
||||
/*
|
||||
json2.js
|
||||
2014-02-04
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint evil: true, regexp: true */
|
||||
|
||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
if (typeof JSON !== 'object') {
|
||||
JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function () {
|
||||
|
||||
return isFinite(this.valueOf())
|
||||
? this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z'
|
||||
: null;
|
||||
};
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function () {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
var cx,
|
||||
escapable,
|
||||
gap,
|
||||
indent,
|
||||
meta,
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string'
|
||||
? c
|
||||
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
};
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
// because they can cause invocation, and '=' because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with ']' characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function'
|
||||
? walk({'': j}, '')
|
||||
: j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2020 Pivotal Labs
|
||||
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
|
||||
@@ -23,7 +23,7 @@ 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 env = jasmine.getEnv({ suppressLoadErrors: true });
|
||||
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#
|
||||
# DO NOT Edit this file. Canonical version of Jasmine lives in the repo's package.json. This file is generated
|
||||
# by a grunt task when the standalone release is built.
|
||||
#
|
||||
module Jasmine
|
||||
module Core
|
||||
VERSION = "3.6.0"
|
||||
end
|
||||
end
|
||||
56
package.json
56
package.json
@@ -1,51 +1,54 @@
|
||||
{
|
||||
"name": "jasmine-core",
|
||||
"license": "MIT",
|
||||
"version": "3.6.0",
|
||||
"version": "4.1.1",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jasmine/jasmine.git"
|
||||
},
|
||||
"keywords": [
|
||||
"test",
|
||||
"testing",
|
||||
"jasmine",
|
||||
"tdd",
|
||||
"bdd"
|
||||
],
|
||||
"scripts": {
|
||||
"posttest": "eslint \"src/**/*.js\" \"spec/**/*.js\" && prettier --check src/**/*.js spec/**/*.js",
|
||||
"posttest": "eslint \"src/**/*.js\" \"spec/**/*.js\" && prettier --check \"src/**/*.js\" \"spec/**/*.js\"",
|
||||
"test": "grunt --stack execSpecsInNode",
|
||||
"cleanup": "prettier --write src/**/*.js spec/**/*.js",
|
||||
"cleanup": "prettier --write \"src/**/*.js\" \"spec/**/*.js\"",
|
||||
"build": "grunt buildDistribution",
|
||||
"serve": "node spec/support/localJasmineBrowser.js",
|
||||
"serve:performance": "node spec/support/localJasmineBrowser.js jasmine-browser-performance.json",
|
||||
"ci": "node spec/support/ci.js",
|
||||
"ci:performance": "node spec/support/ci.js jasmine-browser-performance.json"
|
||||
},
|
||||
"description": "Official packaging of Jasmine's core files for use by Node.js projects.",
|
||||
"description": "Simple JavaScript testing framework for browsers and node.js",
|
||||
"homepage": "https://jasmine.github.io",
|
||||
"main": "./lib/jasmine-core.js",
|
||||
"files": [
|
||||
"MIT.LICENSE",
|
||||
"README.md",
|
||||
"images/*.{png,svg}",
|
||||
"lib/**/*.{js,css}",
|
||||
"package.json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"acorn": "^6.0.0",
|
||||
"ejs": "^2.5.5",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-compat": "^3.8.0",
|
||||
"express": "^4.16.4",
|
||||
"fast-check": "^1.21.0",
|
||||
"fast-glob": "^2.2.6",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-plugin-compat": "^4.0.0",
|
||||
"glob": "^7.2.0",
|
||||
"grunt": "^1.0.4",
|
||||
"grunt-cli": "^1.3.2",
|
||||
"grunt-contrib-compress": "^1.3.0",
|
||||
"grunt-contrib-concat": "^1.0.1",
|
||||
"grunt-contrib-compress": "^2.0.0",
|
||||
"grunt-contrib-concat": "^2.0.0",
|
||||
"grunt-css-url-embed": "^1.11.1",
|
||||
"grunt-sass": "^3.0.2",
|
||||
"jasmine": "^3.4.0",
|
||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser",
|
||||
"jsdom": "^15.0.0",
|
||||
"load-grunt-tasks": "^4.0.0",
|
||||
"node-sass": "^4.11.0",
|
||||
"jasmine": "github:jasmine/jasmine-npm#main",
|
||||
"jasmine-browser-runner": "github:jasmine/jasmine-browser#main",
|
||||
"jsdom": "^19.0.0",
|
||||
"load-grunt-tasks": "^5.1.0",
|
||||
"prettier": "1.17.1",
|
||||
"selenium-webdriver": "^3.6.0",
|
||||
"sass": "^1.45.1",
|
||||
"shelljs": "^0.8.3",
|
||||
"temp": "^0.9.0"
|
||||
},
|
||||
@@ -56,8 +59,13 @@
|
||||
"extends": [
|
||||
"plugin:compat/recommended"
|
||||
],
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es2017": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 5
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"rules": {
|
||||
"quotes": [
|
||||
@@ -73,6 +81,7 @@
|
||||
"args": "none"
|
||||
}
|
||||
],
|
||||
"no-implicit-globals": "error",
|
||||
"block-spacing": "error",
|
||||
"func-call-spacing": [
|
||||
"error",
|
||||
@@ -90,11 +99,10 @@
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
"Safari >= 8",
|
||||
"Safari >= 13",
|
||||
"last 2 Chrome versions",
|
||||
"last 2 Firefox versions",
|
||||
"Firefox 68",
|
||||
"last 2 Edge versions",
|
||||
"IE >= 10"
|
||||
"Firefox >= 68",
|
||||
"last 2 Edge versions"
|
||||
]
|
||||
}
|
||||
|
||||
57
release_notes/3.10.0.md
Normal file
57
release_notes/3.10.0.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Jasmine Core 3.10 Release Notes
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Added support for running Jasmine multiple times
|
||||
* If the env is configured with `autoCleanClosures: false`, then it can be
|
||||
executed repeatedly.
|
||||
* Merges #1934 from @nicojs
|
||||
* Fixes #1925
|
||||
|
||||
* Improved error message when an async expectation occurs after the spec
|
||||
finishes
|
||||
* Merges #1937 from @AndreWillomitzer
|
||||
* Fixes #1854
|
||||
|
||||
* Reject timeout values that are too large for setTimeout
|
||||
* See #1930
|
||||
|
||||
* Don't immediately move to the next queueable fn on async error
|
||||
|
||||
This allows assertion failures and other errors that occur after the async
|
||||
error to be routed to the correct spec/suite.
|
||||
|
||||
* Added a stringContaining asymmetric equality tester
|
||||
* Fixes #1923.
|
||||
|
||||
* The jasmine-core Ruby gem now prints a deprecation message when loaded unless
|
||||
the SUPPRESS_JASMINE_DEPRECATION environment variable is set.
|
||||
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Added discussion of max timeout value to jsdocs
|
||||
* Merges #1931 from @trusktr
|
||||
|
||||
* Added missing @since annotations
|
||||
|
||||
* Improved jsdocs for asymmetric equality testers
|
||||
|
||||
* Added a deprecation notice to the jasmine-core Ruby gem's description
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 3.10.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 10, 12, 14, 16 |
|
||||
| Safari | 8-14 |
|
||||
| Chrome | 94 |
|
||||
| Firefox | 93, 78, 68 |
|
||||
| Edge | 94 |
|
||||
| Internet Explorer | 10, 11 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
12
release_notes/3.10.1.md
Normal file
12
release_notes/3.10.1.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Jasmine Core 3.10.1 Release Notes
|
||||
|
||||
## Bugfixes
|
||||
|
||||
* Fixed missing pendingReason in pending spec results
|
||||
* Fixes [#1939](https://github.com/jasmine/jasmine/issues/1939)
|
||||
* Merges [#1940](https://github.com/jasmine/jasmine/pull/1940) from @jan-molak
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
80
release_notes/3.7.0.md
Normal file
80
release_notes/3.7.0.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# Jasmine Core 3.7 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a maintenance release of Jasmine with a number of new features and fixes.
|
||||
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Allow custom object formatters to be added in beforeAll
|
||||
- Fixes [#1876](http://github.com/jasmine/jasmine/issues/1876)
|
||||
|
||||
* Allow specs to disable Jasmine's global error handling by overwriting `onerror`.
|
||||
- Merges [#1860](https://github.com/jasmine/jasmine/pull/1860) from @greghuc
|
||||
|
||||
* Fixed comparison between URL objects
|
||||
- Fixes [#1866](http://github.com/jasmine/jasmine/issues/1866)
|
||||
|
||||
* Added support for stack traces created by `node --enable-source-maps`
|
||||
with tools like the Typescript compiler.
|
||||
- Merges [#1862](https://github.com/jasmine/jasmine/pull/1862) from @JannesMeyer
|
||||
|
||||
* Made properties added by createSpyObj() enumerable.
|
||||
- Merges [#1859](https://github.com/jasmine/jasmine/pull/1859) from DCtheTall
|
||||
- Fixes [#1837](http://github.com/jasmine/jasmine/issues/1837)
|
||||
|
||||
* Show the name of the spec/suite that caused a deprecation
|
||||
|
||||
* Warn if a spec or before/after function both takes a callback and returns a promise
|
||||
|
||||
* Don't overwrite MatchersUtil methods with ones that were added to
|
||||
`Array.prototype`, esp. `contains`
|
||||
- Fixes [#1849](http://github.com/jasmine/jasmine/issues/1849)
|
||||
|
||||
* Allow generator functions to be passed to `.and.callFake`
|
||||
- Fixes [#1848](http://github.com/jasmine/jasmine/issues/1848)
|
||||
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Fixed instructions for contributors to run Jasmine's ci script
|
||||
|
||||
* Updated supported Node versions in README
|
||||
|
||||
* Fixed script and CSS URLs in standalone example in README
|
||||
- Merges [#1839](https://github.com/jasmine/jasmine/pull/1839) from @snowman
|
||||
|
||||
* Fixed typo in asyncMatcher toBePending comment
|
||||
- Merges [#1847](https://github.com/jasmine/jasmine/pull/1847) from @SnailCoil
|
||||
|
||||
* Fixed link to custom object formatter tutorial
|
||||
|
||||
* Added jasmine.isSpy to the public interface
|
||||
- Fixes [#1880](http://github.com/jasmine/jasmine/issues/1880)
|
||||
|
||||
|
||||
|
||||
## Internal notes
|
||||
|
||||
* Fixed intermittent test failures
|
||||
|
||||
* Added additional assertions to tests for toBeTruthy and toBeFalsy
|
||||
- Merges [#1875](https://github.com/jasmine/jasmine/pull/1875) from @yasinkocak
|
||||
|
||||
* Pointed Travis badge at travis-ci.com, not .org
|
||||
|
||||
* Fixed file globs so that Prettier runs on all files
|
||||
|
||||
* Check for forgotten console and debugger statements
|
||||
|
||||
* Fixed code in Jasmine that will trigger deprecations in 3.99
|
||||
|
||||
* Use jasmine-browser from npm rather than from the main branch
|
||||
- The current released version now works with IE, so we no longer need to
|
||||
depend on main.
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
8
release_notes/3.7.1.md
Normal file
8
release_notes/3.7.1.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Jasmine Core 3.7.1 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a bug fix release of Jasmine. It's identical to 3.7.0 except that it
|
||||
correctly reports its version number. Please see the
|
||||
[3.7.0 release notes](https://github.com/jasmine/jasmine/blob/main/release_notes/3.7.0.md)
|
||||
if you're upgrading directly from 3.6.0 or earlier.
|
||||
132
release_notes/3.8.0.md
Normal file
132
release_notes/3.8.0.md
Normal file
@@ -0,0 +1,132 @@
|
||||
# Jasmine Core 3.8 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a maintenance release of Jasmine with a number of new features and fixes.
|
||||
|
||||
## Python deprecation
|
||||
|
||||
The Jasmine packages for Python are deprecated. We intend to continue releasing
|
||||
them through the end of the 3.x series, but after that they will be
|
||||
discontinued. We recommend migrating to the following alternatives:
|
||||
|
||||
* The [jasmine-browser-runner](https://github.com/jasmine/jasmine-browser)
|
||||
npm package to run specs in browsers, including headless Chrome and
|
||||
Saucelabs. This is the most direct replacement for the `jasmine server`
|
||||
and `jasmine ci` commands provided by the `jasmine` Python package.
|
||||
* The [jasmine](https://github.com/jasmine/jasmine-npm) npm package (
|
||||
`npm install jasmine`) to run specs under Node.js.
|
||||
* The standalone distribution from the
|
||||
[latest Jasmine release](https://github.com/jasmine/jasmine/releases) to
|
||||
run specs in browsers with no additional tools.
|
||||
* The [jasmine-core](https://github.com/jasmine/jasmine) npm package if all
|
||||
you need is the Jasmine assets. This is the direct equivalent of the
|
||||
jasmine-core Python package.
|
||||
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Fixed spec filtering in Karma
|
||||
* Merges [#1920](https://github.com/jasmine/jasmine/pull/1920) from @jlpstolwijk
|
||||
* Fixes [#1906](https://github.com/jasmine/jasmine/issues/1906)
|
||||
|
||||
* Added expectAsync(...).already
|
||||
* Causes async matchers to immediately fail if the promise is pending
|
||||
* See https://jasmine.github.io/api/3.8/async-matchers.html#already
|
||||
* Fixes [#1845](https://github.com/jasmine/jasmine/issues/1845)
|
||||
|
||||
* Include rejection details in failure messages for toBeResolved and toBeResolvedWith
|
||||
|
||||
* Fixed "stop spec on expectation failure" checkbox in standalone
|
||||
|
||||
* Added option for spyOnAllFunctions to include non-enumerable props
|
||||
* Makes spyOnAllFunctions work on instance methods of ES6 classes
|
||||
* Merges [#1909](https://github.com/jasmine/jasmine/pull/1909) from @Dari-k
|
||||
* Fixes [#1897](https://github.com/jasmine/jasmine/issues/1897)
|
||||
|
||||
* Added Spy#calls#thisFor
|
||||
* Provides the `this` value for a given spy call
|
||||
* Merges [#1903](https://github.com/jasmine/jasmine/pull/1903) from @ajvincent
|
||||
|
||||
* Improved handling of unhandled promise rejections with no error in Node
|
||||
* Fixes [#1759](https://github.com/jasmine/jasmine/issues/1759)
|
||||
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Updated package description
|
||||
|
||||
* Updated contributing guide
|
||||
|
||||
* Added TypeScript typings and jasmine-browser-runner to issue template
|
||||
|
||||
* Removed constructors from jsdocs of classes that aren't user-constructable
|
||||
|
||||
* Fixed config.seed type in jsdocs
|
||||
* Merges [#1892](https://github.com/jasmine/jasmine/pull/1892) from @UziTech
|
||||
|
||||
* Added jsdocs for the following:
|
||||
* asymmetric equality testers
|
||||
* Env#execute
|
||||
* Env#allowRespy
|
||||
* The public portion of Spec
|
||||
* Spy.callData.returnValue
|
||||
* Env#topSuite and Suite
|
||||
|
||||
* Added a jsdoc cross-reference from Configuration to its usage
|
||||
|
||||
* Added a note about correct usage of async matchers
|
||||
|
||||
* Added support for ArrayBuffers to matchersUtil.equals
|
||||
* Merges [#1891](https://github.com/jasmine/jasmine/pull/1892) from @Finesse
|
||||
* Merges [#1689](https://github.com/jasmine/jasmine/pull/1892) from @dankurka
|
||||
* Fixes [#1687](https://github.com/jasmine/jasmine/issues/1687)
|
||||
|
||||
|
||||
## Internal notes
|
||||
|
||||
* Fixed typo in spec name
|
||||
* Merges [#1918](https://github.com/jasmine/jasmine/pull/1918) from @eltociear
|
||||
|
||||
* Specify files to include in the NPM package rather than files to exclude
|
||||
|
||||
* Added test coverage for MatchersUtil#equals with typed arrays
|
||||
|
||||
* Removed checks for typed array support in the test suite
|
||||
* All supported browsers have all typed arrays except for Uint8ClampedArray,
|
||||
BigInt64Array, and BigUint64Array.
|
||||
|
||||
* Fixed test failures on IE 10
|
||||
|
||||
* Test matrix updates
|
||||
* Added Node 16
|
||||
* Added Safari 14
|
||||
* Added Firefox 78 (closest match to current ESR)
|
||||
* Removed Safari 10-12 to speed up CI. The newer and older versions we test
|
||||
provide a good measure of safety.
|
||||
|
||||
* Replaced node-sass dev dependency that isn't compatible with Node 16
|
||||
|
||||
* Removed unused dev dependencies
|
||||
|
||||
* Migrated CI from Travis to Circle
|
||||
|
||||
* Compensate for clock jitter in specs
|
||||
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 3.8.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 10, 12, 14, 16 |
|
||||
| Safari | 8-14 |
|
||||
| Chrome | 91 |
|
||||
| Firefox | 89, 68, 78 |
|
||||
| Edge | 91 |
|
||||
| Internet Explorer | 10, 11 |
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
65
release_notes/3.9.0.md
Normal file
65
release_notes/3.9.0.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Jasmine Core 3.9 Release Notes
|
||||
|
||||
## New features and bug fixes
|
||||
|
||||
* Fixed Trusted Types error in `j$.isError_` in Chromium-based browsers
|
||||
* Merges [#1921](https://github.com/jasmine/jasmine/pull/1921) from @bjarkler
|
||||
* Fixes [#1910](https://github.com/jasmine/jasmine/issues/1910)
|
||||
* Fixes [#1653](https://github.com/jasmine/jasmine/issues/1653)
|
||||
|
||||
* Better reporting of unhandled promise rejections with truthy but non-`Error`
|
||||
reasons on Node
|
||||
* `Env#execute` returns a promise in environments that support promises
|
||||
* Renamed `failFast` and `oneFailurePerSpec` config props to `stopOnSpecFailure`
|
||||
and `stopSpecOnExpectationFailure`
|
||||
|
||||
The new names are more self-explanatory and consistent with jasmine-npm. The
|
||||
old names are deprecated but will still work until the next major release.
|
||||
|
||||
* Split `boot.js` into two files to allow the env to be configured in between
|
||||
|
||||
This is mainly intended to support jasmine-browser-runner, which will load
|
||||
a script that configures the env in between the two boot files (`boot0.js` and
|
||||
`boot1.js`). The single-file `boot.js` will still be included until the next
|
||||
major release.
|
||||
|
||||
## Ruby deprecation
|
||||
|
||||
The Jasmine Ruby gems are deprecated. There will be no further releases after
|
||||
the end of the Jasmine 3.x series. We recommend that most users migrate to the
|
||||
[jasmine-browser-runner](https://github.com/jasmine/jasmine-browser)
|
||||
npm package, which is the direct replacement for the `jasmine` gem.
|
||||
|
||||
If `jasmine-browser-runner` doesn't meet your needs, one of these might:
|
||||
|
||||
* The [jasmine](https://github.com/jasmine/jasmine-npm) npm package to run
|
||||
specs in Node.js.
|
||||
* The [standalone distribution](https://github.com/jasmine/jasmine#installation)
|
||||
to run specs in browsers with no additional tools.
|
||||
* The [jasmine-core](https://github.com/jasmine/jasmine) npm package if all
|
||||
you need is the Jasmine assets. This is the direct equivalent of the
|
||||
`jasmine-core` Ruby gem.
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Added API docs for `Suite#id` and `Spec#id`
|
||||
* Marked `Env#hideDisabled` deprecated in jsdocs
|
||||
|
||||
|
||||
------
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 3.9.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 10, 12, 14, 16 |
|
||||
| Safari | 8-14 |
|
||||
| Chrome | 92 |
|
||||
| Firefox | 91, 78, 68 |
|
||||
| Edge | 92 |
|
||||
| Internet Explorer | 10, 11 |
|
||||
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
15
release_notes/3.99.0.md
Normal file
15
release_notes/3.99.0.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Jasmine Core 3.99.0 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release adds deprecation warnings for breaking changes that will be
|
||||
introduced in Jasmine 4.0. Please see the
|
||||
[migration guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0)
|
||||
for more information.
|
||||
|
||||
This is the last planned release of jasmine-core for Ruby or Python. Versions
|
||||
4.0 and later will be offered only via NPM and the standalone distribution.
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
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)_
|
||||
197
release_notes/4.0.0.md
Normal file
197
release_notes/4.0.0.md
Normal file
@@ -0,0 +1,197 @@
|
||||
# Jasmine Core 4.0.0 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a major release. In addition to new features and bug fixes it contains
|
||||
a number of breaking changes that are intended to diagnose common errors,
|
||||
improve awkward or outdated APIs, and make Jasmine easier to maintain
|
||||
and contribute to. If you're upgrading from Jasmine 3.x, we recommend installing
|
||||
3.99 and fixing any deprecation warnings that it emits before updating to 4.0.
|
||||
Please see the [migration guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0)
|
||||
for more information. If you use the `jasmine` or `jasmine-browser-runner` NPM
|
||||
packages, please read the release notes for those packages as well.
|
||||
|
||||
## Highlights
|
||||
|
||||
* Obsolete environments, most notably Internet Explorer, are no longer
|
||||
supported. Jasmine now expects to run in an environment that provides most
|
||||
of ES2017 and, in the case of Node, good interoperability between CommonJS
|
||||
modules and ES modules.
|
||||
|
||||
* The Jasmine packages for Ruby and Python have been discontinued.
|
||||
|
||||
* Errors in `beforeAll` and `beforeEach` functions are handled better.
|
||||
|
||||
* Jasmine can optionally be used without creating globals in Node.
|
||||
|
||||
* Certain common async testing bugs are now reported as errors.
|
||||
|
||||
* A new debug logging feature makes it easier to debug failing specs,
|
||||
particularly intermittent failures.
|
||||
|
||||
See details below.
|
||||
|
||||
## Breaking changes
|
||||
|
||||
### Changes to supported environments
|
||||
|
||||
The following previously supported environments are no longer supported:
|
||||
|
||||
* Internet Explorer
|
||||
* PhantomJS
|
||||
* Safari 8-13
|
||||
* Firefox 68 and 78
|
||||
* Node 10 and 12.0-12.16
|
||||
* Python
|
||||
* Ruby
|
||||
* Bower
|
||||
|
||||
Although Jasmine 4.0 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
|
||||
4.x releases.
|
||||
|
||||
The [`jasmine-browser-runner`](https://jasmine.github.io/setup/browser.html)
|
||||
NPM package is the direct replacement for the `jasmine` Ruby and Python
|
||||
packages.
|
||||
|
||||
### Changes that affect how specs are written
|
||||
|
||||
* When a `beforeAll` function fails in any way other than a failed expectation,
|
||||
Jasmine will not run the contents of the suite or any child suites except
|
||||
for any `afterAll` functions defined in the same suite as the failed
|
||||
`beforeAll` function. All affected specs will still be reported as failed.
|
||||
See [#1533](https://github.com/jasmine/jasmine/issues/1533).
|
||||
|
||||
* When a `beforeEach` function fails in any way other than a failed expectation,
|
||||
Jasmine will skip any subsequent `beforeEach` functions, the corresponding
|
||||
spec, and any `afterEach` functions defined in child suites. `afterEach`
|
||||
functions defined at the same or higher levels will still run. The spec will
|
||||
still be reported as failed. See [#1533](https://github.com/jasmine/jasmine/issues/1533).
|
||||
|
||||
* `MatchersUtil#contains` and the `toContain` matcher use deep equality rather
|
||||
than `===` to compare set members. This matches how arrays are handled but
|
||||
may cause some previously passing `.not.toContain()` expectations to fail.
|
||||
|
||||
* `jasmine.clock().mockDate()` throws if its argument is not a `Date`. Previous
|
||||
versions ignored non-`Date` arguments.
|
||||
|
||||
* Multiple calls to an asynchronous function's `done` callback are treated as
|
||||
errors.
|
||||
|
||||
* Any argument passed to a `done` callback (other than `undefined`) is treated
|
||||
as an error. Previous versions ignored any argument that wasn't an `Error`
|
||||
instance.
|
||||
|
||||
* Jasmine will report an error rather than a warning when a function tries to
|
||||
combine two different forms of async (e.g. taking a callback and also
|
||||
returning a promise).
|
||||
|
||||
* `this` in `describe` functions is no longer a `Suite` object.
|
||||
|
||||
* Empty suites are treated as errors.
|
||||
* Merges [#1742](https://github.com/jasmine/jasmine/pull/1742) from @johnjbarton
|
||||
|
||||
* The current time value does not decrease when `jasmine.clock().tick()` is
|
||||
called from a `setTimeout` or `setInterval` callback.
|
||||
* Merges [#1948](https://github.com/jasmine/jasmine/pull/1948) from @thw0rted
|
||||
* Fixes [#1929](https://github.com/jasmine/jasmine/issues/1929).
|
||||
|
||||
### Changes to how Jasmine is configured
|
||||
|
||||
* Individual configuration property getters and setters such as
|
||||
`Env#randomTests` and `Env#randomizeTests` have been removed. Use
|
||||
`Env#configuration` and `Env#configure` instead.
|
||||
|
||||
* The `failFast` and `oneFailurePerSpec` configuration properties have been
|
||||
removed. Use `stopOnSpecFailure` and `stopSpecOnExpectationFailure` instead.
|
||||
|
||||
* The `Promise` configuration property has been removed. Jasmine can still
|
||||
consume non-native promises but will always use the global `Promise` to
|
||||
create promises.
|
||||
|
||||
### Changes that affect custom matchers
|
||||
|
||||
* The old style of using custom equality testers, where matchers received them
|
||||
from Jasmine and had to pass them back to `matchersUtil` methods, is no longer
|
||||
supported.
|
||||
|
||||
* `matchersUtil` and `pp` are no longer available globally. Instead, use the
|
||||
instances that are passed to custom matcher factories and to `jasmineToString`.
|
||||
|
||||
See the [migration guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0)
|
||||
for more information about these changes and how to update custom matchers that
|
||||
use the old APIs.
|
||||
|
||||
### Changes that affect custom reporters
|
||||
|
||||
* The [`Suite`](https://jasmine.github.io/api/4.0/Suite.html) and
|
||||
[`Spec`](https://jasmine.github.io/api/4.0/Spec.html) objects returned from
|
||||
`describe`, `it`, and `Env#topSuite` no longer expose private APIs.
|
||||
|
||||
### Other breaking changes
|
||||
|
||||
* `boot.js` is no longer included. Use `boot0.js` and `boot1.js` instead.
|
||||
* Boot files in `lib/jasmine-core/boot` are no longer included in the NPM
|
||||
package. Use the boot files in `lib/jasmine-core` instead.
|
||||
* `json2.js` is no longer included, since all supported environments provide a
|
||||
JSON parser.
|
||||
|
||||
## Other new features and bug fixes
|
||||
|
||||
* Jasmine can optionally be used without creating globals in Node.js.
|
||||
* See https://jasmine.github.io/api/4.0/module-jasmine-core.html#.noGlobals
|
||||
* If you're using the `jasmine` package, see
|
||||
[its documentation](https://jasmine.github.io/api/npm/4.0/JasmineOptions.html#globals).
|
||||
* Fixes [#1235](https://github.com/jasmine/jasmine/issues/1235)
|
||||
|
||||
* Custom spy strategies are inherited from parent suites like other runnable
|
||||
resources.
|
||||
|
||||
* `pending()` can now be called from `beforeEach` functions.
|
||||
* Fixes [#1579](https://github.com/jasmine/jasmine/issues/1579)
|
||||
|
||||
* Removed duplicate message from errors (including. matcher failures) in
|
||||
V8-based environments.
|
||||
|
||||
* `Spy#withArgs` supports custom equality testers.
|
||||
* Fixes [#1836](https://github.com/jasmine/jasmine/issues/1836)
|
||||
|
||||
* The promise returned by `Env#execute` is resolved to the
|
||||
[jasmineDoneInfo](https://jasmine.github.io/api/4.0/global.html#JasmineDoneInfo).
|
||||
|
||||
* Fixed stack trace filtering on Safari 15.
|
||||
|
||||
* The HTML reporter includes top suite failures in the reported failure count.
|
||||
|
||||
* `afterAll` functions are run after a failure even if the `stopOnSpecFailure`
|
||||
config property is set.
|
||||
|
||||
* Added a debug logging feature to make it easier to debug failing specs.
|
||||
* Call `jasmine#debugLog` during spec execution to add a log entry.
|
||||
* If the spec fails, log entries are reported as part of the
|
||||
[specDone](https://jasmine.github.io/api/4.0/Reporter.html#specDone) reporter
|
||||
event.
|
||||
|
||||
* The HTML reporter no longer says that expectations occurring after the spec
|
||||
finishes are AfterAll errors.
|
||||
|
||||
## Documentation updates
|
||||
|
||||
* Added a [4.0 migration guide](https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0)
|
||||
|
||||
* Updated the README and contributing guide for 4.0
|
||||
|
||||
## Supported environments
|
||||
|
||||
jasmine-core 4.0.0 has been tested in the following environments.
|
||||
|
||||
| Environment | Supported versions |
|
||||
|-------------------|--------------------|
|
||||
| Node | 12.17+, 14, 16 |
|
||||
| Safari | 14-15 |
|
||||
| Chrome | 96 |
|
||||
| Firefox | 91, 95 |
|
||||
| Edge | 96 |
|
||||
------
|
||||
|
||||
_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)_
|
||||
@@ -1 +0,0 @@
|
||||
ordereddict==1.1
|
||||
38
scripts/run-all-browsers
Executable file
38
scripts/run-all-browsers
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
run_browser() {
|
||||
browser=$1
|
||||
version=$2
|
||||
description="$browser $version"
|
||||
if [ $version = "latest" ]; then
|
||||
version=""
|
||||
fi
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "Running $description"
|
||||
echo
|
||||
USE_SAUCE=true JASMINE_BROWSER=$browser SAUCE_BROWSER_VERSION=$version npm run ci
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "PASS: $description" >> "$passfile"
|
||||
else
|
||||
echo "FAIL: $description" >> "$failfile"
|
||||
fi
|
||||
}
|
||||
|
||||
passfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||
failfile=`mktemp -t jasmine-results.XXXXXX` || exit 1
|
||||
run_browser chrome latest
|
||||
run_browser firefox latest
|
||||
run_browser firefox 91
|
||||
run_browser safari 15
|
||||
run_browser safari 14
|
||||
run_browser MicrosoftEdge latest
|
||||
|
||||
echo
|
||||
cat "$passfile" "$failfile"
|
||||
|
||||
if [ -s "$failfile" ]; then
|
||||
exit 1
|
||||
fi
|
||||
37
scripts/start-sauce-connect
Executable file
37
scripts/start-sauce-connect
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
if [ $# -gt 1 -o "$1" = "--help" ]; then
|
||||
echo "Usage: $0 [pidfile]" 1>&2
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
pidfile=`mktemp`
|
||||
else
|
||||
pidfile="$1"
|
||||
fi
|
||||
|
||||
outfile=`mktemp`
|
||||
echo "Starting Sauce Connect"
|
||||
if [ -z "$SAUCE_TUNNEL_IDENTIFIER" ]; then
|
||||
sc -u "$SAUCE_USERNAME" -k "$SAUCE_ACCESS_KEY" -X 4445 --pidfile "$pidfile" 2>&1 | tee "$outfile" &
|
||||
else
|
||||
sc -u "$SAUCE_USERNAME" -k "$SAUCE_ACCESS_KEY" -X 4445 --pidfile "$pidfile" -i "$SAUCE_TUNNEL_IDENTIFIER" 2>&1 | tee "$outfile" &
|
||||
fi
|
||||
|
||||
while ! fgrep "Sauce Connect is up, you may start your tests." "$outfile" > /dev/null; do
|
||||
sleep 1
|
||||
|
||||
if ! ps -p $(cat "$pidfile") > /dev/null; then
|
||||
echo "Sauce Connect exited"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if ! nc -z localhost 4445; then
|
||||
echo "Can't connect to Sauce tunnel"
|
||||
killall sc
|
||||
exit 1
|
||||
fi
|
||||
33
scripts/stop-sauce-connect
Executable file
33
scripts/stop-sauce-connect
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 sauce-connect-pid" 1>&2
|
||||
exit
|
||||
fi
|
||||
|
||||
pid="$1"
|
||||
echo "PID: $pid"
|
||||
|
||||
echo "Stopping Sauce Connect"
|
||||
# Sauce Connect docs say that we can just kill -9 it if we don't care about
|
||||
# failing any ongoing sessions. In practice, that sometimes works but usually
|
||||
# leaks a tunnel so badly that you can't even stop it from the web UI.
|
||||
# Instead of doing that, we give Sauce Connect some time to shut down
|
||||
# gracefully and then give up.
|
||||
kill -INT $pid
|
||||
|
||||
# Wait up to 2 minutes, then give up if it's still running
|
||||
n=0
|
||||
while [ $n -lt 120 ] && ps -p $pid > /dev/null; do
|
||||
sleep 1
|
||||
kill -INT $pid 2> /dev/null || true
|
||||
n=$(($n + 1))
|
||||
done
|
||||
|
||||
if ps -p $pid > /dev/null; then
|
||||
echo "Could not shut down Sauce Connect"
|
||||
fi
|
||||
|
||||
exit $exitcode
|
||||
44
setup.py
44
setup.py
@@ -1,44 +0,0 @@
|
||||
from setuptools import setup, find_packages, os
|
||||
import json
|
||||
|
||||
with open('package.json') as packageFile:
|
||||
version = json.load(packageFile)['version']
|
||||
|
||||
setup(
|
||||
name="jasmine-core",
|
||||
version=version,
|
||||
url="http://jasmine.github.io",
|
||||
author="Pivotal Labs",
|
||||
author_email="jasmine-js@googlegroups.com",
|
||||
description=('Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on '+
|
||||
'browsers, DOM, or any JavaScript framework. Thus it\'s suited for websites, '+
|
||||
'Node.js (http://nodejs.org) projects, or anywhere that JavaScript can run.'),
|
||||
license='MIT',
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Environment :: Console',
|
||||
'Environment :: Web Environment',
|
||||
'Framework :: Django',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.2',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: Implementation :: PyPy',
|
||||
'Topic :: Internet :: WWW/HTTP',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
'Topic :: Software Development :: Build Tools',
|
||||
'Topic :: Software Development :: Quality Assurance',
|
||||
'Topic :: Software Development :: Testing',
|
||||
],
|
||||
|
||||
packages=['jasmine_core', 'jasmine_core.images'],
|
||||
package_dir={'jasmine_core': 'lib/jasmine-core', 'jasmine_core.images': 'images'},
|
||||
package_data={'jasmine_core': ['*.js', '*.css'], 'jasmine_core.images': ['*.png']},
|
||||
|
||||
include_package_data=True,
|
||||
|
||||
install_requires=['glob2>=0.4.1', 'ordereddict==1.1']
|
||||
)
|
||||
@@ -1,17 +1,25 @@
|
||||
module.exports = {
|
||||
"ignorePatterns": [
|
||||
"support/ci.js",
|
||||
"support/jasmine-browser.js"
|
||||
],
|
||||
ignorePatterns: ['support/ci.js', 'support/jasmine-browser.js'],
|
||||
rules: {
|
||||
// Relax rules for now to allow for the quirks of the test suite
|
||||
// TODO: We should probably remove these & fix the resulting errors
|
||||
"quotes": "off",
|
||||
"semi": "off",
|
||||
"key-spacing": "off",
|
||||
"space-before-blocks": "off",
|
||||
"no-unused-vars": "off",
|
||||
"no-trailing-spaces": "off",
|
||||
"block-spacing": "off",
|
||||
quotes: 'off',
|
||||
semi: 'off',
|
||||
'key-spacing': 'off',
|
||||
'space-before-blocks': 'off',
|
||||
'no-trailing-spaces': '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' }],
|
||||
|
||||
'no-var': 'error',
|
||||
|
||||
// Since linting is done at the end of the process and doesn't stop us
|
||||
// from running tests, it makes sense to fail if debugger statements
|
||||
// or console references are present.
|
||||
'no-debugger': 'error',
|
||||
'no-console': 'error'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('AsyncExpectation', function() {
|
||||
beforeEach(function() {
|
||||
jasmineUnderTest.Expectation.addAsyncCoreMatchers(
|
||||
@@ -6,24 +5,9 @@ describe('AsyncExpectation', function() {
|
||||
);
|
||||
});
|
||||
|
||||
describe('Factory', function() {
|
||||
it('throws an Error if promises are not available', function() {
|
||||
var thenable = { then: function() {} },
|
||||
options = { global: {}, actual: thenable };
|
||||
function f() {
|
||||
jasmineUnderTest.Expectation.asyncFactory(options);
|
||||
}
|
||||
expect(f).toThrowError(
|
||||
'expectAsync is unavailable because the environment does not support promises.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#not', function() {
|
||||
it('converts a pass to a fail', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.resolve(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
@@ -44,9 +28,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('converts a fail to a pass', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.reject(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
matchersUtil: new jasmineUnderTest.MatchersUtil({
|
||||
@@ -69,10 +51,9 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('propagates rejections from the comparison function', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
var error = new Error('ExpectationSpec failure');
|
||||
const error = new Error('ExpectationSpec failure');
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = dummyPromise(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
@@ -93,11 +74,9 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
describe('#withContext', function() {
|
||||
it('prepends the context to the generated failure message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
const matchersUtil = {
|
||||
pp: function(val) {
|
||||
return val.toString();
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
@@ -114,16 +93,15 @@ describe('AsyncExpectation', function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: failure message'
|
||||
message:
|
||||
'Some context: Expected a promise to be resolved but it was rejected with rejected.'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('prepends the context to a custom failure message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = {
|
||||
const matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
},
|
||||
@@ -144,7 +122,8 @@ describe('AsyncExpectation', function() {
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message:
|
||||
"Some context: Expected a promise to be resolved to 'a' but it was rejected."
|
||||
"Some context: Expected a promise to be resolved to 'a' " +
|
||||
"but it was rejected with 'b'."
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -152,9 +131,8 @@ describe('AsyncExpectation', 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');
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = {
|
||||
const matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
@@ -181,9 +159,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('works with #not', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.resolve(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
@@ -207,9 +183,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('works with #not and a custom message', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
const addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.resolve('a'),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
@@ -236,26 +210,20 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
describe('async matchers', function() {
|
||||
it('makes custom matchers available to this expectation', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var asyncMatchers = {
|
||||
const asyncMatchers = {
|
||||
toFoo: function() {},
|
||||
toBar: function() {}
|
||||
},
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: asyncMatchers
|
||||
});
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: asyncMatchers
|
||||
});
|
||||
|
||||
expect(expectation.toFoo).toBeDefined();
|
||||
expect(expectation.toBar).toBeDefined();
|
||||
});
|
||||
|
||||
it("wraps matchers's compare functions, passing in matcher dependencies", function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var fakeCompare = function() {
|
||||
const fakeCompare = function() {
|
||||
return Promise.resolve({ pass: true });
|
||||
},
|
||||
matcherFactory = jasmine
|
||||
@@ -267,30 +235,21 @@ describe('AsyncExpectation', function() {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
customEqualityTesters = ['a'],
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
matchersUtil: matchersUtil,
|
||||
customAsyncMatchers: matchers,
|
||||
customEqualityTesters: customEqualityTesters,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
matchersUtil: matchersUtil,
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
return expectation.toFoo('hello').then(function() {
|
||||
expect(matcherFactory).toHaveBeenCalledWith(
|
||||
matchersUtil,
|
||||
customEqualityTesters
|
||||
);
|
||||
expect(matcherFactory).toHaveBeenCalledWith(matchersUtil);
|
||||
});
|
||||
});
|
||||
|
||||
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var fakeCompare = jasmine
|
||||
const fakeCompare = jasmine
|
||||
.createSpy('fake-compare')
|
||||
.and.returnValue(Promise.resolve({ pass: true })),
|
||||
matchers = {
|
||||
@@ -304,14 +263,12 @@ describe('AsyncExpectation', function() {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
matchersUtil: matchersUtil,
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
matchersUtil: matchersUtil,
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
return expectation.toFoo('hello').then(function() {
|
||||
expect(fakeCompare).toHaveBeenCalledWith('an actual', 'hello');
|
||||
@@ -319,9 +276,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('reports a passing result to the spec when the comparison passes', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -334,14 +289,13 @@ describe('AsyncExpectation', function() {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
@@ -362,9 +316,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('reports a failing result to the spec when the comparison fails', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -379,14 +331,13 @@ describe('AsyncExpectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
@@ -407,9 +358,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('reports a failing result and a custom fail message to the spec when the comparison fails', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -422,14 +371,13 @@ describe('AsyncExpectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: 'an actual',
|
||||
customAsyncMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -449,9 +397,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('reports a failing result with a custom fail message function to the spec when the comparison fails', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -466,14 +412,13 @@ describe('AsyncExpectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -493,9 +438,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('reports a passing result to the spec when the comparison fails for a negative expectation', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -506,14 +449,13 @@ describe('AsyncExpectation', function() {
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -533,9 +475,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('reports a failing result to the spec when the comparison passes for a negative expectation', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -551,14 +491,13 @@ describe('AsyncExpectation', function() {
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
matchersUtil: matchersUtil,
|
||||
@@ -579,9 +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() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -595,14 +532,13 @@ describe('AsyncExpectation', function() {
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -622,9 +558,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it("reports a passing result to the spec when the 'not' comparison passes, given a negativeCompare", function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -638,14 +572,13 @@ describe('AsyncExpectation', function() {
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -665,9 +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() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -684,14 +615,13 @@ describe('AsyncExpectation', function() {
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
customAsyncMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -711,10 +641,8 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it('reports errorWithStack when a custom error message is returned', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var customError = new Error('I am a custom error');
|
||||
var matchers = {
|
||||
const customError = new Error('I am a custom error');
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -728,14 +656,13 @@ describe('AsyncExpectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: 'an actual',
|
||||
customAsyncMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -755,9 +682,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it("reports a custom message to the spec when a 'not' comparison fails", function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -770,14 +695,13 @@ describe('AsyncExpectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
const expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: 'an actual',
|
||||
customAsyncMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -797,9 +721,7 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
it("reports a custom message func to the spec when a 'not' comparison fails", function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -814,14 +736,13 @@ describe('AsyncExpectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
errorWithStack = new Error('errorWithStack'),
|
||||
expectation;
|
||||
errorWithStack = new Error('errorWithStack');
|
||||
|
||||
spyOn(jasmineUnderTest.util, 'errorWithStack').and.returnValue(
|
||||
errorWithStack
|
||||
);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
let expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: 'an actual',
|
||||
customAsyncMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -842,6 +763,6 @@ describe('AsyncExpectation', function() {
|
||||
});
|
||||
|
||||
function dummyPromise() {
|
||||
return new Promise(function(resolve, reject) {});
|
||||
return new Promise(function() {});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('CallTracker', 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);
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('CallTracker', 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);
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('CallTracker', 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: {}, args: [0, 'foo'] });
|
||||
@@ -30,14 +30,28 @@ describe('CallTracker', function() {
|
||||
expect(callTracker.argsFor(1)).toEqual([0, 'foo']);
|
||||
});
|
||||
|
||||
it("tracks the 'this' object from each execution", function() {
|
||||
const callTracker = new jasmineUnderTest.CallTracker();
|
||||
|
||||
const this0 = {},
|
||||
this1 = {};
|
||||
callTracker.track({ object: this0, args: [] });
|
||||
callTracker.track({ object: this1, args: [] });
|
||||
callTracker.track({ args: [] });
|
||||
|
||||
expect(callTracker.thisFor(0)).toBe(this0);
|
||||
expect(callTracker.thisFor(1)).toBe(this1);
|
||||
expect(callTracker.thisFor(2)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('returns any empty array when there was no call', function() {
|
||||
var callTracker = new jasmineUnderTest.CallTracker();
|
||||
const callTracker = new jasmineUnderTest.CallTracker();
|
||||
|
||||
expect(callTracker.argsFor(0)).toEqual([]);
|
||||
});
|
||||
|
||||
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: [0, 'foo'] });
|
||||
@@ -46,7 +60,7 @@ describe('CallTracker', 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: [0, 'foo'] });
|
||||
@@ -57,7 +71,7 @@ describe('CallTracker', 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({ object: {}, args: [0, 'foo'] });
|
||||
@@ -69,13 +83,13 @@ describe('CallTracker', 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();
|
||||
});
|
||||
|
||||
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'] });
|
||||
|
||||
@@ -83,13 +97,13 @@ describe('CallTracker', 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();
|
||||
});
|
||||
|
||||
it('allows the tracking to be reset', function() {
|
||||
var callTracker = new jasmineUnderTest.CallTracker();
|
||||
const callTracker = new jasmineUnderTest.CallTracker();
|
||||
|
||||
callTracker.track();
|
||||
callTracker.track({ object: {}, args: [0, 'foo'] });
|
||||
@@ -103,10 +117,10 @@ describe('CallTracker', function() {
|
||||
});
|
||||
|
||||
it('allows object arguments to be shallow cloned', function() {
|
||||
var callTracker = new jasmineUnderTest.CallTracker();
|
||||
const callTracker = new jasmineUnderTest.CallTracker();
|
||||
callTracker.saveArgumentsByValue();
|
||||
|
||||
var objectArg = { foo: 'bar' },
|
||||
const objectArg = { foo: 'bar' },
|
||||
arrayArg = ['foo', 'bar'];
|
||||
|
||||
callTracker.track({
|
||||
@@ -121,7 +135,7 @@ describe('CallTracker', 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];
|
||||
|
||||
callTracker.saveArgumentsByValue();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('ClearStack', function() {
|
||||
it('works in an integrationy way', function(done) {
|
||||
var clearStack = jasmineUnderTest.getClearStack(
|
||||
const clearStack = jasmineUnderTest.getClearStack(
|
||||
jasmineUnderTest.getGlobal()
|
||||
);
|
||||
|
||||
@@ -10,14 +10,14 @@ describe('ClearStack', function() {
|
||||
});
|
||||
|
||||
it('uses setImmediate when available', function() {
|
||||
var setImmediate = jasmine
|
||||
const setImmediate = jasmine
|
||||
.createSpy('setImmediate')
|
||||
.and.callFake(function(fn) {
|
||||
fn();
|
||||
}),
|
||||
global = { setImmediate: setImmediate },
|
||||
clearStack = jasmineUnderTest.getClearStack(global),
|
||||
called = false;
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
@@ -28,7 +28,7 @@ describe('ClearStack', function() {
|
||||
});
|
||||
|
||||
it('uses setTimeout instead of setImmediate every 10 calls to make sure we release the CPU', function() {
|
||||
var setImmediate = jasmine.createSpy('setImmediate'),
|
||||
const setImmediate = jasmine.createSpy('setImmediate'),
|
||||
setTimeout = jasmine.createSpy('setTimeout'),
|
||||
global = { setImmediate: setImmediate, setTimeout: setTimeout },
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
@@ -56,7 +56,7 @@ describe('ClearStack', function() {
|
||||
});
|
||||
|
||||
it('uses MessageChannels when available', function() {
|
||||
var fakeChannel = {
|
||||
const fakeChannel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: function() {
|
||||
@@ -69,8 +69,8 @@ describe('ClearStack', function() {
|
||||
return fakeChannel;
|
||||
}
|
||||
},
|
||||
clearStack = jasmineUnderTest.getClearStack(global),
|
||||
called = false;
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
@@ -80,7 +80,7 @@ describe('ClearStack', function() {
|
||||
});
|
||||
|
||||
it('uses setTimeout instead of MessageChannel every 10 calls to make sure we release the CPU', function() {
|
||||
var fakeChannel = {
|
||||
const fakeChannel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: jasmine
|
||||
@@ -122,7 +122,7 @@ describe('ClearStack', function() {
|
||||
});
|
||||
|
||||
it('calls setTimeout when onmessage is called recursively', function() {
|
||||
var fakeChannel = {
|
||||
const fakeChannel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: function() {
|
||||
@@ -149,12 +149,14 @@ describe('ClearStack', function() {
|
||||
});
|
||||
|
||||
it('falls back to setTimeout', function() {
|
||||
var setTimeout = jasmine.createSpy('setTimeout').and.callFake(function(fn) {
|
||||
fn();
|
||||
}),
|
||||
const setTimeout = jasmine
|
||||
.createSpy('setTimeout')
|
||||
.and.callFake(function(fn) {
|
||||
fn();
|
||||
}),
|
||||
global = { setTimeout: setTimeout },
|
||||
clearStack = jasmineUnderTest.getClearStack(global),
|
||||
called = false;
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
let called = false;
|
||||
|
||||
clearStack(function() {
|
||||
called = true;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
describe('Clock', function() {
|
||||
var NODE_JS =
|
||||
const NODE_JS =
|
||||
typeof process !== 'undefined' &&
|
||||
process.versions &&
|
||||
typeof process.versions.node === 'string';
|
||||
|
||||
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 },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
@@ -40,7 +40,7 @@ describe('Clock', 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 },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
@@ -76,7 +76,7 @@ describe('Clock', 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 },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
@@ -111,7 +111,7 @@ describe('Clock', 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 },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'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() {
|
||||
var originalFakeSetTimeout = function() {},
|
||||
const originalFakeSetTimeout = function() {},
|
||||
replacedSetTimeout = function() {},
|
||||
fakeGlobal = { setTimeout: originalFakeSetTimeout },
|
||||
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() {
|
||||
var originalFakeClearTimeout = function() {},
|
||||
const originalFakeClearTimeout = function() {},
|
||||
replacedClearTimeout = function() {},
|
||||
fakeGlobal = { clearTimeout: originalFakeClearTimeout },
|
||||
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() {
|
||||
var originalFakeSetInterval = function() {},
|
||||
const originalFakeSetInterval = function() {},
|
||||
replacedSetInterval = function() {},
|
||||
fakeGlobal = { setInterval: originalFakeSetInterval },
|
||||
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() {
|
||||
var originalFakeClearInterval = function() {},
|
||||
const originalFakeClearInterval = function() {},
|
||||
replacedClearInterval = function() {},
|
||||
fakeGlobal = { clearInterval: originalFakeClearInterval },
|
||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||
@@ -243,7 +243,7 @@ describe('Clock', 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'),
|
||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
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() {
|
||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||
@@ -312,8 +312,8 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
passedFunctionCalled = false;
|
||||
);
|
||||
let passedFunctionCalled = false;
|
||||
|
||||
clock.withMock(function() {
|
||||
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() {
|
||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||
@@ -372,8 +372,8 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
passedFunctionCalled = false;
|
||||
);
|
||||
let passedFunctionCalled = false;
|
||||
|
||||
expect(function() {
|
||||
clock.withMock(function() {
|
||||
@@ -409,7 +409,7 @@ describe('Clock', 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'),
|
||||
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||
@@ -451,7 +451,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('returns an id for the delayed function', function() {
|
||||
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||
scheduleId = 123,
|
||||
scheduleFunction = jasmine
|
||||
.createSpy('scheduleFunction')
|
||||
@@ -470,11 +470,10 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
timeout;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
timeout = clock.setTimeout(delayedFn, 0);
|
||||
const timeout = clock.setTimeout(delayedFn, 0);
|
||||
|
||||
if (!NODE_JS) {
|
||||
expect(timeout).toEqual(123);
|
||||
@@ -484,7 +483,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('clears the scheduled function with the scheduler', function() {
|
||||
var fakeClearTimeout = jasmine.createSpy('clearTimeout'),
|
||||
const fakeClearTimeout = jasmine.createSpy('clearTimeout'),
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
['removeFunctionWithId']
|
||||
@@ -513,7 +512,7 @@ describe('Clock', 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'),
|
||||
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
||||
fakeGlobal = { setInterval: fakeSetInterval },
|
||||
@@ -556,7 +555,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('returns an id for the delayed function', function() {
|
||||
var fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||
const fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||
scheduleId = 123,
|
||||
scheduleFunction = jasmine
|
||||
.createSpy('scheduleFunction')
|
||||
@@ -575,11 +574,10 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
interval;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
interval = clock.setInterval(delayedFn, 0);
|
||||
const interval = clock.setInterval(delayedFn, 0);
|
||||
|
||||
if (!NODE_JS) {
|
||||
expect(interval).toEqual(123);
|
||||
@@ -589,7 +587,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('clears the scheduled function with the scheduler', function() {
|
||||
var clearInterval = jasmine.createSpy('clearInterval'),
|
||||
const clearInterval = jasmine.createSpy('clearInterval'),
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
['removeFunctionWithId']
|
||||
@@ -618,7 +616,7 @@ describe('Clock', 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'])
|
||||
);
|
||||
@@ -630,7 +628,7 @@ describe('Clock', function() {
|
||||
|
||||
describe('Clock (acceptance)', function() {
|
||||
it('can run setTimeouts/setIntervals synchronously', function() {
|
||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||
delayedFn3 = jasmine.createSpy('delayedFn3'),
|
||||
recurring1 = jasmine.createSpy('recurring1'),
|
||||
@@ -651,7 +649,7 @@ describe('Clock (acceptance)', function() {
|
||||
clock.install();
|
||||
|
||||
clock.setTimeout(delayedFn1, 0);
|
||||
var intervalId = clock.setInterval(recurring1, 50);
|
||||
const intervalId = clock.setInterval(recurring1, 50);
|
||||
clock.setTimeout(delayedFn2, 100);
|
||||
clock.setTimeout(delayedFn3, 200);
|
||||
|
||||
@@ -690,7 +688,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('can clear a previously set timeout', function() {
|
||||
var clearedFn = jasmine.createSpy('clearedFn'),
|
||||
const clearedFn = jasmine.createSpy('clearedFn'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
install: function() {},
|
||||
@@ -703,12 +701,11 @@ describe('Clock (acceptance)', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
timeoutId;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
|
||||
timeoutId = clock.setTimeout(clearedFn, 100);
|
||||
const timeoutId = clock.setTimeout(clearedFn, 100);
|
||||
expect(clearedFn).not.toHaveBeenCalled();
|
||||
|
||||
clock.clearTimeout(timeoutId);
|
||||
@@ -718,7 +715,7 @@ describe('Clock (acceptance)', 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(),
|
||||
mockDate = {
|
||||
install: function() {},
|
||||
@@ -731,12 +728,11 @@ describe('Clock (acceptance)', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
intervalId;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
|
||||
intervalId = clock.setInterval(function() {
|
||||
const intervalId = clock.setInterval(function() {
|
||||
spy();
|
||||
clock.clearInterval(intervalId);
|
||||
}, 100);
|
||||
@@ -746,7 +742,7 @@ describe('Clock (acceptance)', 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(),
|
||||
mockDate = {
|
||||
install: function() {},
|
||||
@@ -772,7 +768,7 @@ describe('Clock (acceptance)', 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'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
@@ -803,7 +799,7 @@ describe('Clock (acceptance)', 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'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
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() {
|
||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
@@ -865,7 +861,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('does not mock the Date object by default', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -880,7 +876,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
expect(global.Date).toEqual(Date);
|
||||
|
||||
var now = new global.Date().getTime();
|
||||
const now = new global.Date().getTime();
|
||||
|
||||
clock.tick(50);
|
||||
|
||||
@@ -888,7 +884,7 @@ describe('Clock (acceptance)', 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 },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -901,13 +897,13 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install().mockDate();
|
||||
|
||||
var now = new global.Date().getTime();
|
||||
const now = new global.Date().getTime();
|
||||
|
||||
clock.tick(50);
|
||||
|
||||
expect(new global.Date().getTime() - now).toEqual(50);
|
||||
|
||||
var timeoutDate = 0;
|
||||
let timeoutDate = 0;
|
||||
clock.setTimeout(function() {
|
||||
timeoutDate = new global.Date().getTime();
|
||||
}, 100);
|
||||
@@ -918,7 +914,7 @@ describe('Clock (acceptance)', 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 },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -932,7 +928,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install().mockDate(baseTime);
|
||||
|
||||
var now = new global.Date().getTime();
|
||||
const now = new global.Date().getTime();
|
||||
|
||||
expect(now).toEqual(baseTime.getTime());
|
||||
|
||||
@@ -940,7 +936,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
expect(new global.Date().getTime()).toEqual(baseTime.getTime() + 50);
|
||||
|
||||
var timeoutDate = 0;
|
||||
let timeoutDate = 0;
|
||||
clock.setTimeout(function() {
|
||||
timeoutDate = new global.Date().getTime();
|
||||
}, 100);
|
||||
@@ -950,8 +946,26 @@ describe('Clock (acceptance)', function() {
|
||||
expect(timeoutDate).toEqual(baseTime.getTime() + 150);
|
||||
});
|
||||
|
||||
it('throws mockDate is called with a non-Date', function() {
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
{ setTimeout: setTimeout },
|
||||
function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
);
|
||||
|
||||
expect(() => clock.mockDate(12345)).toThrowError(
|
||||
'The argument to jasmine.clock().mockDate(), if specified, should be ' +
|
||||
'a Date instance.'
|
||||
);
|
||||
});
|
||||
|
||||
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 },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -965,8 +979,8 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install().mockDate(baseTime);
|
||||
|
||||
var actualTimes = [];
|
||||
var pushCurrentTime = function() {
|
||||
const actualTimes = [];
|
||||
const pushCurrentTime = function() {
|
||||
actualTimes.push(global.Date().getTime());
|
||||
};
|
||||
delayedFunctionScheduler.scheduleFunction(pushCurrentTime);
|
||||
@@ -990,7 +1004,7 @@ describe('Clock (acceptance)', 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 },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -1003,7 +1017,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install();
|
||||
|
||||
var timerId2;
|
||||
let timerId2;
|
||||
|
||||
global.setTimeout(function() {
|
||||
global.clearTimeout(timerId2);
|
||||
@@ -1015,7 +1029,7 @@ describe('Clock (acceptance)', 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 },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -1028,7 +1042,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install();
|
||||
|
||||
var timerId2;
|
||||
let timerId2;
|
||||
global.setInterval(function() {
|
||||
global.clearInterval(timerId2);
|
||||
}, 100);
|
||||
|
||||
131
spec/core/CompleteOnFirstErrorSkipPolicySpec.js
Normal file
131
spec/core/CompleteOnFirstErrorSkipPolicySpec.js
Normal file
@@ -0,0 +1,131 @@
|
||||
describe('CompleteOnFirstErrorSkipPolicy', function() {
|
||||
describe('#skipTo', function() {
|
||||
describe('Before anything has errored', function() {
|
||||
it('returns the next index', function() {
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
arrayOfArbitraryFns(4),
|
||||
4
|
||||
);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('After something has errored', function() {
|
||||
it('skips non cleanup fns', function() {
|
||||
const fns = arrayOfArbitraryFns(4);
|
||||
fns[2].type = arbitraryCleanupType();
|
||||
fns[3].type = arbitraryCleanupType();
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
|
||||
for (const type of ['afterEach', 'specCleanup', 'afterAll']) {
|
||||
it(`does not skip ${type} fns`, function() {
|
||||
const fns = arrayOfArbitraryFns(2);
|
||||
fns[1].type = type;
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
fns
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(1);
|
||||
});
|
||||
}
|
||||
|
||||
describe('When the error was in a beforeEach fn', function() {
|
||||
it('runs cleanup fns defined by the current and containing suites', function() {
|
||||
const parentSuite = { description: 'parentSuite' };
|
||||
const suite = { description: 'suite', parentSuite };
|
||||
const fns = [
|
||||
{
|
||||
suite: suite
|
||||
},
|
||||
{
|
||||
fn: () => {}
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: suite,
|
||||
type: arbitraryCleanupType()
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: parentSuite,
|
||||
type: arbitraryCleanupType()
|
||||
}
|
||||
];
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
fns
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
});
|
||||
|
||||
it('skips cleanup fns defined by nested suites', function() {
|
||||
const parentSuite = { description: 'parentSuite' };
|
||||
const suite = { description: 'suite', parentSuite };
|
||||
const fns = [
|
||||
{
|
||||
fn: () => {},
|
||||
type: 'beforeEach',
|
||||
suite: parentSuite
|
||||
},
|
||||
{
|
||||
fn: () => {}
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: suite,
|
||||
type: arbitraryCleanupType()
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: parentSuite,
|
||||
type: arbitraryCleanupType()
|
||||
}
|
||||
];
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
fns
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not skip cleanup fns that have no suite, such as the spec complete fn', function() {
|
||||
const fns = [
|
||||
{ fn: () => {} },
|
||||
{
|
||||
fn: () => {},
|
||||
type: arbitraryCleanupType()
|
||||
}
|
||||
];
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function arrayOfArbitraryFns(n) {
|
||||
const result = [];
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
result.push({ fn: () => {} });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function arbitraryCleanupType() {
|
||||
return 'specCleanup';
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('DelayedFunctionScheduler', function() {
|
||||
it('schedules a function for later execution', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn');
|
||||
|
||||
scheduler.scheduleFunction(fn, 0);
|
||||
@@ -13,7 +13,7 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('schedules a string for later execution', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
strfn = 'horrible = true;';
|
||||
|
||||
scheduler.scheduleFunction(strfn, 0);
|
||||
@@ -24,7 +24,7 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('#tick defaults to 0', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn');
|
||||
|
||||
scheduler.scheduleFunction(fn, 0);
|
||||
@@ -37,7 +37,7 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('defaults delay to 0', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn');
|
||||
|
||||
scheduler.scheduleFunction(fn);
|
||||
@@ -50,7 +50,7 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('optionally passes params to scheduled functions', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn');
|
||||
|
||||
scheduler.scheduleFunction(fn, 0, ['foo', 'bar']);
|
||||
@@ -63,7 +63,7 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('scheduled fns can optionally reoccur', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn');
|
||||
|
||||
scheduler.scheduleFunction(fn, 20, [], true);
|
||||
@@ -84,7 +84,7 @@ describe('DelayedFunctionScheduler', 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(2);
|
||||
@@ -95,11 +95,9 @@ describe('DelayedFunctionScheduler', 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'),
|
||||
timeoutKey;
|
||||
|
||||
timeoutKey = scheduler.scheduleFunction(fn, 0);
|
||||
timeoutKey = scheduler.scheduleFunction(fn, 0);
|
||||
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
|
||||
@@ -111,15 +109,15 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('executes recurring functions interleaved with regular functions in the correct order', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn'),
|
||||
recurringCallCount = 0,
|
||||
recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
||||
recurringCallCount++;
|
||||
if (recurringCallCount < 5) {
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler();
|
||||
const fn = jasmine.createSpy('fn');
|
||||
let recurringCallCount = 0;
|
||||
const recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
||||
recurringCallCount++;
|
||||
if (recurringCallCount < 5) {
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
|
||||
scheduler.scheduleFunction(recurring, 10, [], true);
|
||||
scheduler.scheduleFunction(fn, 50);
|
||||
@@ -132,7 +130,7 @@ describe('DelayedFunctionScheduler', 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'),
|
||||
fnDelay = 10;
|
||||
|
||||
@@ -148,10 +146,10 @@ describe('DelayedFunctionScheduler', 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'),
|
||||
fnDelay = 10,
|
||||
timeoutKey;
|
||||
fnDelay = 10;
|
||||
let timeoutKey;
|
||||
|
||||
scheduler.scheduleFunction(function() {
|
||||
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() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn'),
|
||||
recurringCallCount = 0,
|
||||
recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
||||
recurringCallCount++;
|
||||
if (recurringCallCount < 5) {
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
}
|
||||
}),
|
||||
innerFn = jasmine.createSpy('innerFn').and.callFake(function() {
|
||||
expect(recurring.calls.count()).toBe(4);
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler();
|
||||
const fn = jasmine.createSpy('fn');
|
||||
let recurringCallCount = 0;
|
||||
const recurring = jasmine.createSpy('recurring').and.callFake(function() {
|
||||
recurringCallCount++;
|
||||
if (recurringCallCount < 5) {
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
}),
|
||||
scheduling = jasmine.createSpy('scheduling').and.callFake(function() {
|
||||
expect(recurring.calls.count()).toBe(3);
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
scheduler.scheduleFunction(innerFn, 10); // 41ms absolute
|
||||
});
|
||||
}
|
||||
});
|
||||
const innerFn = jasmine.createSpy('innerFn').and.callFake(function() {
|
||||
expect(recurring.calls.count()).toBe(4);
|
||||
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(fn, 50);
|
||||
@@ -199,7 +197,7 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('executes recurring functions after rescheduling them', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
recurring = function() {
|
||||
expect(scheduler.scheduleFunction).toHaveBeenCalled();
|
||||
};
|
||||
@@ -212,11 +210,11 @@ describe('DelayedFunctionScheduler', 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'),
|
||||
spyAndRemove = jasmine.createSpy('fn'),
|
||||
fnDelay = 10,
|
||||
timeoutKey;
|
||||
fnDelay = 10;
|
||||
let timeoutKey;
|
||||
|
||||
spyAndRemove.and.callFake(function() {
|
||||
scheduler.removeFunctionWithId(timeoutKey);
|
||||
@@ -233,10 +231,10 @@ describe('DelayedFunctionScheduler', 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'),
|
||||
fnDelay = 10,
|
||||
timeoutKey;
|
||||
fnDelay = 10;
|
||||
let timeoutKey;
|
||||
|
||||
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
|
||||
scheduler.scheduleFunction(function() {
|
||||
@@ -252,7 +250,7 @@ describe('DelayedFunctionScheduler', 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'),
|
||||
fnDelay = 10;
|
||||
|
||||
@@ -267,7 +265,7 @@ describe('DelayedFunctionScheduler', function() {
|
||||
});
|
||||
|
||||
it('updates the mockDate per scheduled time', function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
tickDate = jasmine.createSpy('tickDate');
|
||||
|
||||
scheduler.scheduleFunction(function() {});
|
||||
@@ -278,4 +276,58 @@ describe('DelayedFunctionScheduler', function() {
|
||||
expect(tickDate).toHaveBeenCalledWith(0);
|
||||
expect(tickDate).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
describe('ticking inside a scheduled function', function() {
|
||||
let clock;
|
||||
|
||||
// Runner function calls the callback until it returns false
|
||||
function runWork(workCallback) {
|
||||
while (workCallback()) {}
|
||||
}
|
||||
|
||||
// Make a worker that takes a little time and tracks when it finished
|
||||
function mockWork(times) {
|
||||
return () => {
|
||||
clock.tick(1);
|
||||
const now = new Date().getTime();
|
||||
expect(lastWork)
|
||||
.withContext('Previous function calls should always be in the past')
|
||||
.toBeLessThan(now);
|
||||
lastWork = now;
|
||||
times--;
|
||||
return times > 0;
|
||||
};
|
||||
}
|
||||
let lastWork = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
clock = jasmineUnderTest.getEnv().clock;
|
||||
clock.install();
|
||||
clock.mockDate(new Date(1));
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
jasmineUnderTest.getEnv().clock.uninstall();
|
||||
});
|
||||
|
||||
it('preserves monotonically-increasing current time', () => {
|
||||
const work1 = mockWork(3);
|
||||
setTimeout(() => {
|
||||
runWork(work1);
|
||||
}, 1);
|
||||
clock.tick(1);
|
||||
expect(lastWork)
|
||||
.withContext('tick should advance past last-scheduled function')
|
||||
.toBeLessThanOrEqual(new Date().getTime());
|
||||
|
||||
const work2 = mockWork(3);
|
||||
setTimeout(() => {
|
||||
runWork(work2);
|
||||
}, 1);
|
||||
clock.tick(1);
|
||||
expect(lastWork)
|
||||
.withContext('tick should advance past last-scheduled function')
|
||||
.toBeLessThanOrEqual(new Date().getTime());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
328
spec/core/DeprecatorSpec.js
Normal file
328
spec/core/DeprecatorSpec.js
Normal file
@@ -0,0 +1,328 @@
|
||||
/* eslint no-console: 0 */
|
||||
describe('Deprecator', function() {
|
||||
describe('#deprecate', function() {
|
||||
beforeEach(function() {
|
||||
spyOn(console, 'error');
|
||||
});
|
||||
|
||||
it('logs the mesage without context when the runnable is the top suite', function() {
|
||||
const runnable = { addDeprecationWarning: function() {} };
|
||||
const deprecator = new jasmineUnderTest.Deprecator(runnable);
|
||||
deprecator.verboseDeprecations(true);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
omitStackTrace: true
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith('DEPRECATION: the message');
|
||||
});
|
||||
|
||||
it('logs the message in a descendant suite', function() {
|
||||
const runnable = {
|
||||
addDeprecationWarning: function() {},
|
||||
getFullName: function() {
|
||||
return 'the suite';
|
||||
},
|
||||
children: []
|
||||
};
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
deprecator.verboseDeprecations(true);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
omitStackTrace: true
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'DEPRECATION: the message (in suite: the suite)'
|
||||
);
|
||||
});
|
||||
|
||||
it('logs and reports the message in a spec', function() {
|
||||
const runnable = {
|
||||
addDeprecationWarning: function() {},
|
||||
getFullName: function() {
|
||||
return 'the spec';
|
||||
}
|
||||
};
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
deprecator.verboseDeprecations(true);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
omitStackTrace: true
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'DEPRECATION: the message (in spec: the spec)'
|
||||
);
|
||||
});
|
||||
|
||||
it('logs and reports the message without runnable info when ignoreRunnable is true', function() {
|
||||
const topSuite = jasmine.createSpyObj('topSuite', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
const deprecator = new jasmineUnderTest.Deprecator(topSuite);
|
||||
const runnable = jasmine.createSpyObj('spec', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
runnable.getFullName.and.returnValue('a spec');
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
ignoreRunnable: true
|
||||
});
|
||||
|
||||
expect(topSuite.addDeprecationWarning).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
);
|
||||
expect(runnable.addDeprecationWarning).not.toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/the message/)
|
||||
);
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/a spec/)
|
||||
);
|
||||
});
|
||||
|
||||
describe('with no options', function() {
|
||||
it('includes the stack trace', function() {
|
||||
testStackTrace(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it('omits the stack trace when omitStackTrace is true', function() {
|
||||
testNoStackTrace({ omitStackTrace: true });
|
||||
});
|
||||
|
||||
it('includes the stack trace when omitStackTrace is false', function() {
|
||||
testStackTrace({ omitStackTrace: false });
|
||||
});
|
||||
|
||||
it('includes the stack trace when omitStackTrace is undefined', function() {
|
||||
testStackTrace({ includeStackTrace: undefined });
|
||||
});
|
||||
|
||||
it('emits the deprecation only once when verboseDeprecations is not set', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable1 = jasmine.createSpyObj('runnable1', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
const runnable2 = jasmine.createSpyObj('runnable2', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable2, 'the message');
|
||||
|
||||
expect(runnable1.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(runnable2.addDeprecationWarning).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits the deprecation only once when verboseDeprecations is false', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable1 = jasmine.createSpyObj('runnable1', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
const runnable2 = jasmine.createSpyObj('runnable2', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.verboseDeprecations(false);
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable2, 'the message');
|
||||
|
||||
expect(runnable1.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(runnable2.addDeprecationWarning).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits the deprecation for each call when verboseDeprecations is true', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable1 = jasmine.createSpyObj('runnable1', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
const runnable2 = jasmine.createSpyObj('runnable2', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.verboseDeprecations(true);
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable2, 'the message');
|
||||
|
||||
expect(runnable1.addDeprecationWarning).toHaveBeenCalledTimes(2);
|
||||
expect(runnable2.addDeprecationWarning).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('includes a note about verboseDeprecations', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message');
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).toContain(verboseDeprecationsNote());
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain(
|
||||
verboseDeprecationsNote()
|
||||
);
|
||||
});
|
||||
|
||||
it('omits the note about verboseDeprecations when verboseDeprecations is true', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.verboseDeprecations(true);
|
||||
deprecator.addDeprecationWarning(runnable, 'the message');
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).not.toContain(verboseDeprecationsNote());
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).not.toContain(
|
||||
verboseDeprecationsNote()
|
||||
);
|
||||
});
|
||||
|
||||
describe('When the deprecation is an Error', function() {
|
||||
// This form is used by external systems like atom-jasmine3-test-runner
|
||||
// to report their own deprecations through Jasmine. See
|
||||
// <https://github.com/jasmine/jasmine/pull/1498>.
|
||||
it('passes the error through unchanged', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
let deprecation, originalStack;
|
||||
|
||||
try {
|
||||
throw new Error('the deprecation');
|
||||
} catch (err) {
|
||||
deprecation = err;
|
||||
originalStack = err.stack;
|
||||
}
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).toEqual('the deprecation');
|
||||
expect(runnable.addDeprecationWarning.calls.argsFor(0)[0].stack).toBe(
|
||||
originalStack
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0].message).toEqual(
|
||||
'the deprecation'
|
||||
);
|
||||
expect(console.error.calls.argsFor(0)[0].stack).toEqual(originalStack);
|
||||
});
|
||||
|
||||
it('reports the deprecation every time, regardless of config.verboseDeprecations', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
let deprecation;
|
||||
|
||||
try {
|
||||
throw new Error('the deprecation');
|
||||
} catch (err) {
|
||||
deprecation = err;
|
||||
}
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(2);
|
||||
expect(console.error).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('omits the note about verboseDeprecations', function() {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
let deprecation;
|
||||
|
||||
try {
|
||||
throw new Error('the deprecation');
|
||||
} catch (err) {
|
||||
deprecation = err;
|
||||
}
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).not.toContain(verboseDeprecationsNote());
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).not.toContain(
|
||||
verboseDeprecationsNote()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function verboseDeprecationsNote() {
|
||||
return (
|
||||
'Note: This message will be shown only once. Set the ' +
|
||||
'verboseDeprecations config property to true to see every occurrence.'
|
||||
);
|
||||
}
|
||||
|
||||
function testStackTrace(options) {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', options);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledWith({
|
||||
message: jasmine.stringMatching(/^the message/),
|
||||
omitStackTrace: false
|
||||
});
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain('the message');
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain('DeprecatorSpec.js');
|
||||
}
|
||||
|
||||
function testNoStackTrace(options) {
|
||||
const deprecator = new jasmineUnderTest.Deprecator({});
|
||||
const runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', options);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledWith({
|
||||
message: jasmine.stringMatching(/^the message/),
|
||||
omitStackTrace: true
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
// TODO: Fix these unit tests!
|
||||
describe('Env', function() {
|
||||
var env;
|
||||
let env;
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
@@ -26,9 +26,59 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
describe('#topSuite', function() {
|
||||
it('returns the Jasmine top suite for users to traverse the spec tree', function() {
|
||||
var suite = env.topSuite();
|
||||
it('returns an object that describes the tree of suites and specs', function() {
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.it('a top level spec');
|
||||
env.describe('a suite', function() {
|
||||
env.it('a spec');
|
||||
env.describe('a nested suite', function() {
|
||||
env.it('a nested spec');
|
||||
});
|
||||
});
|
||||
|
||||
const suite = env.topSuite();
|
||||
expect(suite).not.toBeInstanceOf(jasmineUnderTest.Suite);
|
||||
expect(suite.description).toEqual('Jasmine__TopLevel__Suite');
|
||||
expect(suite.getFullName()).toEqual('');
|
||||
expect(suite.children.length).toEqual(2);
|
||||
|
||||
expect(suite.children[0]).not.toBeInstanceOf(jasmineUnderTest.Spec);
|
||||
expect(suite.children[0].description).toEqual('a top level spec');
|
||||
expect(suite.children[0].getFullName()).toEqual('a top level spec');
|
||||
expect(suite.children[0].children).toBeFalsy();
|
||||
|
||||
expect(suite.children[1]).not.toBeInstanceOf(jasmineUnderTest.Suite);
|
||||
expect(suite.children[1].description).toEqual('a suite');
|
||||
expect(suite.children[1].getFullName()).toEqual('a suite');
|
||||
expect(suite.children[1].parentSuite).toBe(suite);
|
||||
expect(suite.children[1].children.length).toEqual(2);
|
||||
|
||||
expect(suite.children[1].children[0]).not.toBeInstanceOf(
|
||||
jasmineUnderTest.Spec
|
||||
);
|
||||
expect(suite.children[1].children[0].description).toEqual('a spec');
|
||||
expect(suite.children[1].children[0].getFullName()).toEqual(
|
||||
'a suite a spec'
|
||||
);
|
||||
expect(suite.children[1].children[0].children).toBeFalsy();
|
||||
|
||||
expect(suite.children[1].children[1].description).toEqual(
|
||||
'a nested suite'
|
||||
);
|
||||
expect(suite.children[1].children[1].getFullName()).toEqual(
|
||||
'a suite a nested suite'
|
||||
);
|
||||
expect(suite.children[1].children[1].parentSuite).toBe(suite.children[1]);
|
||||
expect(suite.children[1].children[1].children.length).toEqual(1);
|
||||
|
||||
expect(suite.children[1].children[1].children[0].description).toEqual(
|
||||
'a nested spec'
|
||||
);
|
||||
expect(suite.children[1].children[1].children[0].getFullName()).toEqual(
|
||||
'a suite a nested suite a nested spec'
|
||||
);
|
||||
expect(suite.children[1].children[1].children[0].children).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,9 +87,9 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('can configure specs to throw errors on expectation failures', function() {
|
||||
env.configure({ oneFailurePerSpec: true });
|
||||
env.configure({ stopSpecOnExpectationFailure: true });
|
||||
|
||||
spyOn(jasmineUnderTest, 'Spec');
|
||||
spyOn(jasmineUnderTest, 'Spec').and.callThrough();
|
||||
env.it('foo', function() {});
|
||||
expect(jasmineUnderTest.Spec).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -49,7 +99,7 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('can configure suites to throw errors on expectation failures', function() {
|
||||
env.configure({ oneFailurePerSpec: true });
|
||||
env.configure({ stopSpecOnExpectationFailure: true });
|
||||
|
||||
spyOn(jasmineUnderTest, 'Suite');
|
||||
env.describe('foo', function() {});
|
||||
@@ -60,33 +110,34 @@ describe('Env', function() {
|
||||
);
|
||||
});
|
||||
|
||||
describe('promise library', function() {
|
||||
it('can be configured without a custom library', function() {
|
||||
env.configure({});
|
||||
env.configure({ Promise: undefined });
|
||||
it('ignores configuration properties that are present but undefined', function() {
|
||||
spyOn(env, 'deprecated');
|
||||
const initialConfig = {
|
||||
random: true,
|
||||
seed: '123',
|
||||
failSpecWithNoExpectations: true,
|
||||
stopSpecOnExpectationFailure: true,
|
||||
stopOnSpecFailure: true,
|
||||
hideDisabled: true
|
||||
};
|
||||
env.configure(initialConfig);
|
||||
|
||||
env.configure({
|
||||
random: undefined,
|
||||
seed: undefined,
|
||||
failSpecWithNoExpectations: undefined,
|
||||
stopSpecOnExpectationFailure: undefined,
|
||||
stopOnSpecFailure: undefined,
|
||||
hideDisabled: undefined
|
||||
});
|
||||
|
||||
it('can be configured with a custom library', function() {
|
||||
var myLibrary = {
|
||||
resolve: jasmine.createSpy(),
|
||||
reject: jasmine.createSpy()
|
||||
};
|
||||
env.configure({ Promise: myLibrary });
|
||||
});
|
||||
|
||||
it('cannot be configured with an invalid promise library', function() {
|
||||
var myLibrary = {};
|
||||
|
||||
expect(function() {
|
||||
env.configure({ Promise: myLibrary });
|
||||
}).toThrowError(
|
||||
'Custom promise library missing `resolve`/`reject` functions'
|
||||
);
|
||||
});
|
||||
expect(env.configuration()).toEqual(
|
||||
jasmine.objectContaining(initialConfig)
|
||||
);
|
||||
});
|
||||
|
||||
it('defaults to multiple failures for specs', function() {
|
||||
spyOn(jasmineUnderTest, 'Spec');
|
||||
spyOn(jasmineUnderTest, 'Spec').and.callThrough();
|
||||
env.it('bar', function() {});
|
||||
expect(jasmineUnderTest.Spec).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -105,9 +156,43 @@ describe('Env', function() {
|
||||
);
|
||||
});
|
||||
|
||||
function behavesLikeDescribe(methodName) {
|
||||
it('returns a suite metadata object', function() {
|
||||
let innerSuite;
|
||||
let spec;
|
||||
const suite = env[methodName]('outer suite', function() {
|
||||
innerSuite = env[methodName]('inner suite', function() {
|
||||
spec = env.it('a spec');
|
||||
});
|
||||
});
|
||||
|
||||
expect(suite.parentSuite).toEqual(
|
||||
jasmine.objectContaining({
|
||||
description: 'Jasmine__TopLevel__Suite'
|
||||
})
|
||||
);
|
||||
expect(suite.parentSuite.pend).toBeUndefined();
|
||||
expect(suite.pend).toBeUndefined();
|
||||
expect(suite.description).toEqual('outer suite');
|
||||
expect(suite.getFullName()).toEqual('outer suite');
|
||||
expect(suite.id).toBeInstanceOf(String);
|
||||
expect(suite.id).not.toEqual('');
|
||||
expect(suite.children.length).toEqual(1);
|
||||
expect(suite.children[0]).toBe(innerSuite);
|
||||
expect(innerSuite.children.length).toEqual(1);
|
||||
expect(innerSuite.children[0]).toBe(spec);
|
||||
expect(innerSuite.getFullName()).toEqual('outer suite inner suite');
|
||||
expect(innerSuite.parentSuite).toBe(suite);
|
||||
expect(spec.getFullName()).toEqual('outer suite inner suite a spec');
|
||||
});
|
||||
}
|
||||
|
||||
describe('#describe', function() {
|
||||
behavesLikeDescribe('describe');
|
||||
|
||||
it('throws an error when given arguments', function() {
|
||||
expect(function() {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
env.describe('done method', function(done) {});
|
||||
}).toThrowError('describe does not expect any arguments');
|
||||
});
|
||||
@@ -141,14 +226,64 @@ describe('Env', function() {
|
||||
);
|
||||
|
||||
expect(function() {
|
||||
env.describe('fn arg', function() {});
|
||||
env.describe('fn arg', function() {
|
||||
env.it('has a spec', function() {});
|
||||
});
|
||||
}).not.toThrowError(
|
||||
'describe expects a function argument; received [object Function]'
|
||||
);
|
||||
});
|
||||
|
||||
it('throws an error when it has no children', function() {
|
||||
let ran = false;
|
||||
env.describe('parent suite', function() {
|
||||
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() {
|
||||
behavesLikeDescribe('fdescribe');
|
||||
});
|
||||
|
||||
describe('xdescribe', function() {
|
||||
behavesLikeDescribe('xdescribe');
|
||||
});
|
||||
|
||||
function behavesLikeIt(methodName) {
|
||||
it('returns a spec metadata object', function() {
|
||||
let spec;
|
||||
|
||||
env.describe('a suite', function() {
|
||||
spec = env[methodName]('a spec', function() {});
|
||||
});
|
||||
|
||||
expect(spec.description)
|
||||
.withContext('description')
|
||||
.toEqual('a spec');
|
||||
expect(spec.getFullName())
|
||||
.withContext('getFullName')
|
||||
.toEqual('a suite a spec');
|
||||
expect(spec.id)
|
||||
.withContext('id')
|
||||
.toBeInstanceOf(String);
|
||||
expect(spec.id)
|
||||
.withContext('id')
|
||||
.not.toEqual('');
|
||||
expect(spec.pend).toBeFalsy();
|
||||
});
|
||||
}
|
||||
|
||||
describe('#it', function() {
|
||||
behavesLikeIt('it');
|
||||
|
||||
it('throws an error when it receives a non-fn argument', function() {
|
||||
expect(function() {
|
||||
env.it('undefined arg', null);
|
||||
@@ -164,17 +299,36 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.it('async', jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
env.it('async', async function() {});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.it('huge timeout', function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#xit', function() {
|
||||
behavesLikeIt('xit');
|
||||
|
||||
it('calls spec.exclude with "Temporarily disabled with xit"', function() {
|
||||
const excludeSpy = jasmine.createSpy();
|
||||
spyOn(env, 'it_').and.returnValue({
|
||||
exclude: excludeSpy
|
||||
});
|
||||
env.xit('foo', function() {});
|
||||
expect(excludeSpy).toHaveBeenCalledWith('Temporarily disabled with xit');
|
||||
});
|
||||
|
||||
it('calls spec.pend with "Temporarily disabled with xit"', function() {
|
||||
var pendSpy = jasmine.createSpy();
|
||||
spyOn(env, 'it').and.returnValue({
|
||||
const pendSpy = jasmine.createSpy();
|
||||
const realExclude = jasmineUnderTest.Spec.prototype.exclude;
|
||||
|
||||
spyOn(env, 'it_').and.returnValue({
|
||||
exclude: realExclude,
|
||||
pend: pendSpy
|
||||
});
|
||||
env.xit('foo', function() {});
|
||||
@@ -196,14 +350,15 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.xit('async', jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
env.xit('async', async function() {});
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fit', function() {
|
||||
behavesLikeIt('fit');
|
||||
|
||||
it('throws an error when it receives a non-fn argument', function() {
|
||||
expect(function() {
|
||||
env.fit('undefined arg', undefined);
|
||||
@@ -211,6 +366,12 @@ describe('Env', function() {
|
||||
/fit expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/
|
||||
);
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.fit('huge timeout', function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#beforeEach', function() {
|
||||
@@ -223,11 +384,16 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.beforeEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
env.beforeEach(async function() {});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.beforeEach(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#beforeAll', function() {
|
||||
@@ -240,11 +406,16 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.beforeAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
env.beforeAll(async function() {});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.beforeAll(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterEach', function() {
|
||||
@@ -257,11 +428,16 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.afterEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
env.afterEach(async function() {});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.afterEach(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterAll', function() {
|
||||
@@ -274,16 +450,21 @@ describe('Env', function() {
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.afterAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
env.afterAll(async function() {});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('throws an error when the timeout value is too large for setTimeout', function() {
|
||||
expect(function() {
|
||||
env.afterAll(function() {}, 2147483648);
|
||||
}).toThrowError('Timeout value cannot be greater than 2147483647');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when not constructed with suppressLoadErrors: true', function() {
|
||||
it('installs a global error handler on construction', function() {
|
||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||
'install',
|
||||
'uninstall',
|
||||
'pushListener',
|
||||
@@ -298,7 +479,7 @@ describe('Env', function() {
|
||||
|
||||
describe('when constructed with suppressLoadErrors: true', 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',
|
||||
'uninstall',
|
||||
'pushListener',
|
||||
@@ -317,9 +498,9 @@ describe('Env', function() {
|
||||
function customEqualityTester() {}
|
||||
function customObjectFormatter() {}
|
||||
function prettyPrinter() {}
|
||||
var RealSpec = jasmineUnderTest.Spec,
|
||||
specInstance,
|
||||
expectationFactory;
|
||||
const RealSpec = jasmineUnderTest.Spec;
|
||||
let specInstance;
|
||||
let expectationFactory;
|
||||
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||
@@ -334,29 +515,25 @@ describe('Env', function() {
|
||||
expectationFactory('actual', specInstance);
|
||||
});
|
||||
|
||||
env.addReporter({
|
||||
jasmineDone: function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
}
|
||||
env.execute(null, function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) {
|
||||
function customEqualityTester() {}
|
||||
function customObjectFormatter() {}
|
||||
function prettyPrinter() {}
|
||||
var RealSpec = jasmineUnderTest.Spec,
|
||||
specInstance,
|
||||
asyncExpectationFactory;
|
||||
const RealSpec = jasmineUnderTest.Spec;
|
||||
let specInstance;
|
||||
let asyncExpectationFactory;
|
||||
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||
@@ -371,19 +548,50 @@ describe('Env', function() {
|
||||
asyncExpectationFactory('actual', specInstance);
|
||||
});
|
||||
|
||||
env.addReporter({
|
||||
jasmineDone: function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
}
|
||||
env.execute(null, function() {
|
||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
|
||||
customObjectFormatter
|
||||
]);
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("does not expose the suite as 'this'", function() {
|
||||
let suiteThis;
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
suiteThis = this;
|
||||
env.it('has a spec');
|
||||
});
|
||||
|
||||
env.execute();
|
||||
expect(suiteThis).not.toBeInstanceOf(jasmineUnderTest.Suite);
|
||||
});
|
||||
|
||||
describe('#execute', function() {
|
||||
it('returns a promise', function() {
|
||||
expect(env.execute()).toBeInstanceOf(Promise);
|
||||
});
|
||||
|
||||
it('should reset the topSuite when run twice', function() {
|
||||
spyOn(jasmineUnderTest.Suite.prototype, 'reset');
|
||||
return env
|
||||
.execute() // 1
|
||||
.then(function() {
|
||||
return env.execute(); // 2
|
||||
})
|
||||
.then(function() {
|
||||
expect(
|
||||
jasmineUnderTest.Suite.prototype.reset
|
||||
).toHaveBeenCalledOnceWith();
|
||||
const id = jasmineUnderTest.Suite.prototype.reset.calls.thisFor(0).id;
|
||||
expect(id).toBeTruthy();
|
||||
expect(id).toEqual(env.topSuite().id);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
describe('ExceptionFormatter', function() {
|
||||
describe('#message', function() {
|
||||
it('formats Firefox exception messages', function() {
|
||||
var sampleFirefoxException = {
|
||||
const sampleFirefoxException = {
|
||||
fileName: 'foo.js',
|
||||
lineNumber: '1978',
|
||||
message: 'you got your foo in my bar',
|
||||
@@ -16,7 +16,7 @@ describe('ExceptionFormatter', function() {
|
||||
});
|
||||
|
||||
it('formats Webkit exception messages', function() {
|
||||
var sampleWebkitException = {
|
||||
const sampleWebkitException = {
|
||||
sourceURL: 'foo.js',
|
||||
line: '1978',
|
||||
message: 'you got your foo in my bar',
|
||||
@@ -31,7 +31,7 @@ describe('ExceptionFormatter', function() {
|
||||
});
|
||||
|
||||
it('formats V8 exception messages', function() {
|
||||
var sampleV8 = {
|
||||
const sampleV8 = {
|
||||
message: 'you got your foo in my bar',
|
||||
name: 'A Classic Mistake'
|
||||
},
|
||||
@@ -42,29 +42,29 @@ describe('ExceptionFormatter', 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);
|
||||
|
||||
expect(message).toEqual('This is an unnamed error message.');
|
||||
});
|
||||
|
||||
it('formats empty exceptions with toString format', function() {
|
||||
var EmptyError = function() {};
|
||||
const EmptyError = function() {};
|
||||
EmptyError.prototype.toString = function() {
|
||||
return '[EmptyError]';
|
||||
};
|
||||
var emptyError = new EmptyError();
|
||||
const emptyError = new EmptyError();
|
||||
|
||||
var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||
const exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||
message = exceptionFormatter.message(emptyError);
|
||||
|
||||
expect(message).toEqual('[EmptyError] thrown');
|
||||
});
|
||||
|
||||
it("formats thrown exceptions that aren't errors", function() {
|
||||
var thrown = 'crazy error',
|
||||
const thrown = 'crazy error',
|
||||
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||
message = exceptionFormatter.message(thrown);
|
||||
|
||||
@@ -74,20 +74,46 @@ describe('ExceptionFormatter', function() {
|
||||
|
||||
describe('#stack', function() {
|
||||
it('formats stack traces', function() {
|
||||
var error;
|
||||
try {
|
||||
throw new Error('an error');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
const error = new Error('an error');
|
||||
|
||||
expect(new jasmineUnderTest.ExceptionFormatter().stack(error)).toMatch(
|
||||
/ExceptionFormatterSpec\.js.*\d+/
|
||||
);
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames from V8-style traces but leaves unmatched lines intact', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||
" new Error('nope');\n" +
|
||||
' ^\n' +
|
||||
'\n' +
|
||||
'Error: nope\n' +
|
||||
' at fn1 (C:\\__spec__\\core\\UtilSpec.js:115:19)\n' +
|
||||
' -> C:\\__spec__\\core\\UtilSpec.ts:120:15\n' +
|
||||
' at fn2 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7533:40)\n' +
|
||||
' at fn3 (C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js:7575:25)\n' +
|
||||
' at fn4 (node:internal/timers:462:21)\n'
|
||||
};
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: 'C:\\__jasmine__\\lib\\jasmine-core\\jasmine.js'
|
||||
});
|
||||
const result = subject.stack(error);
|
||||
expect(result).toEqual(
|
||||
'C:\\__spec__\\core\\UtilSpec.ts:120\n' +
|
||||
" new Error('nope');\n" +
|
||||
' ^\n' +
|
||||
'Error: nope\n' +
|
||||
' at fn1 (C:\\__spec__\\core\\UtilSpec.js:115:19)\n' +
|
||||
' -> C:\\__spec__\\core\\UtilSpec.ts:120:15\n' +
|
||||
' at <Jasmine>\n' +
|
||||
' at fn4 (node:internal/timers:462:21)'
|
||||
);
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames from V8 style traces', function() {
|
||||
var error = {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'Error: nope\n' +
|
||||
@@ -96,10 +122,10 @@ describe('ExceptionFormatter', function() {
|
||||
' at fn3 (http://localhost:8888/__jasmine__/jasmine.js:4320:20)\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'
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
const result = subject.stack(error);
|
||||
expect(result).toEqual(
|
||||
'Error: nope\n' +
|
||||
' at fn1 (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
@@ -109,17 +135,17 @@ describe('ExceptionFormatter', function() {
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames from Webkit style traces', function() {
|
||||
var error = {
|
||||
const error = {
|
||||
stack:
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'fn1@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'
|
||||
};
|
||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
const result = subject.stack(error);
|
||||
expect(result).toEqual(
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'<Jasmine>\n' +
|
||||
@@ -128,17 +154,12 @@ describe('ExceptionFormatter', function() {
|
||||
});
|
||||
|
||||
it('filters Jasmine stack frames in this environment', function() {
|
||||
var error, i;
|
||||
try {
|
||||
throw new Error('an error');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
const error = new Error('an error');
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: jasmine.util.jasmineFile()
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
var lines = result.split('\n');
|
||||
const result = subject.stack(error);
|
||||
const lines = result.split('\n');
|
||||
|
||||
if (lines[0].match(/an error/)) {
|
||||
lines.shift();
|
||||
@@ -148,28 +169,23 @@ describe('ExceptionFormatter', function() {
|
||||
expect(lines[1]).toMatch(/<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/);
|
||||
}
|
||||
});
|
||||
|
||||
it('handles multiline error messages in this environment', function() {
|
||||
var error,
|
||||
msg = 'an error\nwith two lines';
|
||||
try {
|
||||
throw new Error(msg);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
const msg = 'an error\nwith two lines';
|
||||
const error = new Error(msg);
|
||||
|
||||
if (error.stack.indexOf(msg) === -1) {
|
||||
pending("Stack traces don't have messages in this environment");
|
||||
}
|
||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: jasmine.util.jasmineFile()
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
var lines = result.split('\n');
|
||||
const result = subject.stack(error);
|
||||
const lines = result.split('\n');
|
||||
|
||||
expect(lines[0]).toMatch(/an error/);
|
||||
expect(lines[1]).toMatch(/with two lines/);
|
||||
@@ -182,17 +198,63 @@ describe('ExceptionFormatter', function() {
|
||||
});
|
||||
|
||||
it('includes error properties in stack', function() {
|
||||
var error;
|
||||
try {
|
||||
throw new Error('an error');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
const error = new Error('an error');
|
||||
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/);
|
||||
});
|
||||
|
||||
describe('When omitMessage is true', function() {
|
||||
it('filters the message from V8-style stack traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'Error: nope\n' +
|
||||
' at fn1 (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' at fn2 (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'
|
||||
};
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||
});
|
||||
const result = subject.stack(error, { omitMessage: true });
|
||||
expect(result).toEqual(
|
||||
' at fn1 (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' at <Jasmine>\n' +
|
||||
' at fn4 (http://localhost:8888/__spec__/core/UtilSpec.js:110:19)'
|
||||
);
|
||||
});
|
||||
|
||||
it('handles Webkit style traces that do not include a message', function() {
|
||||
const error = {
|
||||
stack:
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'fn1@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'
|
||||
};
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||
});
|
||||
const result = subject.stack(error, { omitMessage: true });
|
||||
expect(result).toEqual(
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'<Jasmine>\n' +
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28'
|
||||
);
|
||||
});
|
||||
|
||||
it('ensures that stack traces do not include the message in this environment', function() {
|
||||
const error = new Error('an error');
|
||||
const subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: jasmine.util.jasmineFile()
|
||||
});
|
||||
const result = subject.stack(error, { omitMessage: true });
|
||||
expect(result).not.toContain('an error');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe('Exceptions:', function() {
|
||||
var env;
|
||||
let env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
@@ -10,7 +10,7 @@ describe('Exceptions:', function() {
|
||||
});
|
||||
|
||||
it('should handle exceptions thrown, but continue', function(done) {
|
||||
var secondTest = jasmine.createSpy('second test');
|
||||
const secondTest = jasmine.createSpy('second test');
|
||||
env.describe('Suite for handles exceptions', function() {
|
||||
env.it(
|
||||
'should be a test that fails because it throws an exception',
|
||||
@@ -24,17 +24,20 @@ describe('Exceptions:', function() {
|
||||
);
|
||||
});
|
||||
|
||||
var expectations = function() {
|
||||
const expectations = function() {
|
||||
expect(secondTest).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
|
||||
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
|
||||
var secondDescribe = jasmine.createSpy('second describe');
|
||||
const secondDescribe = jasmine
|
||||
.createSpy('second describe')
|
||||
.and.callFake(function() {
|
||||
env.it('has a test', function() {});
|
||||
});
|
||||
env.describe('a suite that throws an exception', function() {
|
||||
env.it('is a test that should pass', function() {
|
||||
this.expect(true).toEqual(true);
|
||||
@@ -44,12 +47,11 @@ describe('Exceptions:', function() {
|
||||
});
|
||||
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
||||
|
||||
var expectations = function() {
|
||||
const expectations = function() {
|
||||
expect(secondDescribe).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
env.execute(null, expectations);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
describe('ExpectationFilterChain', function() {
|
||||
describe('#addFilter', 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'),
|
||||
orig = new jasmineUnderTest.ExpectationFilterChain({
|
||||
modifyFailureMessage: first
|
||||
@@ -15,7 +15,7 @@ describe('ExpectationFilterChain', function() {
|
||||
});
|
||||
|
||||
it('does not modify the original filter chain', function() {
|
||||
var orig = new jasmineUnderTest.ExpectationFilterChain({}),
|
||||
const orig = new jasmineUnderTest.ExpectationFilterChain({}),
|
||||
f = jasmine.createSpy('f');
|
||||
|
||||
orig.addFilter({ selectComparisonFunc: f });
|
||||
@@ -28,7 +28,7 @@ describe('ExpectationFilterChain', function() {
|
||||
describe('#selectComparisonFunc', function() {
|
||||
describe('When no filters have #selectComparisonFunc', function() {
|
||||
it('returns undefined', function() {
|
||||
var chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||
const chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||
chain.addFilter({});
|
||||
expect(chain.selectComparisonFunc()).toBeUndefined();
|
||||
});
|
||||
@@ -36,15 +36,13 @@ describe('ExpectationFilterChain', function() {
|
||||
|
||||
describe('When some filters have #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'),
|
||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||
.addFilter({ selectComparisonFunc: first })
|
||||
.addFilter({ selectComparisonFunc: second }),
|
||||
matcher = {},
|
||||
result;
|
||||
|
||||
result = chain.selectComparisonFunc(matcher);
|
||||
result = chain.selectComparisonFunc(matcher);
|
||||
|
||||
expect(first).toHaveBeenCalledWith(matcher);
|
||||
expect(second).not.toHaveBeenCalled();
|
||||
@@ -56,7 +54,7 @@ describe('ExpectationFilterChain', function() {
|
||||
describe('#buildFailureMessage', function() {
|
||||
describe('When no filters have #buildFailureMessage', function() {
|
||||
it('returns undefined', function() {
|
||||
var chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||
const chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||
chain.addFilter({});
|
||||
expect(chain.buildFailureMessage()).toBeUndefined();
|
||||
});
|
||||
@@ -64,7 +62,7 @@ describe('ExpectationFilterChain', function() {
|
||||
|
||||
describe('When some filters have #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'),
|
||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||
.addFilter({ buildFailureMessage: first })
|
||||
@@ -72,10 +70,9 @@ describe('ExpectationFilterChain', function() {
|
||||
matcherResult = { pass: false },
|
||||
matcherName = 'foo',
|
||||
args = [],
|
||||
matchersUtil = {},
|
||||
result;
|
||||
matchersUtil = {};
|
||||
|
||||
result = chain.buildFailureMessage(
|
||||
const result = chain.buildFailureMessage(
|
||||
matcherResult,
|
||||
matcherName,
|
||||
args,
|
||||
@@ -97,7 +94,7 @@ describe('ExpectationFilterChain', function() {
|
||||
describe('#modifyFailureMessage', function() {
|
||||
describe('When no filters have #modifyFailureMessage', function() {
|
||||
it('returns the original message', function() {
|
||||
var chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||
const chain = new jasmineUnderTest.ExpectationFilterChain();
|
||||
chain.addFilter({});
|
||||
expect(chain.modifyFailureMessage('msg')).toEqual('msg');
|
||||
});
|
||||
@@ -105,14 +102,12 @@ describe('ExpectationFilterChain', function() {
|
||||
|
||||
describe('When some filters have #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'),
|
||||
chain = new jasmineUnderTest.ExpectationFilterChain()
|
||||
.addFilter({ modifyFailureMessage: first })
|
||||
.addFilter({ modifyFailureMessage: second }),
|
||||
result;
|
||||
|
||||
result = chain.modifyFailureMessage('original');
|
||||
result = chain.modifyFailureMessage('original');
|
||||
|
||||
expect(first).toHaveBeenCalledWith('original');
|
||||
expect(second).not.toHaveBeenCalled();
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
describe('buildExpectationResult', function() {
|
||||
it('defaults to passed', function() {
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const 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({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: true,
|
||||
message: 'some-value'
|
||||
});
|
||||
@@ -15,7 +15,7 @@ describe('buildExpectationResult', function() {
|
||||
});
|
||||
|
||||
it('message returns the message for failing expectations', function() {
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
message: 'some-value'
|
||||
});
|
||||
@@ -23,12 +23,12 @@ describe('buildExpectationResult', function() {
|
||||
});
|
||||
|
||||
it('delegates message formatting to the provided formatter if there was an Error', function() {
|
||||
var fakeError = { message: 'foo' },
|
||||
const fakeError = { message: 'foo' },
|
||||
messageFormatter = jasmine
|
||||
.createSpy('exception message formatter')
|
||||
.and.returnValue(fakeError.message);
|
||||
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
error: fakeError,
|
||||
messageFormatter: messageFormatter
|
||||
@@ -39,53 +39,57 @@ describe('buildExpectationResult', function() {
|
||||
});
|
||||
|
||||
it('delegates stack formatting to the provided formatter if there was an Error', function() {
|
||||
var fakeError = { stack: 'foo' },
|
||||
const fakeError = { stack: 'foo' },
|
||||
stackFormatter = jasmine
|
||||
.createSpy('stack formatter')
|
||||
.and.returnValue(fakeError.stack);
|
||||
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
error: fakeError,
|
||||
stackFormatter: stackFormatter
|
||||
});
|
||||
|
||||
expect(stackFormatter).toHaveBeenCalledWith(fakeError);
|
||||
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' },
|
||||
const fakeError = { stack: 'foo' },
|
||||
stackFormatter = jasmine
|
||||
.createSpy('stack formatter')
|
||||
.and.returnValue(fakeError.stack);
|
||||
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
errorForStack: fakeError,
|
||||
stackFormatter: stackFormatter
|
||||
});
|
||||
|
||||
expect(stackFormatter).toHaveBeenCalledWith(fakeError);
|
||||
expect(stackFormatter).toHaveBeenCalledWith(fakeError, {
|
||||
omitMessage: true
|
||||
});
|
||||
expect(result.stack).toEqual('foo');
|
||||
});
|
||||
|
||||
it('matcherName returns passed matcherName', function() {
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
matcherName: 'some-value'
|
||||
});
|
||||
expect(result.matcherName).toBe('some-value');
|
||||
});
|
||||
|
||||
it('expected returns passed expected', function() {
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
expected: 'some-value'
|
||||
});
|
||||
expect(result.expected).toBe('some-value');
|
||||
});
|
||||
|
||||
it('actual returns passed actual', function() {
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
actual: 'some-value'
|
||||
});
|
||||
expect(result.actual).toBe('some-value');
|
||||
@@ -95,10 +99,10 @@ describe('buildExpectationResult', function() {
|
||||
if (typeof require === 'undefined') {
|
||||
return;
|
||||
}
|
||||
var assert = require('assert');
|
||||
var error;
|
||||
var value = 8421;
|
||||
var expectedValue = 'JasmineExpectationTestValue';
|
||||
const assert = require('assert');
|
||||
const value = 8421;
|
||||
const expectedValue = 'JasmineExpectationTestValue';
|
||||
let error;
|
||||
try {
|
||||
assert.equal(value, expectedValue);
|
||||
} catch (e) {
|
||||
@@ -110,7 +114,7 @@ describe('buildExpectationResult', function() {
|
||||
expect(error.expected).toEqual(expectedValue);
|
||||
expect(error.operator).toEqual('==');
|
||||
|
||||
var result = jasmineUnderTest.buildExpectationResult({
|
||||
const result = jasmineUnderTest.buildExpectationResult({
|
||||
passed: false,
|
||||
matcherName: '',
|
||||
expected: '',
|
||||
|
||||
@@ -1,34 +1,31 @@
|
||||
describe('Expectation', function() {
|
||||
it('makes custom matchers available to this expectation', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {},
|
||||
toBar: function() {}
|
||||
},
|
||||
expectation;
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers
|
||||
});
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers
|
||||
});
|
||||
|
||||
expect(expectation.toFoo).toBeDefined();
|
||||
expect(expectation.toBar).toBeDefined();
|
||||
});
|
||||
|
||||
it('.addCoreMatchers makes matchers available to any expectation', function() {
|
||||
var coreMatchers = {
|
||||
toQuux: function() {}
|
||||
},
|
||||
expectation;
|
||||
const coreMatchers = {
|
||||
toQuux: function() {}
|
||||
};
|
||||
|
||||
jasmineUnderTest.Expectation.addCoreMatchers(coreMatchers);
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({});
|
||||
const expectation = jasmineUnderTest.Expectation.factory({});
|
||||
|
||||
expect(expectation.toQuux).toBeDefined();
|
||||
});
|
||||
|
||||
it("wraps matchers's compare functions, passing in matcher dependencies", function() {
|
||||
var fakeCompare = function() {
|
||||
const fakeCompare = function() {
|
||||
return { pass: true };
|
||||
},
|
||||
matcherFactory = jasmine
|
||||
@@ -40,28 +37,22 @@ describe('Expectation', function() {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
customEqualityTesters = ['a'],
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
matchersUtil: matchersUtil,
|
||||
customMatchers: matchers,
|
||||
customEqualityTesters: customEqualityTesters,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
expectation.toFoo('hello');
|
||||
|
||||
expect(matcherFactory).toHaveBeenCalledWith(
|
||||
matchersUtil,
|
||||
customEqualityTesters
|
||||
);
|
||||
expect(matcherFactory).toHaveBeenCalledWith(matchersUtil);
|
||||
});
|
||||
|
||||
it("wraps matchers's compare functions, passing the actual and expected", function() {
|
||||
var fakeCompare = jasmine
|
||||
const fakeCompare = jasmine
|
||||
.createSpy('fake-compare')
|
||||
.and.returnValue({ pass: true }),
|
||||
matchers = {
|
||||
@@ -74,10 +65,9 @@ describe('Expectation', function() {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
matchersUtil: matchersUtil,
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
@@ -90,7 +80,7 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it('reports a passing result to the spec when the comparison passes', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -102,10 +92,9 @@ describe('Expectation', function() {
|
||||
matchersUtil = {
|
||||
buildFailureMessage: jasmine.createSpy('buildFailureMessage')
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
@@ -126,7 +115,7 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it('reports a failing result to the spec when the comparison fails', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -140,10 +129,9 @@ describe('Expectation', function() {
|
||||
return '';
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
matchersUtil: matchersUtil,
|
||||
actual: 'an actual',
|
||||
@@ -164,7 +152,7 @@ describe('Expectation', 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() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -176,10 +164,9 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
actual: 'an actual',
|
||||
customMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -199,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() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -213,10 +200,9 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -236,7 +222,7 @@ describe('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() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -246,10 +232,9 @@ describe('Expectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
expectation;
|
||||
actual = 'an actual';
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -269,7 +254,7 @@ describe('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() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -284,10 +269,9 @@ describe('Expectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
expectation;
|
||||
actual = 'an actual';
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
matchersUtil: matchersUtil,
|
||||
@@ -308,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() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -321,10 +305,9 @@ describe('Expectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
expectation;
|
||||
actual = 'an actual';
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -344,7 +327,7 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it("reports a passing result to the spec when the 'not' comparison passes, given a negativeCompare", function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -357,10 +340,9 @@ describe('Expectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
expectation;
|
||||
actual = 'an actual';
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -380,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() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -396,10 +378,9 @@ describe('Expectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = 'an actual',
|
||||
expectation;
|
||||
actual = 'an actual';
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -419,8 +400,8 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it('reports a custom error message to the spec', function() {
|
||||
var customError = new Error('I am a custom error');
|
||||
var matchers = {
|
||||
const customError = new Error('I am a custom error');
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -433,10 +414,9 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
actual: 'an actual',
|
||||
customMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -456,8 +436,8 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it("reports a custom message to the spec when a 'not' comparison fails", function() {
|
||||
var customError = new Error('I am a custom error');
|
||||
var matchers = {
|
||||
const customError = new Error('I am a custom error');
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -470,10 +450,9 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
actual: 'an actual',
|
||||
customMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -493,8 +472,8 @@ describe('Expectation', 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');
|
||||
var matchers = {
|
||||
const customError = new Error('I am a custom error');
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -509,10 +488,9 @@ describe('Expectation', function() {
|
||||
};
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation;
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult');
|
||||
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
const expectation = jasmineUnderTest.Expectation.factory({
|
||||
actual: 'an actual',
|
||||
customMatchers: matchers,
|
||||
addExpectationResult: addExpectationResult
|
||||
@@ -533,7 +511,7 @@ describe('Expectation', function() {
|
||||
|
||||
describe('#withContext', function() {
|
||||
it('prepends the context to the generated failure message', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -566,7 +544,7 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it('prepends the context to a custom failure message', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -593,7 +571,7 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it('indents a multiline failure message', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -607,19 +585,18 @@ describe('Expectation', function() {
|
||||
customMatchers: matchers,
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
}),
|
||||
actualMessage;
|
||||
});
|
||||
|
||||
expectation.withContext('Some context').toFoo('hello');
|
||||
|
||||
actualMessage = addExpectationResult.calls.argsFor(0)[1].message;
|
||||
const actualMessage = addExpectationResult.calls.argsFor(0)[1].message;
|
||||
expect(actualMessage).toEqual(
|
||||
'Some context:\n a\n multiline\n message'
|
||||
);
|
||||
});
|
||||
|
||||
it('prepends the context to a custom failure message from a function', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -651,7 +628,7 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it('works with #not', function() {
|
||||
var matchers = {
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
@@ -680,8 +657,8 @@ describe('Expectation', function() {
|
||||
});
|
||||
|
||||
it('works with #not and a custom message', function() {
|
||||
var customError = new Error('I am a custom error');
|
||||
var matchers = {
|
||||
const customError = new Error('I am a custom error');
|
||||
const matchers = {
|
||||
toFoo: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('GlobalErrors', function() {
|
||||
it('calls the added handler on error', function() {
|
||||
var fakeGlobal = { onerror: null },
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
@@ -12,8 +12,25 @@ describe('GlobalErrors', function() {
|
||||
expect(handler).toHaveBeenCalledWith('foo');
|
||||
});
|
||||
|
||||
it('enables external interception of error by overriding global.onerror', function() {
|
||||
const 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 },
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
||||
fooError = new Error('foo');
|
||||
@@ -33,7 +50,7 @@ describe('GlobalErrors', function() {
|
||||
});
|
||||
|
||||
it('only calls the most recent handler', function() {
|
||||
var fakeGlobal = { onerror: null },
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler1 = jasmine.createSpy('errorHandler1'),
|
||||
handler2 = jasmine.createSpy('errorHandler2'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
@@ -49,7 +66,7 @@ describe('GlobalErrors', function() {
|
||||
});
|
||||
|
||||
it('calls previous handlers when one is removed', function() {
|
||||
var fakeGlobal = { onerror: null },
|
||||
const fakeGlobal = { onerror: null },
|
||||
handler1 = jasmine.createSpy('errorHandler1'),
|
||||
handler2 = jasmine.createSpy('errorHandler2'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
@@ -58,7 +75,7 @@ describe('GlobalErrors', function() {
|
||||
errors.pushListener(handler1);
|
||||
errors.pushListener(handler2);
|
||||
|
||||
errors.popListener();
|
||||
errors.popListener(handler2);
|
||||
|
||||
fakeGlobal.onerror('foo');
|
||||
|
||||
@@ -66,8 +83,15 @@ describe('GlobalErrors', function() {
|
||||
expect(handler2).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws when no listener is passed to #popListener', function() {
|
||||
const errors = new jasmineUnderTest.GlobalErrors({});
|
||||
expect(function() {
|
||||
errors.popListener();
|
||||
}).toThrowError('popListener expects a listener');
|
||||
});
|
||||
|
||||
it('uninstalls itself, putting back a previous callback', function() {
|
||||
var originalCallback = jasmine.createSpy('error'),
|
||||
const originalCallback = jasmine.createSpy('error'),
|
||||
fakeGlobal = { onerror: originalCallback },
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
@@ -83,7 +107,7 @@ describe('GlobalErrors', function() {
|
||||
});
|
||||
|
||||
it('rethrows the original error when there is no handler', function() {
|
||||
var fakeGlobal = {},
|
||||
const fakeGlobal = {},
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
||||
originalError = new Error('nope');
|
||||
|
||||
@@ -98,8 +122,8 @@ describe('GlobalErrors', function() {
|
||||
errors.uninstall();
|
||||
});
|
||||
|
||||
it('reports uncaughtException in node.js', function() {
|
||||
var fakeGlobal = {
|
||||
it('reports uncaught exceptions in node.js', function() {
|
||||
const fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: jasmine.createSpy('process.removeListener'),
|
||||
@@ -126,7 +150,7 @@ describe('GlobalErrors', function() {
|
||||
|
||||
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'));
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
||||
@@ -146,57 +170,123 @@ describe('GlobalErrors', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('reports unhandledRejection in node.js', function() {
|
||||
var fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: jasmine.createSpy('process.removeListener'),
|
||||
listeners: jasmine
|
||||
.createSpy('process.listeners')
|
||||
.and.returnValue(['foo']),
|
||||
removeAllListeners: jasmine.createSpy('process.removeAllListeners')
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
describe('Reporting unhandled promise rejections in node.js', function() {
|
||||
it('reports rejections with `Error` reasons', function() {
|
||||
const fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: jasmine.createSpy('process.removeListener'),
|
||||
listeners: jasmine
|
||||
.createSpy('process.listeners')
|
||||
.and.returnValue(['foo']),
|
||||
removeAllListeners: jasmine.createSpy('process.removeAllListeners')
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
jasmine.any(Function)
|
||||
);
|
||||
expect(fakeGlobal.process.listeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
expect(fakeGlobal.process.removeAllListeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
errors.install();
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
jasmine.any(Function)
|
||||
);
|
||||
expect(fakeGlobal.process.listeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
expect(fakeGlobal.process.removeAllListeners).toHaveBeenCalledWith(
|
||||
'unhandledRejection'
|
||||
);
|
||||
|
||||
errors.pushListener(handler);
|
||||
errors.pushListener(handler);
|
||||
|
||||
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(new Error('bar'));
|
||||
const addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(new Error('bar'));
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
||||
expect(handler.calls.argsFor(0)[0].jasmineMessage).toBe(
|
||||
'Unhandled promise rejection: Error: bar'
|
||||
);
|
||||
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
||||
expect(handler.calls.argsFor(0)[0].jasmineMessage).toBe(
|
||||
'Unhandled promise rejection: Error: bar'
|
||||
);
|
||||
|
||||
errors.uninstall();
|
||||
errors.uninstall();
|
||||
|
||||
expect(fakeGlobal.process.removeListener).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
addedListener
|
||||
);
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
'foo'
|
||||
);
|
||||
expect(fakeGlobal.process.removeListener).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
addedListener
|
||||
);
|
||||
expect(fakeGlobal.process.on).toHaveBeenCalledWith(
|
||||
'unhandledRejection',
|
||||
'foo'
|
||||
);
|
||||
});
|
||||
|
||||
it('reports rejections with non-`Error` reasons', function() {
|
||||
const fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: function() {},
|
||||
listeners: function() {
|
||||
return [];
|
||||
},
|
||||
removeAllListeners: function() {}
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
||||
'unhandledRejection'
|
||||
);
|
||||
const addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(17);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
new Error(
|
||||
'Unhandled promise rejection: 17\n' +
|
||||
'(Tip: to get a useful stack trace, use ' +
|
||||
'Promise.reject(new Error(...)) instead of Promise.reject(...).)'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('reports rejections with no reason provided', function() {
|
||||
const fakeGlobal = {
|
||||
process: {
|
||||
on: jasmine.createSpy('process.on'),
|
||||
removeListener: function() {},
|
||||
listeners: function() {
|
||||
return [];
|
||||
},
|
||||
removeAllListeners: function() {}
|
||||
}
|
||||
},
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
expect(fakeGlobal.process.on.calls.argsFor(1)[0]).toEqual(
|
||||
'unhandledRejection'
|
||||
);
|
||||
const addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
|
||||
addedListener(undefined);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
new Error(
|
||||
'Unhandled promise rejection with no error or message\n' +
|
||||
'(Tip: to get a useful stack trace, use ' +
|
||||
'Promise.reject(new Error(...)) instead of Promise.reject().)'
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Reporting unhandled promise rejections in the browser', function() {
|
||||
it('subscribes and unsubscribes from the unhandledrejection event', function() {
|
||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'onerror'
|
||||
@@ -209,7 +299,7 @@ describe('GlobalErrors', function() {
|
||||
jasmine.any(Function)
|
||||
);
|
||||
|
||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
errors.uninstall();
|
||||
|
||||
expect(fakeGlobal.removeEventListener).toHaveBeenCalledWith(
|
||||
@@ -219,7 +309,7 @@ describe('GlobalErrors', function() {
|
||||
});
|
||||
|
||||
it('reports rejections whose reason is a string', function() {
|
||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'onerror'
|
||||
@@ -230,14 +320,14 @@ describe('GlobalErrors', function() {
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
addedListener({ reason: 'nope' });
|
||||
|
||||
expect(handler).toHaveBeenCalledWith('Unhandled promise rejection: nope');
|
||||
});
|
||||
|
||||
it('reports rejections whose reason is an Error', function() {
|
||||
var fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener',
|
||||
'removeEventListener',
|
||||
'onerror'
|
||||
@@ -248,15 +338,8 @@ describe('GlobalErrors', function() {
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
var addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
var reason;
|
||||
|
||||
try {
|
||||
// Throwing ensures that we get a stack property in all browsers
|
||||
throw new Error('bar');
|
||||
} catch (e) {
|
||||
reason = e;
|
||||
}
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
const reason = new Error('bar');
|
||||
|
||||
addedListener({ reason: reason });
|
||||
|
||||
@@ -268,5 +351,57 @@ describe('GlobalErrors', function() {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('Enabling external interception of reported rejections by overriding global.onerror', function() {
|
||||
it('overriding global.onerror intercepts rejections whose reason is a string', function() {
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
addedListener({ reason: 'nope' });
|
||||
|
||||
expect(hijackHandler).toHaveBeenCalledWith(
|
||||
'Unhandled promise rejection: nope'
|
||||
);
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('overriding global.onerror intercepts rejections whose reason is an Error', function() {
|
||||
const fakeGlobal = jasmine.createSpyObj('globalErrors', [
|
||||
'addEventListener'
|
||||
]),
|
||||
handler = jasmine.createSpy('errorHandler'),
|
||||
hijackHandler = jasmine.createSpy('hijackErrorHandler'),
|
||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
||||
|
||||
errors.install();
|
||||
errors.pushListener(handler);
|
||||
|
||||
fakeGlobal.onerror = hijackHandler;
|
||||
|
||||
const addedListener = fakeGlobal.addEventListener.calls.argsFor(0)[1];
|
||||
const reason = new Error('bar');
|
||||
|
||||
addedListener({ reason: reason });
|
||||
|
||||
expect(hijackHandler).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
jasmineMessage: 'Unhandled promise rejection: Error: bar',
|
||||
message: reason.message,
|
||||
stack: reason.stack
|
||||
})
|
||||
);
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('JsApiReporter', 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.finished).toBe(false);
|
||||
@@ -12,7 +12,7 @@ describe('JsApiReporter', 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.finished).toBe(false);
|
||||
@@ -24,13 +24,13 @@ describe('JsApiReporter', function() {
|
||||
});
|
||||
|
||||
it("defaults to 'loaded' status", function() {
|
||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
|
||||
expect(reporter.status()).toEqual('loaded');
|
||||
});
|
||||
|
||||
it("reports 'started' when Jasmine has started", function() {
|
||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('JsApiReporter', function() {
|
||||
});
|
||||
|
||||
it("reports 'done' when Jasmine is done", function() {
|
||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
|
||||
reporter.jasmineDone({});
|
||||
|
||||
@@ -46,14 +46,14 @@ describe('JsApiReporter', function() {
|
||||
});
|
||||
|
||||
it('tracks a suite', function() {
|
||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
|
||||
reporter.suiteStarted({
|
||||
id: 123,
|
||||
description: 'A suite'
|
||||
});
|
||||
|
||||
var suites = reporter.suites();
|
||||
const suites = reporter.suites();
|
||||
|
||||
expect(suites).toEqual({ 123: { id: 123, description: 'A suite' } });
|
||||
|
||||
@@ -69,7 +69,7 @@ describe('JsApiReporter', function() {
|
||||
});
|
||||
|
||||
describe('#specResults', function() {
|
||||
var reporter, specResult1, specResult2;
|
||||
let reporter, specResult1, specResult2;
|
||||
beforeEach(function() {
|
||||
reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
specResult1 = {
|
||||
@@ -99,7 +99,7 @@ describe('JsApiReporter', function() {
|
||||
});
|
||||
|
||||
describe('#suiteResults', function() {
|
||||
var reporter, suiteResult1, suiteResult2;
|
||||
let reporter, suiteStarted1, suiteResult1, suiteResult2;
|
||||
beforeEach(function() {
|
||||
reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
suiteStarted1 = {
|
||||
@@ -137,7 +137,7 @@ describe('JsApiReporter', function() {
|
||||
|
||||
describe('#executionTime', 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({
|
||||
timer: timerSpy
|
||||
});
|
||||
@@ -147,7 +147,7 @@ describe('JsApiReporter', 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({
|
||||
timer: timerSpy
|
||||
});
|
||||
@@ -159,7 +159,7 @@ describe('JsApiReporter', function() {
|
||||
|
||||
describe("when the specs haven't finished being run", function() {
|
||||
it('should return undefined', function() {
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
const timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
reporter = new jasmineUnderTest.JsApiReporter({
|
||||
timer: timerSpy
|
||||
});
|
||||
@@ -171,7 +171,7 @@ describe('JsApiReporter', function() {
|
||||
|
||||
describe('#runDetails', function() {
|
||||
it('should have details about the run', function() {
|
||||
var reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
const reporter = new jasmineUnderTest.JsApiReporter({});
|
||||
reporter.jasmineDone({ some: { run: 'details' } });
|
||||
expect(reporter.runDetails).toEqual({ some: { run: 'details' } });
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('FakeDate', function() {
|
||||
it('does not fail if no global date is found', function() {
|
||||
var fakeGlobal = {},
|
||||
const fakeGlobal = {},
|
||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
expect(function() {
|
||||
@@ -11,11 +11,13 @@ describe('FakeDate', function() {
|
||||
});
|
||||
|
||||
it('replaces the global Date when it is installed', function() {
|
||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {}
|
||||
};
|
||||
}),
|
||||
const globalDate = jasmine
|
||||
.createSpy('global Date')
|
||||
.and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {}
|
||||
};
|
||||
}),
|
||||
fakeGlobal = { Date: globalDate },
|
||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
@@ -26,11 +28,13 @@ describe('FakeDate', function() {
|
||||
});
|
||||
|
||||
it('replaces the global Date on uninstall', function() {
|
||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {}
|
||||
};
|
||||
}),
|
||||
const globalDate = jasmine
|
||||
.createSpy('global Date')
|
||||
.and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {}
|
||||
};
|
||||
}),
|
||||
fakeGlobal = { Date: globalDate },
|
||||
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() {
|
||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
const globalDate = jasmine
|
||||
.createSpy('global Date')
|
||||
.and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
fakeGlobal = { Date: globalDate },
|
||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
@@ -59,7 +65,7 @@ describe('FakeDate', 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),
|
||||
baseDate = new Date();
|
||||
|
||||
@@ -70,7 +76,7 @@ describe('FakeDate', function() {
|
||||
});
|
||||
|
||||
it('makes real dates', function() {
|
||||
var fakeGlobal = { Date: Date },
|
||||
const fakeGlobal = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
mockDate.install();
|
||||
@@ -79,53 +85,39 @@ describe('FakeDate', function() {
|
||||
});
|
||||
|
||||
it('fakes current time when using Date.now()', function() {
|
||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
const globalDate = jasmine
|
||||
.createSpy('global Date')
|
||||
.and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
fakeGlobal = { Date: globalDate };
|
||||
|
||||
globalDate.now = function() {};
|
||||
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
const mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
mockDate.install();
|
||||
|
||||
expect(fakeGlobal.Date.now()).toEqual(1000);
|
||||
});
|
||||
|
||||
it("does not stub Date.now() if it doesn't already exist", function() {
|
||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
fakeGlobal = { Date: globalDate },
|
||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
mockDate.install();
|
||||
|
||||
expect(fakeGlobal.Date.now).toThrowError(
|
||||
'Browser does not support Date.now()'
|
||||
);
|
||||
});
|
||||
|
||||
it('makes time passes using tick', function() {
|
||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
const globalDate = jasmine
|
||||
.createSpy('global Date')
|
||||
.and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
fakeGlobal = { Date: globalDate };
|
||||
|
||||
globalDate.now = function() {};
|
||||
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
const mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
mockDate.install();
|
||||
|
||||
@@ -139,17 +131,19 @@ describe('FakeDate', function() {
|
||||
});
|
||||
|
||||
it('allows to increase 0 milliseconds using tick', function() {
|
||||
var globalDate = jasmine.createSpy('global Date').and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
const globalDate = jasmine
|
||||
.createSpy('global Date')
|
||||
.and.callFake(function() {
|
||||
return {
|
||||
getTime: function() {
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
}),
|
||||
fakeGlobal = { Date: globalDate };
|
||||
|
||||
globalDate.now = function() {};
|
||||
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
const mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
mockDate.install();
|
||||
|
||||
@@ -161,40 +155,40 @@ describe('FakeDate', 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.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(
|
||||
new Date(2013, 9, 23, 0, 0, 1, 0).getTime()
|
||||
);
|
||||
});
|
||||
|
||||
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.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());
|
||||
});
|
||||
|
||||
it('allows creation of a Date with millis', function() {
|
||||
var fakeGlobal = { Date: Date },
|
||||
const fakeGlobal = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
|
||||
now = new Date(2014, 3, 15).getTime();
|
||||
|
||||
mockDate.install();
|
||||
|
||||
var otherDate = new fakeGlobal.Date(now);
|
||||
const otherDate = new fakeGlobal.Date(now);
|
||||
expect(otherDate.getTime()).toEqual(now);
|
||||
});
|
||||
|
||||
it('copies all Date properties to the mocked date', function() {
|
||||
var fakeGlobal = { Date: Date },
|
||||
const fakeGlobal = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
||||
|
||||
mockDate.install();
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
describe('PrettyPrinter', 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("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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(true)).toEqual('true');
|
||||
expect(pp(false)).toEqual('false');
|
||||
expect(pp(null)).toEqual('null');
|
||||
@@ -18,25 +26,23 @@ describe('PrettyPrinter', function() {
|
||||
|
||||
describe('stringify sets', function() {
|
||||
it('should stringify sets properly', function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var set = new Set(); // eslint-disable-line compat/compat
|
||||
const set = new Set();
|
||||
set.add(1);
|
||||
set.add(2);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(set)).toEqual('Set( 1, 2 )');
|
||||
});
|
||||
|
||||
it('should truncate sets with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
const originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
var set = new Set(); // eslint-disable-line compat/compat
|
||||
const set = new Set();
|
||||
set.add('a');
|
||||
set.add('b');
|
||||
set.add('c');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
@@ -46,24 +52,22 @@ describe('PrettyPrinter', function() {
|
||||
|
||||
describe('stringify maps', function() {
|
||||
it('should stringify maps properly', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var map = new Map(); // eslint-disable-line compat/compat
|
||||
const map = new Map();
|
||||
map.set(1, 2);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(map)).toEqual('Map( [ 1, 2 ] )');
|
||||
});
|
||||
|
||||
it('should truncate maps with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
const originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
var map = new Map(); // eslint-disable-line compat/compat
|
||||
const map = new Map();
|
||||
map.set('a', 1);
|
||||
map.set('b', 2);
|
||||
map.set('c', 3);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
@@ -73,17 +77,22 @@ describe('PrettyPrinter', function() {
|
||||
|
||||
describe('stringify arrays', 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, 'foo', {}, jasmine.undefined, null])).toEqual(
|
||||
"[ 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() {
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var array = [1, 2, 3];
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
const array = [1, 2, 3];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
@@ -94,25 +103,25 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should stringify arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var arr = [1, 2];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const arr = [1, 2];
|
||||
arr.foo = 'bar';
|
||||
arr.baz = {};
|
||||
expect(pp(arr)).toEqual("[ 1, 2, foo: 'bar', baz: Object({ }) ]");
|
||||
});
|
||||
|
||||
it('should stringify empty arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var empty = [];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const empty = [];
|
||||
empty.foo = 'bar';
|
||||
empty.baz = {};
|
||||
expect(pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
|
||||
});
|
||||
|
||||
it('should stringify long arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = [1, 2, 3];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
const long = [1, 2, 3];
|
||||
long.foo = 'bar';
|
||||
long.baz = {};
|
||||
|
||||
@@ -127,22 +136,22 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should indicate circular array references', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var array1 = [1, 2];
|
||||
var array2 = [array1];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const array1 = [1, 2];
|
||||
const array2 = [array1];
|
||||
array1.push(array2);
|
||||
expect(pp(array1)).toEqual('[ 1, 2, [ <circular reference: Array> ] ]');
|
||||
});
|
||||
|
||||
it('should not indicate circular references incorrectly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var array = [[1]];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const array = [[1]];
|
||||
expect(pp(array)).toEqual('[ [ 1 ] ]');
|
||||
});
|
||||
});
|
||||
|
||||
it('should stringify objects properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ foo: 'bar' })).toEqual("Object({ foo: 'bar' })");
|
||||
expect(
|
||||
pp({
|
||||
@@ -159,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() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ nodeType: 1 })).toEqual('Object({ nodeType: 1 })');
|
||||
});
|
||||
|
||||
it('should truncate objects with too many keys', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = { a: 1, b: 2, c: 3 };
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
const long = { a: 1, b: 2, c: 3 };
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
@@ -178,7 +206,7 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
function withMaxChars(maxChars, fn) {
|
||||
var originalMaxChars = jasmineUnderTest.MAX_PRETTY_PRINT_CHARS;
|
||||
const originalMaxChars = jasmineUnderTest.MAX_PRETTY_PRINT_CHARS;
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_CHARS = maxChars;
|
||||
@@ -189,8 +217,8 @@ describe('PrettyPrinter', function() {
|
||||
}
|
||||
|
||||
it('should truncate outputs that are too long', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var big = [{ a: 1, b: 'a long string' }, {}];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const big = [{ a: 1, b: 'a long string' }, {}];
|
||||
|
||||
withMaxChars(34, function() {
|
||||
expect(pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
||||
@@ -198,7 +226,7 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should not serialize more objects after hitting MAX_PRETTY_PRINT_CHARS', function() {
|
||||
var a = {
|
||||
const a = {
|
||||
jasmineToString: function() {
|
||||
return 'object a';
|
||||
}
|
||||
@@ -228,25 +256,25 @@ describe('PrettyPrinter', 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: 'foo' })).toContain('null({');
|
||||
});
|
||||
|
||||
it('should not include inherited properties when stringifying an object', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var SomeClass = function SomeClass() {};
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const SomeClass = function SomeClass() {};
|
||||
SomeClass.prototype.foo = 'inherited foo';
|
||||
var instance = new SomeClass();
|
||||
const instance = new SomeClass();
|
||||
instance.bar = 'my own bar';
|
||||
expect(pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
|
||||
});
|
||||
|
||||
it('should not recurse objects and arrays more deeply than jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
|
||||
var nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
||||
var nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
|
||||
const nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
||||
const nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
|
||||
@@ -272,25 +300,23 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should stringify immutable circular objects', function() {
|
||||
if (Object.freeze) {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var frozenObject = { foo: { bar: 'baz' } };
|
||||
frozenObject.circular = frozenObject;
|
||||
frozenObject = Object.freeze(frozenObject);
|
||||
expect(pp(frozenObject)).toEqual(
|
||||
"Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })"
|
||||
);
|
||||
}
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
let frozenObject = { foo: { bar: 'baz' } };
|
||||
frozenObject.circular = frozenObject;
|
||||
frozenObject = Object.freeze(frozenObject);
|
||||
expect(pp(frozenObject)).toEqual(
|
||||
"Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })"
|
||||
);
|
||||
});
|
||||
|
||||
it('should stringify RegExp objects properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(/x|y|z/)).toEqual('/x|y|z/');
|
||||
});
|
||||
|
||||
it('should indicate circular object references', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var sampleValue = { foo: 'hello' };
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const sampleValue = { foo: 'hello' };
|
||||
sampleValue.nested = sampleValue;
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
"Object({ foo: 'hello', nested: <circular reference: Object> })"
|
||||
@@ -298,43 +324,38 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should indicate getters on objects as such', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var sampleValue = { id: 1 };
|
||||
if (sampleValue.__defineGetter__) {
|
||||
//not supported in IE!
|
||||
sampleValue.__defineGetter__('calculatedValue', function() {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const sampleValue = {
|
||||
id: 1,
|
||||
get calculatedValue() {
|
||||
throw new Error("don't call me!");
|
||||
});
|
||||
}
|
||||
if (sampleValue.__defineGetter__) {
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
'Object({ id: 1, calculatedValue: <getter> })'
|
||||
);
|
||||
} else {
|
||||
expect(pp(sampleValue)).toEqual('Object({ id: 1 })');
|
||||
}
|
||||
}
|
||||
};
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
'Object({ id: 1, calculatedValue: <getter> })'
|
||||
);
|
||||
});
|
||||
|
||||
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(
|
||||
"'some <b>html string</b> &'"
|
||||
);
|
||||
});
|
||||
|
||||
it('should abbreviate the global (usually window) object', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(jasmine.getGlobal())).toEqual('<global>');
|
||||
});
|
||||
|
||||
it('should stringify Date objects properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var now = new Date();
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const now = new Date();
|
||||
expect(pp(now)).toEqual('Date(' + now.toString() + ')');
|
||||
});
|
||||
|
||||
describe('with a spy object', function() {
|
||||
var env, pp;
|
||||
let env, pp;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
@@ -346,11 +367,11 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should stringify spy objects properly', function() {
|
||||
var TestObject = {
|
||||
const TestObject = {
|
||||
someFunction: function() {}
|
||||
};
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return [];
|
||||
},
|
||||
@@ -366,13 +387,13 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should stringify spyOn toString properly', function() {
|
||||
var TestObject = {
|
||||
const TestObject = {
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return [];
|
||||
},
|
||||
@@ -382,15 +403,15 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
spyRegistry.spyOn(TestObject, 'toString');
|
||||
var testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
||||
const testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
||||
|
||||
expect(pp(testSpyObj)).toEqual('spy on TheClassName.toString');
|
||||
});
|
||||
});
|
||||
|
||||
it('should stringify objects that implement jasmineToString', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const obj = {
|
||||
jasmineToString: function() {
|
||||
return 'strung';
|
||||
}
|
||||
@@ -400,8 +421,8 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should pass itself to jasmineToString', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter([]);
|
||||
var obj = {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter([]);
|
||||
const obj = {
|
||||
jasmineToString: jasmine.createSpy('jasmineToString').and.returnValue('')
|
||||
};
|
||||
|
||||
@@ -410,8 +431,8 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should stringify objects that implement custom toString', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const obj = {
|
||||
toString: function() {
|
||||
return 'my toString';
|
||||
}
|
||||
@@ -421,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
|
||||
// toString despite obj.toString !== Object.prototype.toString
|
||||
var objFromOtherContext = {
|
||||
const objFromOtherContext = {
|
||||
foo: 'bar',
|
||||
toString: function() {
|
||||
return Object.prototype.toString.call(this);
|
||||
@@ -434,8 +455,8 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it("should stringify objects have have a toString that isn't a function", function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const obj = {
|
||||
toString: 'foo'
|
||||
};
|
||||
|
||||
@@ -443,30 +464,30 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should stringify objects from anonymous constructors with custom toString', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var MyAnonymousConstructor = (function() {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const MyAnonymousConstructor = (function() {
|
||||
return function() {};
|
||||
})();
|
||||
MyAnonymousConstructor.toString = function() {
|
||||
return '';
|
||||
};
|
||||
|
||||
var a = new MyAnonymousConstructor();
|
||||
const a = new MyAnonymousConstructor();
|
||||
|
||||
expect(pp(a)).toEqual('<anonymous>({ })');
|
||||
});
|
||||
|
||||
it('should handle objects with null prototype', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = Object.create(null);
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const obj = Object.create(null);
|
||||
obj.foo = 'bar';
|
||||
|
||||
expect(pp(obj)).toEqual("null({ foo: 'bar' })");
|
||||
});
|
||||
|
||||
it('should gracefully handle objects with invalid toString implementations', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
const pp = jasmineUnderTest.makePrettyPrinter();
|
||||
const obj = {
|
||||
foo: {
|
||||
toString: function() {
|
||||
// Invalid: toString returning a number
|
||||
@@ -502,8 +523,8 @@ describe('PrettyPrinter', function() {
|
||||
|
||||
describe('Custom object formatters', function() {
|
||||
it('should use the first custom object formatter that does not return undefined', function() {
|
||||
var customObjectFormatters = [
|
||||
function(obj) {
|
||||
const customObjectFormatters = [
|
||||
function() {
|
||||
return undefined;
|
||||
},
|
||||
function(obj) {
|
||||
@@ -520,8 +541,8 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should fall back to built in logic if all custom object formatters return undefined', function() {
|
||||
var customObjectFormatters = [
|
||||
function(obj) {
|
||||
const customObjectFormatters = [
|
||||
function() {
|
||||
return undefined;
|
||||
}
|
||||
],
|
||||
@@ -534,8 +555,8 @@ describe('PrettyPrinter', function() {
|
||||
|
||||
describe('#customFormat_', function() {
|
||||
it('should use the first custom object formatter that does not return undefined', function() {
|
||||
var customObjectFormatters = [
|
||||
function(obj) {
|
||||
const customObjectFormatters = [
|
||||
function() {
|
||||
return undefined;
|
||||
},
|
||||
function(obj) {
|
||||
@@ -552,8 +573,8 @@ describe('PrettyPrinter', function() {
|
||||
});
|
||||
|
||||
it('should return undefined if all custom object formatters return undefined', function() {
|
||||
var customObjectFormatters = [
|
||||
function(obj) {
|
||||
const customObjectFormatters = [
|
||||
function() {
|
||||
return undefined;
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('QueueRunner', function() {
|
||||
it("runs all the functions it's passed", function() {
|
||||
var calls = [],
|
||||
const calls = [],
|
||||
queueableFn1 = { fn: jasmine.createSpy('fn1') },
|
||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
@@ -18,30 +18,11 @@ describe('QueueRunner', function() {
|
||||
expect(calls).toEqual(['fn1', 'fn2']);
|
||||
});
|
||||
|
||||
it('runs cleanup functions after the others', function() {
|
||||
var calls = [],
|
||||
queueableFn1 = { fn: jasmine.createSpy('fn1') },
|
||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1],
|
||||
cleanupFns: [queueableFn2]
|
||||
});
|
||||
queueableFn1.fn.and.callFake(function() {
|
||||
calls.push('fn1');
|
||||
});
|
||||
queueableFn2.fn.and.callFake(function() {
|
||||
calls.push('fn2');
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(calls).toEqual(['fn1', 'fn2']);
|
||||
});
|
||||
|
||||
it("calls each function with a consistent 'this'-- an empty object", function() {
|
||||
var queueableFn1 = { fn: jasmine.createSpy('fn1') },
|
||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||
queueableFn3 = {
|
||||
const queueableFn1 = { fn: jasmine.createSpy('fn1') };
|
||||
const queueableFn2 = { fn: jasmine.createSpy('fn2') };
|
||||
let asyncContext;
|
||||
const queueableFn3 = {
|
||||
fn: function(done) {
|
||||
asyncContext = this;
|
||||
done();
|
||||
@@ -49,12 +30,11 @@ describe('QueueRunner', function() {
|
||||
},
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1, queueableFn2, queueableFn3]
|
||||
}),
|
||||
asyncContext;
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
var context = queueableFn1.fn.calls.first().object;
|
||||
const context = queueableFn1.fn.calls.first().object;
|
||||
expect(context).toEqual(new jasmineUnderTest.UserContext());
|
||||
expect(queueableFn2.fn.calls.first().object).toBe(context);
|
||||
expect(asyncContext).toBe(context);
|
||||
@@ -73,7 +53,7 @@ describe('QueueRunner', function() {
|
||||
//TODO: it would be nice if spy arity could match the fake, so we could do something like:
|
||||
//createSpy('asyncfn').and.callFake(function(done) {});
|
||||
|
||||
var onComplete = jasmine.createSpy('onComplete'),
|
||||
const onComplete = jasmine.createSpy('onComplete'),
|
||||
beforeCallback = jasmine.createSpy('beforeCallback'),
|
||||
fnCallback = jasmine.createSpy('fnCallback'),
|
||||
afterCallback = jasmine.createSpy('afterCallback'),
|
||||
@@ -124,7 +104,7 @@ describe('QueueRunner', 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) {
|
||||
setTimeout(function() {
|
||||
done.fail('foo');
|
||||
@@ -149,35 +129,112 @@ describe('QueueRunner', function() {
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('explicitly fails an async function when next is called with an Error and moves to the next function', function() {
|
||||
var err = new Error('foo'),
|
||||
queueableFn1 = {
|
||||
fn: function(done) {
|
||||
setTimeout(function() {
|
||||
done(err);
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||
failFn = jasmine.createSpy('fail'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1, queueableFn2],
|
||||
fail: failFn
|
||||
describe('When next is called with an argument', function() {
|
||||
it('explicitly fails and moves to the next function', function() {
|
||||
const err = 'anything except undefined',
|
||||
queueableFn1 = {
|
||||
fn: function(done) {
|
||||
setTimeout(function() {
|
||||
done(err);
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||
failFn = jasmine.createSpy('fail'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1, queueableFn2],
|
||||
fail: failFn
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
expect(queueableFn2.fn).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(failFn).toHaveBeenCalledWith(err);
|
||||
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();
|
||||
});
|
||||
|
||||
it('does not log a deprecation', function(done) {
|
||||
const err = new Error('foo'),
|
||||
queueableFn1 = {
|
||||
fn: function() {
|
||||
return Promise.resolve(err);
|
||||
}
|
||||
},
|
||||
deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1],
|
||||
deprecated: deprecated,
|
||||
onComplete: function() {
|
||||
expect(deprecated).not.toHaveBeenCalled();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
});
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
describe('and the argument is not an Error', function() {
|
||||
it('does not log a deprecation or report a failure', function(done) {
|
||||
const queueableFn1 = {
|
||||
fn: function() {
|
||||
return Promise.resolve('not an error');
|
||||
}
|
||||
},
|
||||
failFn = jasmine.createSpy('fail'),
|
||||
deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1],
|
||||
deprecated: deprecated,
|
||||
fail: failFn,
|
||||
onComplete: function() {
|
||||
expect(deprecated).not.toHaveBeenCalled();
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
expect(queueableFn2.fn).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(failFn).toHaveBeenCalledWith(err);
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
queueRunner.execute();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 = {
|
||||
fn: function(done) {
|
||||
setTimeout(function() {
|
||||
@@ -204,7 +261,8 @@ describe('QueueRunner', 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 },
|
||||
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
|
||||
onComplete = jasmine.createSpy('onComplete'),
|
||||
@@ -225,8 +283,35 @@ describe('QueueRunner', function() {
|
||||
expect(onComplete).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not call onMultipleDone if an asynchrnous function completes after timing out', function() {
|
||||
const timeout = 3;
|
||||
let queueableFnDone;
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
queueableFnDone = done;
|
||||
},
|
||||
type: 'queueable',
|
||||
timeout: timeout
|
||||
};
|
||||
const onComplete = jasmine.createSpy('onComplete');
|
||||
const onMultipleDone = jasmine.createSpy('onMultipleDone');
|
||||
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
onComplete: onComplete,
|
||||
onMultipleDone: onMultipleDone
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick(timeout);
|
||||
queueableFnDone();
|
||||
|
||||
expect(onComplete).toHaveBeenCalled();
|
||||
expect(onMultipleDone).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
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') },
|
||||
onComplete = jasmine.createSpy('onComplete'),
|
||||
onException = jasmine.createSpy('onException'),
|
||||
@@ -247,7 +332,8 @@ describe('QueueRunner', 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) {
|
||||
throw new Error('error!');
|
||||
}
|
||||
@@ -270,7 +356,7 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('clears the timeout when the done callback is called', function() {
|
||||
var queueableFn = {
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
done();
|
||||
}
|
||||
@@ -293,57 +379,65 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('only moves to the next spec the first time you call done', function() {
|
||||
var queueableFn = {
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
done();
|
||||
done();
|
||||
}
|
||||
},
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') },
|
||||
onMultipleDone = jasmine.createSpy('onMultipleDone'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn]
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
onMultipleDone: onMultipleDone
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick(1);
|
||||
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
|
||||
expect(onMultipleDone).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
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) {
|
||||
setTimeout(done, 1);
|
||||
throw new Error('error!');
|
||||
}
|
||||
},
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') },
|
||||
deprecated = jasmine.createSpy('deprecated'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
deprecated: deprecated,
|
||||
queueableFns: [queueableFn, nextQueueableFn]
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick(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() {
|
||||
// Some promises want handlers to return anything but undefined to help catch "forgotten returns".
|
||||
var doneReturn,
|
||||
queueableFn = {
|
||||
fn: function(done) {
|
||||
doneReturn = done();
|
||||
}
|
||||
},
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn]
|
||||
});
|
||||
let doneReturn;
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
doneReturn = done();
|
||||
}
|
||||
};
|
||||
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn]
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
expect(doneReturn).toBe(null);
|
||||
});
|
||||
|
||||
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) {
|
||||
throwAsync();
|
||||
},
|
||||
@@ -394,7 +488,7 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('handles exceptions thrown while waiting for the stack to clear', function() {
|
||||
var queueableFn = {
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
done();
|
||||
}
|
||||
@@ -445,7 +539,7 @@ describe('QueueRunner', 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'),
|
||||
p1 = new StubPromise(),
|
||||
p2 = new StubPromise(),
|
||||
@@ -456,20 +550,20 @@ describe('QueueRunner', function() {
|
||||
}, 100);
|
||||
return p1;
|
||||
}
|
||||
};
|
||||
(queueableFn2 = {
|
||||
fn: function() {
|
||||
fnCallback();
|
||||
setTimeout(function() {
|
||||
p2.resolveHandler();
|
||||
}, 100);
|
||||
return p2;
|
||||
}
|
||||
}),
|
||||
(queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
},
|
||||
queueableFn2 = {
|
||||
fn: function() {
|
||||
fnCallback();
|
||||
setTimeout(function() {
|
||||
p2.resolveHandler();
|
||||
}, 100);
|
||||
return p2;
|
||||
}
|
||||
},
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1, queueableFn2],
|
||||
onComplete: onComplete
|
||||
}));
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
expect(fnCallback).not.toHaveBeenCalled();
|
||||
@@ -486,7 +580,7 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('handles a rejected promise like an unhandled exception', function() {
|
||||
var promise = new StubPromise(),
|
||||
const promise = new StubPromise(),
|
||||
queueableFn1 = {
|
||||
fn: function() {
|
||||
setTimeout(function() {
|
||||
@@ -512,10 +606,52 @@ describe('QueueRunner', function() {
|
||||
expect(onExceptionCallback).toHaveBeenCalledWith('foo');
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('issues an error if the function also takes a parameter', function() {
|
||||
const queueableFn = {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
fn: function(done) {
|
||||
return new StubPromise();
|
||||
}
|
||||
},
|
||||
onException = jasmine.createSpy('onException'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
onException: onException
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(onException).toHaveBeenCalledWith(
|
||||
'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('issues a more specific error if the function is `async`', function() {
|
||||
eval('var fn = async function(done){};');
|
||||
const onException = jasmine.createSpy('onException'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [{ fn: fn }],
|
||||
onException: onException
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(onException).toHaveBeenCalledWith(
|
||||
'An asynchronous ' +
|
||||
'before/it/after function was defined with the async keyword but ' +
|
||||
'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() {
|
||||
var error = new Error('fake error'),
|
||||
const error = new Error('fake error'),
|
||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
onException: onExceptionCallback
|
||||
@@ -528,7 +664,7 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('passes the first argument to exception handlers for compatibility', function() {
|
||||
var error = new Error('fake error'),
|
||||
const error = new Error('fake error'),
|
||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
onException: onExceptionCallback
|
||||
@@ -541,7 +677,7 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('calls exception handlers when an exception is thrown in a fn', function() {
|
||||
var queueableFn = {
|
||||
const queueableFn = {
|
||||
type: 'queueable',
|
||||
fn: function() {
|
||||
throw new Error('fake error');
|
||||
@@ -559,7 +695,8 @@ describe('QueueRunner', 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) {
|
||||
throw new Error('error');
|
||||
}
|
||||
@@ -573,21 +710,84 @@ describe('QueueRunner', function() {
|
||||
expect(nextQueueableFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('When configured with a skip policy', function() {
|
||||
it('instantiates the skip policy', function() {
|
||||
const SkipPolicy = jasmine.createSpy('SkipPolicy ctor');
|
||||
const queueableFns = [{ fn: () => {} }, { fn: () => {} }];
|
||||
|
||||
new jasmineUnderTest.QueueRunner({
|
||||
queueableFns,
|
||||
SkipPolicy
|
||||
});
|
||||
|
||||
expect(SkipPolicy).toHaveBeenCalledWith(queueableFns);
|
||||
});
|
||||
|
||||
it('uses the skip policy to determine which fn to run next', function() {
|
||||
const queueableFns = [
|
||||
{ fn: jasmine.createSpy('fn0') },
|
||||
{ fn: jasmine.createSpy('fn1') },
|
||||
{ fn: jasmine.createSpy('fn2').and.throwError(new Error('nope')) },
|
||||
{ fn: jasmine.createSpy('fn3') }
|
||||
];
|
||||
const skipPolicy = jasmine.createSpyObj('skipPolicy', [
|
||||
'skipTo',
|
||||
'fnErrored'
|
||||
]);
|
||||
skipPolicy.skipTo.and.callFake(function(lastRanIx) {
|
||||
return lastRanIx === 0 ? 2 : lastRanIx + 1;
|
||||
});
|
||||
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns,
|
||||
SkipPolicy: function() {
|
||||
return skipPolicy;
|
||||
}
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(0);
|
||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(2);
|
||||
expect(skipPolicy.fnErrored).toHaveBeenCalledWith(2);
|
||||
expect(queueableFns[0].fn).toHaveBeenCalled();
|
||||
expect(queueableFns[1].fn).not.toHaveBeenCalled();
|
||||
expect(queueableFns[2].fn).toHaveBeenCalled();
|
||||
expect(queueableFns[3].fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws if the skip policy returns the current fn', function() {
|
||||
const skipPolicy = { skipTo: i => i };
|
||||
const queueableFns = [{ fn: () => {} }];
|
||||
const queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns,
|
||||
SkipPolicy: function() {
|
||||
return skipPolicy;
|
||||
}
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
queueRunner.execute();
|
||||
}).toThrowError("Can't skip to the same queueable fn that just finished");
|
||||
});
|
||||
});
|
||||
|
||||
describe('When configured to complete on first error', function() {
|
||||
it('skips to cleanup functions on the first exception', function() {
|
||||
var queueableFn = {
|
||||
const queueableFn = {
|
||||
fn: function() {
|
||||
throw new Error('error');
|
||||
}
|
||||
},
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup') },
|
||||
cleanupFn = {
|
||||
fn: jasmine.createSpy('cleanup'),
|
||||
type: 'specCleanup'
|
||||
},
|
||||
onComplete = jasmine.createSpy('onComplete'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
|
||||
onComplete: onComplete,
|
||||
completeOnFirstError: true
|
||||
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
@@ -599,17 +799,20 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('does not skip when a cleanup function throws', function() {
|
||||
var queueableFn = { fn: function() {} },
|
||||
const queueableFn = { fn: function() {} },
|
||||
cleanupFn1 = {
|
||||
fn: function() {
|
||||
throw new Error('error');
|
||||
}
|
||||
},
|
||||
type: 'afterEach'
|
||||
},
|
||||
cleanupFn2 = {
|
||||
fn: jasmine.createSpy('cleanupFn2'),
|
||||
type: 'afterEach'
|
||||
},
|
||||
cleanupFn2 = { fn: jasmine.createSpy('cleanupFn2') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
cleanupFns: [cleanupFn1, cleanupFn2],
|
||||
completeOnFirstError: true
|
||||
queueableFns: [queueableFn, cleanupFn1, cleanupFn2],
|
||||
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
@@ -625,43 +828,51 @@ describe('QueueRunner', function() {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it('skips to cleanup functions on the first exception', function() {
|
||||
var errorListeners = [],
|
||||
queueableFn = { fn: function(done) {} },
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
globalErrors: {
|
||||
pushListener: function(f) {
|
||||
errorListeners.push(f);
|
||||
},
|
||||
popListener: function() {
|
||||
errorListeners.pop();
|
||||
}
|
||||
it('skips to cleanup functions once the fn completes after an unhandled exception', function() {
|
||||
const errorListeners = [];
|
||||
let queueableFnDone;
|
||||
const queueableFn = {
|
||||
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);
|
||||
},
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true
|
||||
});
|
||||
popListener: function() {
|
||||
errorListeners.pop();
|
||||
}
|
||||
},
|
||||
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
|
||||
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
errorListeners[errorListeners.length - 1](new Error('error'));
|
||||
expect(cleanupFn.fn).not.toHaveBeenCalled();
|
||||
queueableFnDone();
|
||||
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
|
||||
expect(cleanupFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('skips to cleanup functions when next.fail is called', function() {
|
||||
var queueableFn = {
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
done.fail('nope');
|
||||
}
|
||||
},
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup'), type: 'specCleanup' },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true
|
||||
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
|
||||
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
@@ -671,17 +882,19 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('skips to cleanup functions when next is called with an Error', function() {
|
||||
var queueableFn = {
|
||||
const queueableFn = {
|
||||
fn: function(done) {
|
||||
done(new Error('nope'));
|
||||
}
|
||||
},
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup') },
|
||||
cleanupFn = {
|
||||
fn: jasmine.createSpy('cleanup'),
|
||||
type: 'specCleanup'
|
||||
},
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true
|
||||
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
|
||||
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
@@ -693,7 +906,7 @@ describe('QueueRunner', 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'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
@@ -715,7 +928,7 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('calls a provided stack clearing function when done', function() {
|
||||
var asyncFn = {
|
||||
const asyncFn = {
|
||||
fn: function(done) {
|
||||
done();
|
||||
}
|
||||
@@ -744,16 +957,16 @@ describe('QueueRunner', function() {
|
||||
|
||||
describe('when user context has not been defined', function() {
|
||||
beforeEach(function() {
|
||||
var fn;
|
||||
const fn = jasmine.createSpy('fn1');
|
||||
|
||||
this.fn = fn = jasmine.createSpy('fn1');
|
||||
this.fn = fn;
|
||||
this.queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [{ fn: fn }]
|
||||
});
|
||||
});
|
||||
|
||||
it('runs the functions on the scope of a UserContext', function() {
|
||||
var context;
|
||||
let context;
|
||||
this.fn.and.callFake(function() {
|
||||
context = this;
|
||||
});
|
||||
@@ -766,9 +979,10 @@ describe('QueueRunner', function() {
|
||||
|
||||
describe('when user context has been defined', 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.queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [{ fn: fn }],
|
||||
@@ -777,7 +991,7 @@ describe('QueueRunner', function() {
|
||||
});
|
||||
|
||||
it('runs the functions on the scope of a UserContext', function() {
|
||||
var context;
|
||||
let context;
|
||||
this.fn.and.callFake(function() {
|
||||
context = this;
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('ReportDispatcher', function() {
|
||||
it('builds an interface of requested methods', function() {
|
||||
var dispatcher = new jasmineUnderTest.ReportDispatcher([
|
||||
const dispatcher = new jasmineUnderTest.ReportDispatcher([
|
||||
'foo',
|
||||
'bar',
|
||||
'baz'
|
||||
@@ -12,7 +12,7 @@ describe('ReportDispatcher', function() {
|
||||
});
|
||||
|
||||
it('dispatches requested methods to added reporters', function() {
|
||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
const queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
||||
['foo', 'bar'],
|
||||
queueRunnerFactory
|
||||
@@ -36,7 +36,7 @@ describe('ReportDispatcher', function() {
|
||||
})
|
||||
);
|
||||
|
||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
let fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
||||
expect(reporter.foo.calls.mostRecent().object).toBe(reporter);
|
||||
@@ -68,7 +68,7 @@ describe('ReportDispatcher', 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(
|
||||
['foo'],
|
||||
queueRunnerFactory
|
||||
@@ -86,7 +86,7 @@ describe('ReportDispatcher', 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(
|
||||
['foo', 'bar'],
|
||||
queueRunnerFactory
|
||||
@@ -104,13 +104,13 @@ describe('ReportDispatcher', function() {
|
||||
})
|
||||
);
|
||||
|
||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
const fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
||||
});
|
||||
|
||||
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(
|
||||
['foo', 'bar'],
|
||||
queueRunnerFactory
|
||||
@@ -130,14 +130,14 @@ describe('ReportDispatcher', function() {
|
||||
})
|
||||
);
|
||||
|
||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
const fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
||||
expect(fallbackReporter.foo).not.toHaveBeenCalledWith(123, 456);
|
||||
});
|
||||
|
||||
it('allows registered reporters to be cleared', function() {
|
||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
const queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
dispatcher = new jasmineUnderTest.ReportDispatcher(
|
||||
['foo', 'bar'],
|
||||
queueRunnerFactory
|
||||
@@ -155,7 +155,7 @@ describe('ReportDispatcher', function() {
|
||||
})
|
||||
);
|
||||
|
||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
let fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter1.foo).toHaveBeenCalledWith(123);
|
||||
|
||||
|
||||
84
spec/core/SkipAfterBeforeAllErrorPolicySpec.js
Normal file
84
spec/core/SkipAfterBeforeAllErrorPolicySpec.js
Normal file
@@ -0,0 +1,84 @@
|
||||
describe('SkipAfterBeforeAllErrorPolicy', function() {
|
||||
describe('#skipTo', function() {
|
||||
describe('When nothing has errored', function() {
|
||||
it('does not skip anything', function() {
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||
arrayOfArbitraryFns(4)
|
||||
);
|
||||
|
||||
expect(policy.skipTo(0)).toEqual(1);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When anything but a beforeAll has errored', function() {
|
||||
it('does not skip anything', function() {
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||
arrayOfArbitraryFns(4)
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(1);
|
||||
policy.fnErrored(1);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
policy.fnErrored(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
policy.fnErrored(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When a beforeAll has errored', function() {
|
||||
it('skips subsequent functions other than afterAll', function() {
|
||||
const suite = {};
|
||||
const fns = [
|
||||
{ type: 'beforeAll', fn: () => {}, suite },
|
||||
{ fn: () => {} },
|
||||
{ fn: () => {} },
|
||||
{ type: 'afterAll', fn: () => {} },
|
||||
{ type: 'afterAll', fn: () => {} }
|
||||
];
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fnErrored', function() {
|
||||
describe('When the fn is a beforeAll', function() {
|
||||
it("sets the suite's hadBeforeAllFailure property to true", function() {
|
||||
const suite = {};
|
||||
const fns = [{ type: 'beforeAll', fn: () => {}, suite }];
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
|
||||
|
||||
policy.fnErrored(0);
|
||||
|
||||
expect(suite.hadBeforeAllFailure).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the fn is not a beforeAll', function() {
|
||||
it('does not try to access the suite, which is probably not there', function() {
|
||||
const fns = [{ fn: () => {} /* no suite */ }];
|
||||
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(fns);
|
||||
|
||||
expect(() => policy.fnErrored(0)).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function arrayOfArbitraryFns(n) {
|
||||
const result = [];
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
result.push({ fn: () => {} });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
describe('Spec', 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);
|
||||
});
|
||||
|
||||
it('#isPendingSpecException returns true for a pending spec exception (even when FF bug is present)', function() {
|
||||
var fakeError = {
|
||||
const fakeError = {
|
||||
toString: function() {
|
||||
return 'Error: ' + jasmineUnderTest.Spec.pendingSpecExceptionMessage;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ describe('Spec', 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);
|
||||
});
|
||||
@@ -34,7 +34,7 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('delegates execution to a QueueRunner', function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
description: 'my test',
|
||||
id: 'some-id',
|
||||
@@ -48,7 +48,7 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('should call the start callback on execution', function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
startCallback = jasmine.createSpy('startCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
id: 123,
|
||||
@@ -61,34 +61,30 @@ describe('Spec', function() {
|
||||
spec.execute();
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
// TODO: due to some issue with the Pretty Printer, this line fails, but the other two pass.
|
||||
// This means toHaveBeenCalledWith on IE8 will always be broken.
|
||||
|
||||
// expect(startCallback).toHaveBeenCalledWith(spec);
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
expect(startCallback.calls.first().object).toEqual(spec);
|
||||
});
|
||||
|
||||
it('should call the start callback on execution but before any befores are called', function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
beforesWereCalled = false,
|
||||
startCallback = jasmine
|
||||
.createSpy('start-callback')
|
||||
.and.callFake(function() {
|
||||
expect(beforesWereCalled).toBe(false);
|
||||
}),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
beforeFns: function() {
|
||||
return [
|
||||
function() {
|
||||
beforesWereCalled = true;
|
||||
}
|
||||
];
|
||||
},
|
||||
onStart: startCallback,
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner');
|
||||
let beforesWereCalled = false;
|
||||
const startCallback = jasmine
|
||||
.createSpy('start-callback')
|
||||
.and.callFake(function() {
|
||||
expect(beforesWereCalled).toBe(false);
|
||||
});
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
beforeFns: function() {
|
||||
return [
|
||||
function() {
|
||||
beforesWereCalled = true;
|
||||
}
|
||||
];
|
||||
},
|
||||
onStart: startCallback,
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
|
||||
@@ -97,7 +93,7 @@ describe('Spec', 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'),
|
||||
after = jasmine.createSpy('after'),
|
||||
queueableFn = {
|
||||
@@ -116,17 +112,21 @@ describe('Spec', function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
var options = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
const options = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
expect(options.queueableFns).toEqual([
|
||||
{ fn: jasmine.any(Function) },
|
||||
before,
|
||||
queueableFn
|
||||
queueableFn,
|
||||
after,
|
||||
{
|
||||
fn: jasmine.any(Function),
|
||||
type: 'specCleanup'
|
||||
}
|
||||
]);
|
||||
expect(options.cleanupFns).toEqual([after, { fn: jasmine.any(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({
|
||||
queueableFn: { fn: function() {} },
|
||||
beforeAndAfterFns: function() {
|
||||
@@ -145,7 +145,7 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('is marked pending if created without a function body', function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
startCallback = jasmine.createSpy('startCallback'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
@@ -159,7 +159,7 @@ describe('Spec', 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'),
|
||||
specBody = jasmine.createSpy('specBody'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
@@ -175,23 +175,28 @@ describe('Spec', function() {
|
||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
onComplete: jasmine.any(Function),
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
cleanupFns: [{ fn: jasmine.any(Function) }]
|
||||
queueableFns: [
|
||||
{ fn: jasmine.any(Function) },
|
||||
{
|
||||
fn: jasmine.any(Function),
|
||||
type: 'specCleanup'
|
||||
}
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(specBody).not.toHaveBeenCalled();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[0].fn();
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
args.cleanupFns[0].fn();
|
||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||
expect(resultCallback).toHaveBeenCalled();
|
||||
|
||||
expect(spec.result.status).toBe('excluded');
|
||||
});
|
||||
|
||||
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'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
@@ -213,10 +218,10 @@ describe('Spec', function() {
|
||||
|
||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[0].fn();
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
args.cleanupFns[0].fn('things');
|
||||
args.queueableFns[1].fn('things');
|
||||
expect(resultCallback).toHaveBeenCalledWith(
|
||||
{
|
||||
id: spec.id,
|
||||
@@ -228,14 +233,15 @@ describe('Spec', function() {
|
||||
deprecationWarnings: [],
|
||||
pendingReason: '',
|
||||
duration: jasmine.any(Number),
|
||||
properties: null
|
||||
properties: null,
|
||||
debugLogs: null
|
||||
},
|
||||
'things'
|
||||
);
|
||||
});
|
||||
|
||||
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({
|
||||
queueableFn: { fn: function() {} },
|
||||
catchExceptions: function() {
|
||||
@@ -253,7 +259,7 @@ describe('Spec', 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({
|
||||
queueableFn: { fn: function() {} },
|
||||
catchExceptions: function() {
|
||||
@@ -274,34 +280,34 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('should report the duration of the test', function() {
|
||||
var timer = jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||
catchExceptions: function() {
|
||||
return false;
|
||||
},
|
||||
resultCallback: function(result) {
|
||||
duration = result.duration;
|
||||
},
|
||||
queueRunnerFactory: function(config) {
|
||||
config.queueableFns.forEach(function(qf) {
|
||||
qf.fn();
|
||||
});
|
||||
config.cleanupFns.forEach(function(qf) {
|
||||
qf.fn();
|
||||
});
|
||||
config.onComplete();
|
||||
},
|
||||
timer: timer
|
||||
}),
|
||||
duration = undefined;
|
||||
const timer = jasmine.createSpyObj('timer', {
|
||||
start: null,
|
||||
elapsed: 77000
|
||||
});
|
||||
let duration = undefined;
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||
catchExceptions: function() {
|
||||
return false;
|
||||
},
|
||||
resultCallback: function(result) {
|
||||
duration = result.duration;
|
||||
},
|
||||
queueRunnerFactory: function(config) {
|
||||
config.queueableFns.forEach(function(qf) {
|
||||
qf.fn();
|
||||
});
|
||||
config.onComplete();
|
||||
},
|
||||
timer: timer
|
||||
});
|
||||
|
||||
spec.execute(function() {});
|
||||
expect(duration).toBe(77000);
|
||||
});
|
||||
|
||||
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({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||
catchExceptions: function() {
|
||||
@@ -318,14 +324,14 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('#status returns passing by default', function() {
|
||||
var spec = new jasmineUnderTest.Spec({
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') }
|
||||
});
|
||||
expect(spec.status()).toBe('passed');
|
||||
});
|
||||
|
||||
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') }
|
||||
});
|
||||
spec.addExpectationResult(true);
|
||||
@@ -333,7 +339,7 @@ describe('Spec', 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') }
|
||||
});
|
||||
spec.addExpectationResult(true);
|
||||
@@ -342,7 +348,7 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('keeps track of passed and failed expectations', function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||
const fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy('spec body') },
|
||||
@@ -357,7 +363,9 @@ describe('Spec', function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].cleanupFns[0].fn();
|
||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
fns[fns.length - 1].fn();
|
||||
|
||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||
'expectation1'
|
||||
]);
|
||||
@@ -367,7 +375,7 @@ describe('Spec', 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'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
@@ -386,7 +394,8 @@ describe('Spec', function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].cleanupFns[0].fn();
|
||||
const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
fns[fns.length - 1].fn();
|
||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([
|
||||
'passed'
|
||||
]);
|
||||
@@ -396,7 +405,7 @@ describe('Spec', 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({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) {
|
||||
@@ -413,11 +422,11 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('can return its full name', function() {
|
||||
var specNameSpy = jasmine
|
||||
const specNameSpy = jasmine
|
||||
.createSpy('specNameSpy')
|
||||
.and.returnValue('expected val');
|
||||
|
||||
var spec = new jasmineUnderTest.Spec({
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
getSpecName: specNameSpy,
|
||||
queueableFn: { fn: null }
|
||||
});
|
||||
@@ -428,7 +437,7 @@ describe('Spec', function() {
|
||||
|
||||
describe('when a spec is marked pending during execution', function() {
|
||||
it('should mark the spec as pending', function() {
|
||||
var fakeQueueRunner = function(opts) {
|
||||
const fakeQueueRunner = function(opts) {
|
||||
opts.onException(
|
||||
new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage)
|
||||
);
|
||||
@@ -447,7 +456,7 @@ describe('Spec', function() {
|
||||
});
|
||||
|
||||
it('should set the pendingReason', function() {
|
||||
var fakeQueueRunner = function(opts) {
|
||||
const fakeQueueRunner = function(opts) {
|
||||
opts.onException(
|
||||
new Error(
|
||||
jasmineUnderTest.Spec.pendingSpecExceptionMessage +
|
||||
@@ -470,7 +479,7 @@ describe('Spec', 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'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
@@ -484,8 +493,8 @@ describe('Spec', function() {
|
||||
spec.onException('foo');
|
||||
spec.execute();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.cleanupFns[0].fn();
|
||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([
|
||||
{
|
||||
error: 'foo',
|
||||
@@ -498,7 +507,7 @@ describe('Spec', 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'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
@@ -512,8 +521,141 @@ describe('Spec', function() {
|
||||
spec.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||
spec.execute();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.cleanupFns[0].fn();
|
||||
const args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[args.queueableFns.length - 1].fn();
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]);
|
||||
});
|
||||
|
||||
it('treats multiple done calls as late errors', function() {
|
||||
const queueRunnerFactory = jasmine.createSpy('queueRunnerFactory'),
|
||||
onLateError = jasmine.createSpy('onLateError'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
onLateError: onLateError,
|
||||
queueableFn: { fn: function() {} },
|
||||
queueRunnerFactory: queueRunnerFactory,
|
||||
getSpecName: function() {
|
||||
return 'a spec';
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalled();
|
||||
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
||||
|
||||
expect(onLateError).toHaveBeenCalledTimes(1);
|
||||
expect(onLateError.calls.argsFor(0)[0]).toBeInstanceOf(Error);
|
||||
expect(onLateError.calls.argsFor(0)[0].message).toEqual(
|
||||
'An asynchronous spec, beforeEach, or afterEach function called its ' +
|
||||
"'done' callback more than once.\n(in spec: a spec)"
|
||||
);
|
||||
});
|
||||
|
||||
describe('#trace', function() {
|
||||
it('adds the messages to the result', function() {
|
||||
const timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: {
|
||||
fn: function() {}
|
||||
},
|
||||
queueRunnerFactory: function() {},
|
||||
timer: timer
|
||||
}),
|
||||
t1 = 123,
|
||||
t2 = 456;
|
||||
|
||||
spec.execute();
|
||||
expect(spec.result.debugLogs).toBeNull();
|
||||
timer.elapsed.and.returnValue(t1);
|
||||
spec.debugLog('msg 1');
|
||||
expect(spec.result.debugLogs).toEqual([
|
||||
{ message: 'msg 1', timestamp: t1 }
|
||||
]);
|
||||
timer.elapsed.and.returnValue(t2);
|
||||
spec.debugLog('msg 2');
|
||||
expect(spec.result.debugLogs).toEqual([
|
||||
{ message: 'msg 1', timestamp: t1 },
|
||||
{ message: 'msg 2', timestamp: t2 }
|
||||
]);
|
||||
});
|
||||
|
||||
describe('When the spec passes', function() {
|
||||
it('omits the messages from the reported result', function() {
|
||||
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: {
|
||||
fn: function() {}
|
||||
},
|
||||
resultCallback: resultCallback,
|
||||
queueRunnerFactory: function(config) {
|
||||
spec.debugLog('msg');
|
||||
for (const fn of config.queueableFns) {
|
||||
fn.fn();
|
||||
}
|
||||
config.onComplete(false);
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute(function() {});
|
||||
expect(resultCallback).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({ debugLogs: null }),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it('removes the messages to save memory', function() {
|
||||
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: {
|
||||
fn: function() {}
|
||||
},
|
||||
resultCallback: resultCallback,
|
||||
queueRunnerFactory: function(config) {
|
||||
spec.debugLog('msg');
|
||||
for (const fn of config.queueableFns) {
|
||||
fn.fn();
|
||||
}
|
||||
config.onComplete(false);
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute(function() {});
|
||||
expect(resultCallback).toHaveBeenCalled();
|
||||
expect(spec.result.debugLogs).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When the spec fails', function() {
|
||||
it('includes the messages in the reported result', function() {
|
||||
const resultCallback = jasmine.createSpy('resultCallback'),
|
||||
timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: {
|
||||
fn: function() {}
|
||||
},
|
||||
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
|
||||
}),
|
||||
timestamp = 12345;
|
||||
|
||||
timer.elapsed.and.returnValue(timestamp);
|
||||
|
||||
spec.execute(function() {});
|
||||
expect(resultCallback).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
debugLogs: [{ message: 'msg', timestamp: timestamp }]
|
||||
}),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ describe('SpyRegistry', function() {
|
||||
|
||||
describe('#spyOn', function() {
|
||||
it('checks for the existence of the object', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: createSpy
|
||||
});
|
||||
expect(function() {
|
||||
@@ -14,7 +14,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks that a method name was passed', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
subject = {};
|
||||
|
||||
expect(function() {
|
||||
@@ -23,14 +23,14 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks that the object is not `null`', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
expect(function() {
|
||||
spyRegistry.spyOn(null, 'pants');
|
||||
}).toThrowError(/could not find an object/);
|
||||
});
|
||||
|
||||
it('checks that the method name is not `null`', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
subject = {};
|
||||
|
||||
expect(function() {
|
||||
@@ -39,7 +39,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks for the existence of the method', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
subject = {};
|
||||
|
||||
expect(function() {
|
||||
@@ -48,7 +48,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks if it has already been spied upon', function() {
|
||||
var spies = [],
|
||||
const spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -65,7 +65,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks if it can be spied upon', function() {
|
||||
var scope = {};
|
||||
const scope = {};
|
||||
|
||||
function myFunc() {
|
||||
return 1;
|
||||
@@ -77,7 +77,7 @@ describe('SpyRegistry', function() {
|
||||
}
|
||||
});
|
||||
|
||||
var spies = [],
|
||||
const spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -95,7 +95,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('overrides the method on the object and returns the spy', function() {
|
||||
var originalFunctionWasCalled = false,
|
||||
const originalFunctionWasCalled = false,
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
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);
|
||||
subject.spiedFunc();
|
||||
@@ -115,14 +115,14 @@ describe('SpyRegistry', function() {
|
||||
|
||||
describe('#spyOnProperty', function() {
|
||||
it('checks for the existence of the object', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
expect(function() {
|
||||
spyRegistry.spyOnProperty(void 0, 'pants');
|
||||
}).toThrowError(/could not find an object/);
|
||||
});
|
||||
|
||||
it('checks that a property name was passed', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
subject = {};
|
||||
|
||||
expect(function() {
|
||||
@@ -131,7 +131,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks for the existence of the method', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
subject = {};
|
||||
|
||||
expect(function() {
|
||||
@@ -140,7 +140,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks for the existence of access type', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
subject = {};
|
||||
|
||||
Object.defineProperty(subject, 'pants', {
|
||||
@@ -156,7 +156,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('checks if it can be spied upon', function() {
|
||||
var subject = {};
|
||||
const subject = {};
|
||||
|
||||
Object.defineProperty(subject, 'myProp', {
|
||||
get: function() {}
|
||||
@@ -167,7 +167,7 @@ describe('SpyRegistry', function() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
|
||||
expect(function() {
|
||||
spyRegistry.spyOnProperty(subject, 'myProp');
|
||||
@@ -179,7 +179,7 @@ describe('SpyRegistry', 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
|
||||
}),
|
||||
subject = {},
|
||||
@@ -194,8 +194,8 @@ describe('SpyRegistry', function() {
|
||||
|
||||
expect(subject.spiedProperty).toEqual(returnValue);
|
||||
|
||||
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty');
|
||||
var getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
||||
const spy = spyRegistry.spyOnProperty(subject, 'spiedProperty');
|
||||
const getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
||||
.get;
|
||||
|
||||
expect(getter).toEqual(spy);
|
||||
@@ -203,7 +203,7 @@ describe('SpyRegistry', 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
|
||||
}),
|
||||
subject = {},
|
||||
@@ -217,8 +217,8 @@ describe('SpyRegistry', function() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set');
|
||||
var setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
||||
const spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set');
|
||||
const setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty')
|
||||
.set;
|
||||
|
||||
expect(subject.spiedProperty).toEqual(returnValue);
|
||||
@@ -227,7 +227,7 @@ describe('SpyRegistry', function() {
|
||||
|
||||
describe('when the property is already spied upon', function() {
|
||||
it('throws an error if respy is not allowed', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: createSpy
|
||||
}),
|
||||
subject = {};
|
||||
@@ -247,7 +247,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('returns the original spy if respy is allowed', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: createSpy
|
||||
}),
|
||||
subject = {};
|
||||
@@ -261,7 +261,7 @@ describe('SpyRegistry', function() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
var originalSpy = spyRegistry.spyOnProperty(subject, 'spiedProp');
|
||||
const originalSpy = spyRegistry.spyOnProperty(subject, 'spiedProp');
|
||||
|
||||
expect(spyRegistry.spyOnProperty(subject, 'spiedProp')).toBe(
|
||||
originalSpy
|
||||
@@ -272,33 +272,33 @@ describe('SpyRegistry', function() {
|
||||
|
||||
describe('#spyOnAllFunctions', function() {
|
||||
it('checks for the existence of the object', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
expect(function() {
|
||||
spyRegistry.spyOnAllFunctions(void 0);
|
||||
}).toThrowError(/spyOnAllFunctions could not find an object to spy upon/);
|
||||
});
|
||||
|
||||
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() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var createNoop = function() {
|
||||
const createNoop = function() {
|
||||
return function() {
|
||||
/**/
|
||||
};
|
||||
};
|
||||
var noop1 = createNoop();
|
||||
var noop2 = createNoop();
|
||||
var noop3 = createNoop();
|
||||
var noop4 = createNoop();
|
||||
var noop5 = createNoop();
|
||||
const noop1 = createNoop();
|
||||
const noop2 = createNoop();
|
||||
const noop3 = createNoop();
|
||||
const noop4 = createNoop();
|
||||
const noop5 = createNoop();
|
||||
|
||||
var parent = {
|
||||
const parent = {
|
||||
parentSpied1: noop1
|
||||
};
|
||||
var subject = Object.create(parent);
|
||||
const subject = Object.create(parent);
|
||||
Object.defineProperty(subject, 'spied1', {
|
||||
value: noop1,
|
||||
writable: true,
|
||||
@@ -311,7 +311,7 @@ describe('SpyRegistry', function() {
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
var _spied3 = noop3;
|
||||
let _spied3 = noop3;
|
||||
Object.defineProperty(subject, 'spied3', {
|
||||
configurable: true,
|
||||
set: function(val) {
|
||||
@@ -337,7 +337,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
Object.defineProperty(subject, 'notSpied4', {
|
||||
configurable: false,
|
||||
set: function(val) {
|
||||
set: function() {
|
||||
/**/
|
||||
},
|
||||
get: function() {
|
||||
@@ -353,7 +353,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
subject.notSpied6 = 6;
|
||||
|
||||
var spiedObject = spyRegistry.spyOnAllFunctions(subject);
|
||||
const spiedObject = spyRegistry.spyOnAllFunctions(subject);
|
||||
|
||||
expect(subject.parentSpied1).toBe('I am a spy');
|
||||
expect(subject.notSpied2).toBe(noop2);
|
||||
@@ -369,21 +369,21 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it('overrides prototype methods on the object', function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
|
||||
var noop1 = function() {};
|
||||
var noop2 = function() {};
|
||||
const noop1 = function() {};
|
||||
const noop2 = function() {};
|
||||
|
||||
var MyClass = function() {
|
||||
const MyClass = function() {
|
||||
this.spied1 = noop1;
|
||||
};
|
||||
MyClass.prototype.spied2 = noop2;
|
||||
|
||||
var subject = new MyClass();
|
||||
const subject = new MyClass();
|
||||
spyRegistry.spyOnAllFunctions(subject);
|
||||
|
||||
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() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
var subject = {
|
||||
const subject = {
|
||||
spied1: function() {}
|
||||
};
|
||||
|
||||
@@ -407,11 +407,128 @@ describe('SpyRegistry', function() {
|
||||
expect(subject.toString).not.toBe('I am a spy');
|
||||
expect(subject.hasOwnProperty).not.toBe('I am a spy');
|
||||
});
|
||||
describe('when includeNonEnumerable is true', function() {
|
||||
it('does not override Object.prototype methods', function() {
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
const subject = {
|
||||
spied1: function() {}
|
||||
};
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.spied1).toBe('I am a spy');
|
||||
expect(subject.toString).not.toBe('I am a spy');
|
||||
expect(subject.hasOwnProperty).not.toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('overrides non-enumerable properties', function() {
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
const subject = {
|
||||
spied1: function() {},
|
||||
spied2: function() {}
|
||||
};
|
||||
|
||||
Object.defineProperty(subject, 'spied2', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.spied1).toBe('I am a spy');
|
||||
expect(subject.spied2).toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('should not spy on non-enumerable functions named constructor', function() {
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
const subject = {
|
||||
constructor: function() {}
|
||||
};
|
||||
|
||||
Object.defineProperty(subject, 'constructor', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.constructor).not.toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('should spy on enumerable functions named constructor', function() {
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
const subject = {
|
||||
constructor: function() {}
|
||||
};
|
||||
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
|
||||
expect(subject.constructor).toBe('I am a spy');
|
||||
});
|
||||
|
||||
it('should not throw an exception if we try and access strict mode restricted properties', function() {
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
const subject = function() {};
|
||||
const fn = function() {
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
};
|
||||
|
||||
expect(fn).not.toThrow();
|
||||
});
|
||||
|
||||
it('should not spy on properties which are more permissable further up the prototype chain', function() {
|
||||
const spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
createSpy: function() {
|
||||
return 'I am a spy';
|
||||
}
|
||||
});
|
||||
const subjectParent = Object.defineProperty({}, 'sharedProp', {
|
||||
value: function() {},
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const subject = Object.create(subjectParent);
|
||||
|
||||
Object.defineProperty(subject, 'sharedProp', {
|
||||
value: function() {}
|
||||
});
|
||||
|
||||
const fn = function() {
|
||||
spyRegistry.spyOnAllFunctions(subject, true);
|
||||
};
|
||||
|
||||
expect(fn).not.toThrow();
|
||||
expect(subject).not.toBe('I am a spy');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clearSpies', function() {
|
||||
it('restores the original functions on the spied-upon objects', function() {
|
||||
var spies = [],
|
||||
const spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -428,7 +545,7 @@ describe('SpyRegistry', 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({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -452,7 +569,7 @@ describe('SpyRegistry', 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({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -462,7 +579,7 @@ describe('SpyRegistry', function() {
|
||||
originalFunction = function() {},
|
||||
subjectParent = { spiedFunc: originalFunction };
|
||||
|
||||
var subject = Object.create(subjectParent);
|
||||
const subject = Object.create(subjectParent);
|
||||
|
||||
expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
|
||||
|
||||
@@ -474,7 +591,7 @@ describe('SpyRegistry', function() {
|
||||
});
|
||||
|
||||
it("restores the original function when it's inherited and cannot be deleted", function() {
|
||||
var spies = [],
|
||||
const spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -484,7 +601,7 @@ describe('SpyRegistry', function() {
|
||||
originalFunction = function() {},
|
||||
subjectParent = { spiedFunc: originalFunction };
|
||||
|
||||
var subject = Object.create(subjectParent);
|
||||
const subject = Object.create(subjectParent);
|
||||
|
||||
spyRegistry.spyOn(subject, 'spiedFunc');
|
||||
|
||||
@@ -502,7 +619,7 @@ describe('SpyRegistry', function() {
|
||||
function FakeWindow() {}
|
||||
FakeWindow.prototype.onerror = function() {};
|
||||
|
||||
var spies = [],
|
||||
const spies = [],
|
||||
global = new FakeWindow(),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
@@ -521,7 +638,7 @@ describe('SpyRegistry', function() {
|
||||
|
||||
describe('spying on properties', function() {
|
||||
it('restores the original properties on the spied-upon objects', function() {
|
||||
var spies = [],
|
||||
const spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -545,7 +662,7 @@ describe('SpyRegistry', 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({
|
||||
currentSpies: function() {
|
||||
return spies;
|
||||
@@ -562,7 +679,7 @@ describe('SpyRegistry', function() {
|
||||
configurable: true
|
||||
});
|
||||
|
||||
var subject = Object.create(subjectParent);
|
||||
const subject = Object.create(subjectParent);
|
||||
|
||||
expect(subject.hasOwnProperty('spiedProp')).toBe(false);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe('Spies', function() {
|
||||
var env;
|
||||
let env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
@@ -10,7 +10,7 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
describe('createSpy', function() {
|
||||
var TestClass;
|
||||
let TestClass;
|
||||
|
||||
beforeEach(function() {
|
||||
TestClass = function() {};
|
||||
@@ -19,7 +19,7 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
it('preserves the properties of the spied function', function() {
|
||||
var spy = env.createSpy(
|
||||
const spy = env.createSpy(
|
||||
TestClass.prototype,
|
||||
TestClass.prototype.someFunction
|
||||
);
|
||||
@@ -28,15 +28,10 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
it('should allow you to omit the name argument and only pass the originalFn argument', function() {
|
||||
var fn = function test() {};
|
||||
var spy = env.createSpy(fn);
|
||||
const fn = function test() {};
|
||||
const spy = env.createSpy(fn);
|
||||
|
||||
// IE doesn't do `.name`
|
||||
if (fn.name === 'test') {
|
||||
expect(spy.and.identity).toEqual('test');
|
||||
} else {
|
||||
expect(spy.and.identity).toEqual('unknown');
|
||||
}
|
||||
expect(spy.and.identity).toEqual('test');
|
||||
});
|
||||
|
||||
it('warns the user that we intend to overwrite an existing property', function() {
|
||||
@@ -50,7 +45,7 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
it('adds a spyStrategy and callTracker to the spy', function() {
|
||||
var spy = env.createSpy(
|
||||
const spy = env.createSpy(
|
||||
TestClass.prototype,
|
||||
TestClass.prototype.someFunction
|
||||
);
|
||||
@@ -60,11 +55,11 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
it('tracks the argument of calls', function() {
|
||||
var spy = env.createSpy(
|
||||
const spy = env.createSpy(
|
||||
TestClass.prototype,
|
||||
TestClass.prototype.someFunction
|
||||
);
|
||||
var trackSpy = spyOn(spy.calls, 'track');
|
||||
const trackSpy = spyOn(spy.calls, 'track');
|
||||
|
||||
spy('arg');
|
||||
|
||||
@@ -72,24 +67,24 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
it('tracks the context of calls', function() {
|
||||
var spy = env.createSpy(
|
||||
const spy = env.createSpy(
|
||||
TestClass.prototype,
|
||||
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();
|
||||
|
||||
expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
|
||||
});
|
||||
|
||||
it('tracks the return value of calls', function() {
|
||||
var spy = env.createSpy(
|
||||
const spy = env.createSpy(
|
||||
TestClass.prototype,
|
||||
TestClass.prototype.someFunction
|
||||
);
|
||||
var trackSpy = spyOn(spy.calls, 'track');
|
||||
const trackSpy = spyOn(spy.calls, 'track');
|
||||
|
||||
spy.and.returnValue('return value');
|
||||
spy();
|
||||
@@ -100,18 +95,24 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
it('preserves arity of original function', function() {
|
||||
var functions = [
|
||||
const functions = [
|
||||
function nullary() {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function unary(arg) {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function binary(arg1, arg2) {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function ternary(arg1, arg2, arg3) {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function quaternary(arg1, arg2, arg3, arg4) {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function quinary(arg1, arg2, arg3, arg4, arg5) {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function senary(arg1, arg2, arg3, arg4, arg5, arg6) {}
|
||||
];
|
||||
|
||||
for (var arity = 0; arity < functions.length; arity++) {
|
||||
var someFunction = functions[arity],
|
||||
for (let arity = 0; arity < functions.length; arity++) {
|
||||
const someFunction = functions[arity],
|
||||
spy = env.createSpy(someFunction.name, someFunction);
|
||||
|
||||
expect(spy.length).toEqual(arity);
|
||||
@@ -121,7 +122,7 @@ describe('Spies', 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() {
|
||||
var spyObj = env.createSpyObj('BaseName', {
|
||||
const spyObj = env.createSpyObj('BaseName', {
|
||||
method1: 42,
|
||||
method2: 'special sauce'
|
||||
});
|
||||
@@ -134,7 +135,7 @@ describe('Spies', 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({
|
||||
method1: jasmine.any(Function),
|
||||
@@ -145,7 +146,7 @@ describe('Spies', 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({
|
||||
method1: jasmine.any(Function),
|
||||
@@ -180,27 +181,28 @@ describe('Spies', 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({
|
||||
method1: jasmine.any(Function)
|
||||
method1: jasmine.any(Function),
|
||||
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.set.and.identity).toEqual('base.prop1.set');
|
||||
|
||||
expect(spyObj.prop1).toBeUndefined();
|
||||
});
|
||||
|
||||
it('creates an object with property names and return values if second object is passed', function() {
|
||||
var spyObj = env.createSpyObj('base', ['method1'], {
|
||||
const spyObj = env.createSpyObj('base', ['method1'], {
|
||||
prop1: 'foo',
|
||||
prop2: 37
|
||||
});
|
||||
|
||||
expect(spyObj).toEqual({
|
||||
method1: jasmine.any(Function)
|
||||
method1: jasmine.any(Function),
|
||||
prop1: 'foo',
|
||||
prop2: 37
|
||||
});
|
||||
|
||||
expect(spyObj.prop1).toEqual('foo');
|
||||
@@ -212,8 +214,8 @@ describe('Spies', function() {
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it('allows base name to be ommitted when assigning methods and properties', function() {
|
||||
var spyObj = env.createSpyObj({ m: 3 }, { p: 4 });
|
||||
it('allows base name to be omitted when assigning methods and properties', function() {
|
||||
const spyObj = env.createSpyObj({ m: 3 }, { p: 4 });
|
||||
|
||||
expect(spyObj.m()).toEqual(3);
|
||||
expect(spyObj.p).toEqual(4);
|
||||
@@ -224,7 +226,7 @@ describe('Spies', 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.withArgs('baz', 'grault').and.returnValue(-1);
|
||||
spy.withArgs('thud').and.returnValue('bob');
|
||||
@@ -235,8 +237,8 @@ describe('Spies', function() {
|
||||
expect(spy('baz', 'grault', 'waldo')).toEqual(42);
|
||||
});
|
||||
|
||||
it('uses custom equality testers when selecting a strategy', function() {
|
||||
var spy = env.createSpy('foo');
|
||||
it('uses asymmetric equality testers when selecting a strategy', function() {
|
||||
const spy = env.createSpy('foo');
|
||||
spy.and.returnValue(42);
|
||||
spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
|
||||
|
||||
@@ -244,18 +246,33 @@ describe('Spies', function() {
|
||||
expect(spy({})).toEqual(42);
|
||||
});
|
||||
|
||||
it('uses the provided matchersUtil selecting a strategy', function() {
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: [
|
||||
function(a, b) {
|
||||
if ((a === 'bar' && b === 'baz') || (a === 'baz' && b === 'bar')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
const spy = new jasmineUnderTest.Spy('aSpy', matchersUtil);
|
||||
spy.and.returnValue('default strategy return value');
|
||||
spy.withArgs('bar').and.returnValue('custom strategy return value');
|
||||
expect(spy('foo')).toEqual('default strategy return value');
|
||||
expect(spy('baz')).toEqual('custom strategy return value');
|
||||
});
|
||||
|
||||
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(17);
|
||||
expect(spy('foo')).toEqual(17);
|
||||
});
|
||||
|
||||
describe('any promise-based strategy', function() {
|
||||
it('works with global Promise library when available', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var spy = env.createSpy('foo').and.resolveTo(42);
|
||||
it('works with global Promise library', function(done) {
|
||||
const spy = env.createSpy('foo').and.resolveTo(42);
|
||||
spy()
|
||||
.then(function(result) {
|
||||
expect(result).toEqual(42);
|
||||
@@ -263,31 +280,18 @@ describe('Spies', function() {
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('works with a custom Promise library', function() {
|
||||
var customPromise = {
|
||||
resolve: jasmine.createSpy(),
|
||||
reject: jasmine.createSpy()
|
||||
};
|
||||
customPromise.resolve.and.returnValue('resolved');
|
||||
env.configure({ Promise: customPromise });
|
||||
|
||||
var spy = env.createSpy('foo').and.resolveTo(42);
|
||||
expect(spy()).toEqual('resolved');
|
||||
expect(customPromise.resolve).toHaveBeenCalledWith(42);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when withArgs is used without a base strategy', function() {
|
||||
it('uses the matching strategy', function() {
|
||||
var spy = env.createSpy('foo');
|
||||
const spy = env.createSpy('foo');
|
||||
spy.withArgs('baz').and.returnValue(-1);
|
||||
|
||||
expect(spy('baz')).toEqual(-1);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
expect(function() {
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
describe('SpyStrategy', function() {
|
||||
it('defaults its name to unknown', function() {
|
||||
var spyStrategy = new jasmineUnderTest.SpyStrategy();
|
||||
const spyStrategy = new jasmineUnderTest.SpyStrategy();
|
||||
|
||||
expect(spyStrategy.identity).toEqual('unknown');
|
||||
});
|
||||
|
||||
it('takes a name', function() {
|
||||
var spyStrategy = new jasmineUnderTest.SpyStrategy({ name: 'foo' });
|
||||
const spyStrategy = new jasmineUnderTest.SpyStrategy({ name: 'foo' });
|
||||
|
||||
expect(spyStrategy.identity).toEqual('foo');
|
||||
});
|
||||
|
||||
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.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() {
|
||||
var originalFn = jasmine.createSpy('original').and.returnValue(42),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
||||
returnValue;
|
||||
const originalFn = jasmine.createSpy('original').and.returnValue(42),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
spyStrategy.callThrough();
|
||||
returnValue = spyStrategy.exec(null, ['foo']);
|
||||
const returnValue = spyStrategy.exec(null, ['foo']);
|
||||
|
||||
expect(originalFn).toHaveBeenCalled();
|
||||
expect(originalFn.calls.mostRecent().args).toEqual(['foo']);
|
||||
@@ -34,19 +33,18 @@ describe('SpyStrategy', function() {
|
||||
});
|
||||
|
||||
it('can return a specified value when executed', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
||||
returnValue;
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
spyStrategy.returnValue(17);
|
||||
returnValue = spyStrategy.exec();
|
||||
const returnValue = spyStrategy.exec();
|
||||
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
expect(returnValue).toEqual(17);
|
||||
});
|
||||
|
||||
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.returnValues('value1', 'value2', 'value3');
|
||||
@@ -59,7 +57,7 @@ describe('SpyStrategy', 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.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() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
spyStrategy.throwError('bar');
|
||||
@@ -83,33 +81,31 @@ describe('SpyStrategy', 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.throwError({ code: 'ESRCH' });
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.exec();
|
||||
}).toThrow({ code: 'ESRCH' });
|
||||
}).toThrow(jasmine.objectContaining({ code: 'ESRCH' }));
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
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),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
||||
returnValue;
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
spyStrategy.callFake(fakeFn);
|
||||
returnValue = spyStrategy.exec();
|
||||
const returnValue = spyStrategy.exec();
|
||||
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
expect(returnValue).toEqual(67);
|
||||
});
|
||||
|
||||
it('allows a fake async function to be called instead', function(done) {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
fakeFn = jasmine
|
||||
.createSpy('fake')
|
||||
.and.callFake(eval('async () => { return 67; }')),
|
||||
@@ -131,15 +127,9 @@ describe('SpyStrategy', function() {
|
||||
|
||||
describe('#resolveTo', function() {
|
||||
it('allows a resolved promise to be returned', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.resolveTo(37);
|
||||
@@ -153,15 +143,9 @@ describe('SpyStrategy', function() {
|
||||
});
|
||||
|
||||
it('allows an empty resolved promise to be returned', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.resolveTo();
|
||||
@@ -173,30 +157,13 @@ describe('SpyStrategy', function() {
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('fails if promises are not available', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.resolveTo(37);
|
||||
}).toThrowError(
|
||||
'resolveTo requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#rejectWith', function() {
|
||||
it('allows a rejected promise to be returned', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.rejectWith(new Error('oops'));
|
||||
@@ -211,15 +178,9 @@ describe('SpyStrategy', function() {
|
||||
});
|
||||
|
||||
it('allows an empty rejected promise to be returned', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.rejectWith();
|
||||
@@ -234,15 +195,9 @@ describe('SpyStrategy', function() {
|
||||
});
|
||||
|
||||
it('allows a non-Error to be rejected', function(done) {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.rejectWith('oops');
|
||||
@@ -255,21 +210,10 @@ describe('SpyStrategy', function() {
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('fails if promises are not available', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.rejectWith(new Error('oops'));
|
||||
}).toThrowError(
|
||||
'rejectWith requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('allows a custom strategy to be used', function() {
|
||||
var plan = jasmine
|
||||
const plan = jasmine
|
||||
.createSpy('custom strategy')
|
||||
.and.returnValue('custom strategy result'),
|
||||
customStrategy = jasmine
|
||||
@@ -292,7 +236,7 @@ describe('SpyStrategy', 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({
|
||||
fn: originalFn,
|
||||
customStrategies: {
|
||||
@@ -308,7 +252,7 @@ describe('SpyStrategy', function() {
|
||||
});
|
||||
|
||||
it('does not allow custom strategies to overwrite existing methods', function() {
|
||||
var spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
const spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: function() {},
|
||||
customStrategies: {
|
||||
exec: function() {}
|
||||
@@ -319,7 +263,7 @@ describe('SpyStrategy', 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 });
|
||||
|
||||
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
|
||||
@@ -334,14 +278,24 @@ describe('SpyStrategy', function() {
|
||||
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
||||
});
|
||||
|
||||
it('allows generator functions to be passed to callFake strategy', function() {
|
||||
const generator = function*() {
|
||||
yield 'ok';
|
||||
},
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
|
||||
|
||||
spyStrategy.callFake(generator);
|
||||
|
||||
expect(spyStrategy.exec().next().value).toEqual('ok');
|
||||
});
|
||||
|
||||
it('allows a return to plan stubbing after another strategy', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
const originalFn = jasmine.createSpy('original'),
|
||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
|
||||
returnValue;
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
spyStrategy.callFake(fakeFn);
|
||||
returnValue = spyStrategy.exec();
|
||||
let returnValue = spyStrategy.exec();
|
||||
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
expect(returnValue).toEqual(67);
|
||||
@@ -353,7 +307,7 @@ describe('SpyStrategy', function() {
|
||||
});
|
||||
|
||||
it('returns the spy after changing the strategy', function() {
|
||||
var spy = {},
|
||||
const spy = {},
|
||||
spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ getSpy: spyFn });
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('StackTrace', function() {
|
||||
it('understands Chrome/IE/Edge style traces', function() {
|
||||
var error = {
|
||||
it('understands Chrome/Edge style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'Error: nope\n' +
|
||||
@@ -8,7 +8,7 @@ describe('StackTrace', function() {
|
||||
' 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.style).toEqual('v8');
|
||||
@@ -30,8 +30,8 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Chrome/IE/Edge style traces with multiline messages', function() {
|
||||
var error = {
|
||||
it('understands Chrome/Edge style traces with multiline messages', function() {
|
||||
const error = {
|
||||
message: 'line 1\nline 2',
|
||||
stack:
|
||||
'Error: line 1\nline 2\n' +
|
||||
@@ -39,10 +39,10 @@ describe('StackTrace', function() {
|
||||
' 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');
|
||||
var rawFrames = result.frames.map(function(f) {
|
||||
const rawFrames = result.frames.map(function(f) {
|
||||
return f.raw;
|
||||
});
|
||||
expect(rawFrames).toEqual([
|
||||
@@ -52,7 +52,7 @@ describe('StackTrace', function() {
|
||||
});
|
||||
|
||||
it('understands Node style traces', function() {
|
||||
var error = {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'Error\n' +
|
||||
@@ -61,7 +61,7 @@ describe('StackTrace', function() {
|
||||
' at Immediate.<anonymous> (/somewhere/jasmine/lib/jasmine-core/jasmine.js:4314:12)\n' +
|
||||
' 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.style).toEqual('v8');
|
||||
@@ -95,14 +95,14 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Safari/Firefox/Phantom-OS X style traces', function() {
|
||||
var error = {
|
||||
it('understands Safari <=14/Firefox/Phantom-OS X style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'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.style).toEqual('webkit');
|
||||
@@ -122,25 +122,52 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Safari 15 style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'@http://localhost:8888/__spec__/core/FooSpec.js:164:24\n' +
|
||||
'attempt@http://localhost:8888/__jasmine__/jasmine.js:8074:44\n'
|
||||
};
|
||||
const result = new jasmineUnderTest.StackTrace(error);
|
||||
|
||||
expect(result.message).toBeFalsy();
|
||||
expect(result.style).toEqual('webkit');
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw: '@http://localhost:8888/__spec__/core/FooSpec.js:164:24',
|
||||
func: undefined,
|
||||
file: 'http://localhost:8888/__spec__/core/FooSpec.js',
|
||||
line: 164
|
||||
},
|
||||
{
|
||||
raw: 'attempt@http://localhost:8888/__jasmine__/jasmine.js:8074:44',
|
||||
func: 'attempt',
|
||||
file: 'http://localhost:8888/__jasmine__/jasmine.js',
|
||||
line: 8074
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not mistake gibberish for Safari/Firefox/Phantom-OS X style traces', function() {
|
||||
var error = {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack: 'randomcharsnotincludingwhitespace'
|
||||
};
|
||||
var result = new jasmineUnderTest.StackTrace(error);
|
||||
const result = new jasmineUnderTest.StackTrace(error);
|
||||
expect(result.style).toBeNull();
|
||||
expect(result.frames).toEqual([{ raw: error.stack }]);
|
||||
});
|
||||
|
||||
it('understands Phantom-Linux style traces', function() {
|
||||
var error = {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||
};
|
||||
|
||||
var result = new jasmineUnderTest.StackTrace(error);
|
||||
const result = new jasmineUnderTest.StackTrace(error);
|
||||
|
||||
expect(result.message).toBeFalsy();
|
||||
expect(result.style).toEqual('v8');
|
||||
@@ -163,13 +190,13 @@ describe('StackTrace', function() {
|
||||
});
|
||||
|
||||
it('ignores blank lines', function() {
|
||||
var error = {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
' 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([
|
||||
{
|
||||
@@ -183,7 +210,7 @@ describe('StackTrace', function() {
|
||||
});
|
||||
|
||||
it("omits properties except 'raw' for frames that are not understood", function() {
|
||||
var error = {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
@@ -191,7 +218,7 @@ describe('StackTrace', function() {
|
||||
' 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.frames).toEqual([
|
||||
{
|
||||
@@ -215,7 +242,7 @@ describe('StackTrace', function() {
|
||||
});
|
||||
|
||||
it('consideres different types of errors', function() {
|
||||
var error = {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'TypeError: nope\n' +
|
||||
@@ -223,7 +250,7 @@ describe('StackTrace', function() {
|
||||
' 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.frames).toEqual([
|
||||
@@ -243,7 +270,7 @@ describe('StackTrace', function() {
|
||||
}
|
||||
]);
|
||||
|
||||
var no_error = {
|
||||
const no_error = {
|
||||
message: 'nope',
|
||||
stack:
|
||||
'Type Error: nope\n' +
|
||||
@@ -251,7 +278,7 @@ describe('StackTrace', function() {
|
||||
' 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());
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe('Suite', function() {
|
||||
var env;
|
||||
let env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
@@ -10,7 +10,7 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
it('keeps its id', function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
id: 456,
|
||||
description: 'I am a suite'
|
||||
@@ -20,7 +20,7 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
it('returns blank full name for top level suite', function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
});
|
||||
@@ -29,7 +29,7 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
it('returns its full name when it has parent suites', function() {
|
||||
var parentSuite = new jasmineUnderTest.Suite({
|
||||
const parentSuite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a parent suite',
|
||||
parentSuite: jasmine.createSpy('pretend top level suite')
|
||||
@@ -43,36 +43,87 @@ describe('Suite', function() {
|
||||
expect(suite.getFullName()).toEqual('I am a parent suite I am a suite');
|
||||
});
|
||||
|
||||
it('adds before functions in order of needed execution', function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
it('adds beforeEach functions in order of needed execution', function() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
outerBefore = jasmine.createSpy('outerBeforeEach'),
|
||||
innerBefore = jasmine.createSpy('insideBeforeEach');
|
||||
outerBefore = { fn: 'outerBeforeEach' },
|
||||
innerBefore = { fn: 'insideBeforeEach' };
|
||||
|
||||
suite.beforeEach(outerBefore);
|
||||
suite.beforeEach(innerBefore);
|
||||
|
||||
expect(suite.beforeFns).toEqual([innerBefore, outerBefore]);
|
||||
expect(suite.beforeFns).toEqual([
|
||||
{ fn: innerBefore.fn, suite },
|
||||
{ fn: outerBefore.fn, suite }
|
||||
]);
|
||||
});
|
||||
|
||||
it('adds after functions in order of needed execution', function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
it('adds beforeAll functions in order of needed execution', function() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
outerAfter = jasmine.createSpy('outerAfterEach'),
|
||||
innerAfter = jasmine.createSpy('insideAfterEach');
|
||||
outerBefore = { fn: 'outerBeforeAll' },
|
||||
innerBefore = { fn: 'insideBeforeAll' };
|
||||
|
||||
suite.beforeAll(outerBefore);
|
||||
suite.beforeAll(innerBefore);
|
||||
|
||||
function sameInstance(expected) {
|
||||
return {
|
||||
asymmetricMatch: function(actual) {
|
||||
return actual === expected;
|
||||
},
|
||||
jasmineToString: function() {
|
||||
return `<same instance as ${expected}>`;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
expect(suite.beforeAllFns).toEqual([
|
||||
{ fn: outerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) },
|
||||
{ fn: innerBefore.fn, type: 'beforeAll', suite: sameInstance(suite) }
|
||||
]);
|
||||
});
|
||||
|
||||
it('adds afterEach functions in order of needed execution', function() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
outerAfter = { fn: 'outerAfterEach' },
|
||||
innerAfter = { fn: 'insideAfterEach' };
|
||||
|
||||
suite.afterEach(outerAfter);
|
||||
suite.afterEach(innerAfter);
|
||||
|
||||
expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
|
||||
expect(suite.afterFns).toEqual([
|
||||
{ fn: innerAfter.fn, suite, type: 'afterEach' },
|
||||
{ fn: outerAfter.fn, suite, type: 'afterEach' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('adds afterAll functions in order of needed execution', function() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
outerAfter = { fn: 'outerAfterAll' },
|
||||
innerAfter = { fn: 'insideAfterAl' };
|
||||
|
||||
suite.afterAll(outerAfter);
|
||||
suite.afterAll(innerAfter);
|
||||
|
||||
expect(suite.afterAllFns).toEqual([
|
||||
{ fn: innerAfter.fn, type: 'afterAll' },
|
||||
{ fn: outerAfter.fn, type: 'afterAll' }
|
||||
]);
|
||||
});
|
||||
|
||||
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';
|
||||
}
|
||||
@@ -83,20 +134,20 @@ describe('Suite', 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');
|
||||
});
|
||||
|
||||
it('retrieves a result with pending status', function() {
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
const suite = new jasmineUnderTest.Suite({});
|
||||
suite.pend();
|
||||
|
||||
expect(suite.getResult().status).toBe('pending');
|
||||
});
|
||||
|
||||
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;
|
||||
},
|
||||
@@ -112,7 +163,7 @@ describe('Suite', 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());
|
||||
|
||||
@@ -120,7 +171,7 @@ describe('Suite', function() {
|
||||
});
|
||||
|
||||
it('calls timer to compute duration', function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
env: env,
|
||||
id: 456,
|
||||
description: 'I am a suite',
|
||||
@@ -142,4 +193,126 @@ describe('Suite', function() {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('attr.autoCleanClosures', function() {
|
||||
function arrangeSuite(attrs) {
|
||||
const suite = new jasmineUnderTest.Suite(attrs);
|
||||
suite.beforeAll(function() {});
|
||||
suite.beforeEach(function() {});
|
||||
suite.afterEach(function() {});
|
||||
suite.afterAll(function() {});
|
||||
return suite;
|
||||
}
|
||||
|
||||
it('should clean closures when "attr.autoCleanClosures" is missing', function() {
|
||||
const suite = arrangeSuite({});
|
||||
suite.cleanupBeforeAfter();
|
||||
expect(suite.beforeAllFns[0].fn).toBe(null);
|
||||
expect(suite.beforeFns[0].fn).toBe(null);
|
||||
expect(suite.afterFns[0].fn).toBe(null);
|
||||
expect(suite.afterAllFns[0].fn).toBe(null);
|
||||
});
|
||||
|
||||
it('should clean closures when "attr.autoCleanClosures" is true', function() {
|
||||
const suite = arrangeSuite({ autoCleanClosures: true });
|
||||
suite.cleanupBeforeAfter();
|
||||
expect(suite.beforeAllFns[0].fn).toBe(null);
|
||||
expect(suite.beforeFns[0].fn).toBe(null);
|
||||
expect(suite.afterFns[0].fn).toBe(null);
|
||||
expect(suite.afterAllFns[0].fn).toBe(null);
|
||||
});
|
||||
|
||||
it('should NOT clean closures when "attr.autoCleanClosures" is false', function() {
|
||||
const suite = arrangeSuite({ autoCleanClosures: false });
|
||||
suite.cleanupBeforeAfter();
|
||||
expect(suite.beforeAllFns[0].fn).not.toBe(null);
|
||||
expect(suite.beforeFns[0].fn).not.toBe(null);
|
||||
expect(suite.afterFns[0].fn).not.toBe(null);
|
||||
expect(suite.afterAllFns[0].fn).not.toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#reset', function() {
|
||||
it('should reset the "pending" status', function() {
|
||||
const suite = new jasmineUnderTest.Suite({});
|
||||
suite.pend();
|
||||
suite.reset();
|
||||
expect(suite.getResult().status).toBe('passed');
|
||||
});
|
||||
|
||||
it('should not reset the "pending" status when the suite was excluded', function() {
|
||||
const suite = new jasmineUnderTest.Suite({});
|
||||
suite.exclude();
|
||||
suite.reset();
|
||||
expect(suite.getResult().status).toBe('pending');
|
||||
});
|
||||
|
||||
it('should also reset the children', function() {
|
||||
const suite = new jasmineUnderTest.Suite({});
|
||||
const child1 = jasmine.createSpyObj(['reset']);
|
||||
const child2 = jasmine.createSpyObj(['reset']);
|
||||
suite.addChild(child1);
|
||||
suite.addChild(child2);
|
||||
|
||||
suite.reset();
|
||||
|
||||
expect(child1.reset).toHaveBeenCalled();
|
||||
expect(child2.reset).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset the failedExpectations', function() {
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
expectationResultFactory: function(error) {
|
||||
return error;
|
||||
}
|
||||
});
|
||||
suite.onException(new Error());
|
||||
|
||||
suite.reset();
|
||||
|
||||
const result = suite.getResult();
|
||||
expect(result.status).toBe('passed');
|
||||
expect(result.failedExpectations).toHaveSize(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#onMultipleDone', function() {
|
||||
it('reports a special error when it is the top suite', function() {
|
||||
const onLateError = jasmine.createSpy('onLateError');
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
onLateError,
|
||||
parentSuite: null
|
||||
});
|
||||
|
||||
suite.onMultipleDone();
|
||||
|
||||
expect(onLateError).toHaveBeenCalledTimes(1);
|
||||
expect(onLateError.calls.argsFor(0)[0]).toBeInstanceOf(Error);
|
||||
expect(onLateError.calls.argsFor(0)[0].message).toEqual(
|
||||
'A top-level beforeAll or afterAll function called its ' +
|
||||
"'done' callback more than once."
|
||||
);
|
||||
});
|
||||
|
||||
it('reports an error including the suite name when it is a normal suite', function() {
|
||||
const onLateError = jasmine.createSpy('onLateError');
|
||||
const suite = new jasmineUnderTest.Suite({
|
||||
onLateError,
|
||||
description: 'the suite',
|
||||
parentSuite: {
|
||||
description: 'the parent suite',
|
||||
parentSuite: {}
|
||||
}
|
||||
});
|
||||
|
||||
suite.onMultipleDone();
|
||||
|
||||
expect(onLateError).toHaveBeenCalledTimes(1);
|
||||
expect(onLateError.calls.argsFor(0)[0]).toBeInstanceOf(Error);
|
||||
expect(onLateError.calls.argsFor(0)[0].message).toEqual(
|
||||
"An asynchronous beforeAll or afterAll function called its 'done' " +
|
||||
'callback more than once.\n(in suite: the parent suite the suite)'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
describe('Timer', 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 });
|
||||
|
||||
fakeNow.and.returnValue(100);
|
||||
@@ -12,17 +12,19 @@ describe('Timer', function() {
|
||||
});
|
||||
|
||||
describe('when date is stubbed, perhaps by other testing helpers', function() {
|
||||
var origDate = Date;
|
||||
const origDate = Date;
|
||||
beforeEach(function() {
|
||||
// eslint-disable-next-line no-implicit-globals
|
||||
Date = jasmine.createSpy('date spy');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
// eslint-disable-next-line no-implicit-globals
|
||||
Date = origDate;
|
||||
});
|
||||
|
||||
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.elapsed()).toEqual(jasmine.any(Number));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe('TreeProcessor', function() {
|
||||
var nodeNumber = 0,
|
||||
let nodeNumber = 0,
|
||||
leafNumber = 0;
|
||||
|
||||
function Node(attrs) {
|
||||
@@ -27,7 +27,7 @@ describe('TreeProcessor', function() {
|
||||
}
|
||||
|
||||
it('processes a single leaf', function() {
|
||||
var leaf = new Leaf(),
|
||||
const leaf = new Leaf(),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: leaf,
|
||||
runnableIds: [leaf.id]
|
||||
@@ -44,7 +44,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('processes a single pending leaf', function() {
|
||||
var leaf = new Leaf({ markedPending: true }),
|
||||
const leaf = new Leaf({ markedPending: true }),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: leaf,
|
||||
runnableIds: [leaf.id]
|
||||
@@ -61,7 +61,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('processes a single non-specified leaf', function() {
|
||||
var leaf = new Leaf(),
|
||||
const leaf = new Leaf(),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: leaf,
|
||||
runnableIds: []
|
||||
@@ -78,11 +78,11 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('processes a single excluded leaf', function() {
|
||||
var leaf = new Leaf(),
|
||||
const leaf = new Leaf(),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: leaf,
|
||||
runnableIds: [leaf.id],
|
||||
excludeNode: function(node) {
|
||||
excludeNode: function() {
|
||||
return true;
|
||||
}
|
||||
}),
|
||||
@@ -98,7 +98,7 @@ describe('TreeProcessor', 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] }),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: parent,
|
||||
@@ -122,7 +122,7 @@ describe('TreeProcessor', 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] }),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: parent,
|
||||
@@ -146,7 +146,7 @@ describe('TreeProcessor', 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 }),
|
||||
parent = new Node({ children: [pendingLeaf, executableLeaf] }),
|
||||
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() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
leaf3 = new Leaf(),
|
||||
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() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
leaf3 = new Leaf(),
|
||||
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() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
leaf3 = new Leaf(),
|
||||
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() {
|
||||
var noReentry = new Node({ noReenter: true }),
|
||||
const noReentry = new Node({ noReenter: true }),
|
||||
root = new Node({ children: [noReentry] }),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: root,
|
||||
@@ -275,7 +275,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs a single leaf', function() {
|
||||
var leaf = new Leaf(),
|
||||
const leaf = new Leaf(),
|
||||
node = new Node({ children: [leaf], userContext: { root: 'context' } }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
@@ -291,7 +291,8 @@ describe('TreeProcessor', function() {
|
||||
onComplete: treeComplete,
|
||||
onException: jasmine.any(Function),
|
||||
userContext: { root: 'context' },
|
||||
queueableFns: [{ fn: jasmine.any(Function) }]
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
onMultipleDone: null
|
||||
});
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
||||
@@ -300,7 +301,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs a node with no children', function() {
|
||||
var node = new Node({ userContext: { node: 'context' } }),
|
||||
const node = new Node({ userContext: { node: 'context' } }),
|
||||
root = new Node({ children: [node], userContext: { root: 'context' } }),
|
||||
nodeStart = jasmine.createSpy('nodeStart'),
|
||||
nodeComplete = jasmine.createSpy('nodeComplete'),
|
||||
@@ -321,16 +322,19 @@ describe('TreeProcessor', function() {
|
||||
onComplete: treeComplete,
|
||||
onException: jasmine.any(Function),
|
||||
userContext: { root: 'context' },
|
||||
queueableFns: [{ fn: jasmine.any(Function) }]
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
onMultipleDone: null
|
||||
});
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn(nodeDone);
|
||||
|
||||
expect(queueRunner).toHaveBeenCalledWith({
|
||||
onComplete: jasmine.any(Function),
|
||||
onMultipleDone: null,
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
userContext: { node: 'context' },
|
||||
onException: jasmine.any(Function)
|
||||
onException: jasmine.any(Function),
|
||||
onMultipleDone: null
|
||||
});
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
||||
@@ -347,7 +351,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs a node with children', function() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
node = new Node({ children: [leaf1, leaf2] }),
|
||||
root = new Node({ children: [node] }),
|
||||
@@ -361,7 +365,7 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
@@ -375,7 +379,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('cascades errors up the tree', function() {
|
||||
var leaf = new Leaf(),
|
||||
const leaf = new Leaf(),
|
||||
node = new Node({ children: [leaf] }),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -390,7 +394,7 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
@@ -406,7 +410,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs an excluded node with leaf', function() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
node = new Node({ children: [leaf1] }),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -423,7 +427,7 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
@@ -446,7 +450,7 @@ describe('TreeProcessor', 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] }),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -464,7 +468,7 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
@@ -475,10 +479,13 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs beforeAlls for a node with children', function() {
|
||||
var leaf = new Leaf(),
|
||||
const leaf = new Leaf(),
|
||||
node = new Node({
|
||||
children: [leaf],
|
||||
beforeAllFns: ['beforeAll1', 'beforeAll2']
|
||||
beforeAllFns: [
|
||||
{ fn: 'beforeAll1', timeout: 1 },
|
||||
{ fn: 'beforeAll2', timeout: 2 }
|
||||
]
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -491,24 +498,25 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
|
||||
expect(queueableFns).toEqual([
|
||||
{ fn: jasmine.any(Function) },
|
||||
'beforeAll1',
|
||||
'beforeAll2',
|
||||
{ fn: 'beforeAll1', timeout: 1 },
|
||||
{ fn: 'beforeAll2', timeout: 2 },
|
||||
{ fn: jasmine.any(Function) }
|
||||
]);
|
||||
});
|
||||
|
||||
it('runs afterAlls for a node with children', function() {
|
||||
var leaf = new Leaf(),
|
||||
const leaf = new Leaf(),
|
||||
afterAllFns = [{ fn: 'afterAll1' }, { fn: 'afterAll2' }],
|
||||
node = new Node({
|
||||
children: [leaf],
|
||||
afterAllFns: ['afterAll1', 'afterAll2']
|
||||
afterAllFns
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -521,7 +529,7 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
@@ -529,15 +537,15 @@ describe('TreeProcessor', function() {
|
||||
expect(queueableFns).toEqual([
|
||||
{ fn: jasmine.any(Function) },
|
||||
{ fn: jasmine.any(Function) },
|
||||
'afterAll1',
|
||||
'afterAll2'
|
||||
afterAllFns[0],
|
||||
afterAllFns[1]
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not run beforeAlls or afterAlls for a node with no children', function() {
|
||||
var node = new Node({
|
||||
beforeAllFns: ['before'],
|
||||
afterAllFns: ['after']
|
||||
const node = new Node({
|
||||
beforeAllFns: [{ fn: 'before' }],
|
||||
afterAllFns: [{ fn: 'after' }]
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -550,7 +558,7 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
@@ -559,11 +567,11 @@ describe('TreeProcessor', 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({
|
||||
children: [leaf],
|
||||
beforeAllFns: ['before'],
|
||||
afterAllFns: ['after'],
|
||||
beforeAllFns: [{ fn: 'before' }],
|
||||
afterAllFns: [{ fn: 'after' }],
|
||||
markedPending: false
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
@@ -577,7 +585,7 @@ describe('TreeProcessor', function() {
|
||||
nodeDone = jasmine.createSpy('nodeDone');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
let queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
@@ -589,7 +597,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs leaves in the order specified', function() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
root = new Node({ children: [leaf1, leaf2] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -601,7 +609,7 @@ describe('TreeProcessor', function() {
|
||||
treeComplete = jasmine.createSpy('treeComplete');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn();
|
||||
|
||||
expect(leaf1.execute).not.toHaveBeenCalled();
|
||||
@@ -613,7 +621,7 @@ describe('TreeProcessor', 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(),
|
||||
root = new Node({ children: [nonSpecified, specified] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -625,7 +633,7 @@ describe('TreeProcessor', function() {
|
||||
treeComplete = jasmine.createSpy('treeComplete');
|
||||
|
||||
processor.execute(treeComplete);
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn();
|
||||
|
||||
expect(nonSpecified.execute).not.toHaveBeenCalled();
|
||||
@@ -637,7 +645,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs nodes and leaves with a specified order', function() {
|
||||
var specifiedLeaf = new Leaf(),
|
||||
const specifiedLeaf = new Leaf(),
|
||||
childLeaf = new Leaf(),
|
||||
specifiedNode = new Node({ children: [childLeaf] }),
|
||||
root = new Node({ children: [specifiedLeaf, specifiedNode] }),
|
||||
@@ -649,11 +657,12 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
processor.execute();
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn();
|
||||
|
||||
expect(specifiedLeaf.execute).not.toHaveBeenCalled();
|
||||
var nodeQueueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const nodeQueueableFns = queueRunner.calls.mostRecent().args[0]
|
||||
.queueableFns;
|
||||
nodeQueueableFns[1].fn();
|
||||
|
||||
expect(childLeaf.execute).toHaveBeenCalled();
|
||||
@@ -664,7 +673,7 @@ describe('TreeProcessor', 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(),
|
||||
leaf3 = new Leaf(),
|
||||
leaf4 = new Leaf(),
|
||||
@@ -679,7 +688,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
processor.execute();
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(queueableFns.length).toBe(5);
|
||||
|
||||
queueableFns[0].fn();
|
||||
@@ -707,7 +716,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs a parent of a node with segments correctly', function() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
leaf3 = new Leaf(),
|
||||
leaf4 = new Leaf(),
|
||||
@@ -723,7 +732,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
processor.execute();
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(queueableFns.length).toBe(5);
|
||||
|
||||
queueableFns[0].fn();
|
||||
@@ -764,7 +773,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs nodes in the order they were declared', function() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
leaf3 = new Leaf(),
|
||||
parent = new Node({ children: [leaf2, leaf3] }),
|
||||
@@ -777,7 +786,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
processor.execute();
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(queueableFns.length).toBe(2);
|
||||
|
||||
queueableFns[0].fn();
|
||||
@@ -785,7 +794,7 @@ describe('TreeProcessor', function() {
|
||||
|
||||
queueableFns[1].fn();
|
||||
|
||||
var childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(childFns.length).toBe(3);
|
||||
childFns[1].fn();
|
||||
expect(leaf2.execute).toHaveBeenCalled();
|
||||
@@ -795,7 +804,7 @@ describe('TreeProcessor', 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(),
|
||||
leaf3 = new Leaf(),
|
||||
leaf4 = new Leaf(),
|
||||
@@ -829,7 +838,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
processor.execute();
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(queueableFns.length).toBe(11);
|
||||
|
||||
queueableFns[0].fn();
|
||||
@@ -867,7 +876,7 @@ describe('TreeProcessor', function() {
|
||||
});
|
||||
|
||||
it('runs nodes in a custom order when orderChildren is overridden', function() {
|
||||
var leaf1 = new Leaf(),
|
||||
const leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
leaf3 = new Leaf(),
|
||||
leaf4 = new Leaf(),
|
||||
@@ -899,13 +908,13 @@ describe('TreeProcessor', function() {
|
||||
runnableIds: [root.id],
|
||||
queueRunnerFactory: queueRunner,
|
||||
orderChildren: function(node) {
|
||||
var children = node.children.slice();
|
||||
const children = node.children.slice();
|
||||
return children.reverse();
|
||||
}
|
||||
});
|
||||
|
||||
processor.execute();
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
const queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(queueableFns.length).toBe(11);
|
||||
|
||||
queueableFns[0].fn();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
describe('UserContext', function() {
|
||||
it('Behaves just like an plain object', function() {
|
||||
var context = new jasmineUnderTest.UserContext(),
|
||||
const context = new jasmineUnderTest.UserContext(),
|
||||
properties = [];
|
||||
|
||||
for (var prop in context) {
|
||||
for (const prop in context) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
properties.push(prop);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
describe('jasmineUnderTest.util', function() {
|
||||
describe('util', function() {
|
||||
describe('isArray_', function() {
|
||||
it('should return true if the argument is an array', function() {
|
||||
expect(jasmineUnderTest.isArray_([])).toBe(true);
|
||||
@@ -32,15 +32,14 @@ describe('jasmineUnderTest.util', function() {
|
||||
});
|
||||
|
||||
describe('promise utils', function() {
|
||||
var mockNativePromise, mockPromiseLikeObject;
|
||||
let mockNativePromise, mockPromiseLikeObject;
|
||||
|
||||
var mockPromiseLike = function() {
|
||||
const mockPromiseLike = function() {
|
||||
this.then = function() {};
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
mockNativePromise = new Promise(function(res, rej) {}); // eslint-disable-line compat/compat
|
||||
mockNativePromise = new Promise(function() {});
|
||||
mockPromiseLikeObject = new mockPromiseLike();
|
||||
});
|
||||
|
||||
@@ -131,18 +130,44 @@ describe('jasmineUnderTest.util', function() {
|
||||
|
||||
describe('isUndefined', function() {
|
||||
it('reports if a variable is defined', function() {
|
||||
var a;
|
||||
let a;
|
||||
expect(jasmineUnderTest.util.isUndefined(a)).toBe(true);
|
||||
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(true);
|
||||
|
||||
var undefined = 'diz be undefined yo';
|
||||
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(false);
|
||||
const defined = 'diz be undefined yo';
|
||||
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() {
|
||||
it('get property descriptor from object', function() {
|
||||
var obj = { prop: 1 },
|
||||
const obj = { prop: 1 },
|
||||
actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
|
||||
expected = Object.getOwnPropertyDescriptor(obj, 'prop');
|
||||
|
||||
@@ -150,7 +175,7 @@ describe('jasmineUnderTest.util', function() {
|
||||
});
|
||||
|
||||
it('get property descriptor from object property', function() {
|
||||
var proto = { prop: 1 },
|
||||
const proto = { prop: 1 },
|
||||
actual = jasmineUnderTest.util.getPropertyDescriptor(proto, 'prop'),
|
||||
expected = Object.getOwnPropertyDescriptor(proto, 'prop');
|
||||
|
||||
@@ -158,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() {
|
||||
it('returns the file containing jasmine.util', function() {
|
||||
// Chrome sometimes reports foo.js as foo.js/, so tolerate
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
describe('asymmetricEqualityTesterArgCompatShim', function() {
|
||||
it('provides all the properties of the MatchersUtil', function() {
|
||||
var matchersUtil = {
|
||||
foo: function() {},
|
||||
bar: function() {}
|
||||
},
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||
matchersUtil,
|
||||
[]
|
||||
);
|
||||
|
||||
expect(shim.foo).toBe(matchersUtil.foo);
|
||||
expect(shim.bar).toBe(matchersUtil.bar);
|
||||
});
|
||||
|
||||
it('provides all the properties of the customEqualityTesters', function() {
|
||||
var customEqualityTesters = [function() {}, function() {}],
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
|
||||
{},
|
||||
customEqualityTesters
|
||||
);
|
||||
|
||||
expect(shim.length).toBe(2);
|
||||
expect(shim[0]).toBe(customEqualityTesters[0]);
|
||||
expect(shim[1]).toBe(customEqualityTesters[1]);
|
||||
});
|
||||
|
||||
it('provides all the properties of Array.prototype', function() {
|
||||
var shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []);
|
||||
|
||||
expect(shim.filter).toBe(Array.prototype.filter);
|
||||
expect(shim.forEach).toBe(Array.prototype.forEach);
|
||||
expect(shim.map).toBe(Array.prototype.map);
|
||||
});
|
||||
|
||||
it('provides properties of Array.prototype', function() {
|
||||
var keys = [
|
||||
'concat',
|
||||
'constructor',
|
||||
'every',
|
||||
'filter',
|
||||
'forEach',
|
||||
'indexOf',
|
||||
'join',
|
||||
'lastIndexOf',
|
||||
'length',
|
||||
'map',
|
||||
'pop',
|
||||
'push',
|
||||
'reduce',
|
||||
'reduceRight',
|
||||
'reverse',
|
||||
'shift',
|
||||
'slice',
|
||||
'some',
|
||||
'sort',
|
||||
'splice',
|
||||
'toLocaleString',
|
||||
'toString',
|
||||
'unshift'
|
||||
],
|
||||
optionalKeys = [
|
||||
'copyWithin',
|
||||
'entries',
|
||||
'fill',
|
||||
'find',
|
||||
'findIndex',
|
||||
'flat',
|
||||
'flatMap',
|
||||
'includes',
|
||||
'keys',
|
||||
'toSource',
|
||||
'values'
|
||||
],
|
||||
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim({}, []),
|
||||
i,
|
||||
k;
|
||||
|
||||
// Properties that are present on all supported runtimes
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
k = keys[i];
|
||||
expect(shim[k])
|
||||
.withContext(k)
|
||||
.not.toBeUndefined();
|
||||
expect(shim[k])
|
||||
.withContext(k)
|
||||
.toBe(Array.prototype[k]);
|
||||
}
|
||||
|
||||
// Properties that are present on only some supported runtimes
|
||||
for (i = 0; i < optionalKeys.length; i++) {
|
||||
k = optionalKeys[i];
|
||||
|
||||
if (shim[k] !== undefined) {
|
||||
expect(shim[k])
|
||||
.withContext(k)
|
||||
.toBe(Array.prototype[k]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,88 +1,80 @@
|
||||
describe("Any", function() {
|
||||
it("matches a string", function() {
|
||||
var any = new jasmineUnderTest.Any(String);
|
||||
describe('Any', function() {
|
||||
it('matches a string', function() {
|
||||
const any = new jasmineUnderTest.Any(String);
|
||||
|
||||
expect(any.asymmetricMatch("foo")).toBe(true);
|
||||
expect(any.asymmetricMatch('foo')).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a number", function() {
|
||||
var any = new jasmineUnderTest.Any(Number);
|
||||
it('matches a number', function() {
|
||||
const any = new jasmineUnderTest.Any(Number);
|
||||
|
||||
expect(any.asymmetricMatch(1)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a function", function() {
|
||||
var any = new jasmineUnderTest.Any(Function);
|
||||
it('matches a function', function() {
|
||||
const any = new jasmineUnderTest.Any(Function);
|
||||
|
||||
expect(any.asymmetricMatch(function(){})).toBe(true);
|
||||
expect(any.asymmetricMatch(function() {})).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an Object", function() {
|
||||
var any = new jasmineUnderTest.Any(Object);
|
||||
it('matches an Object', function() {
|
||||
const any = new jasmineUnderTest.Any(Object);
|
||||
|
||||
expect(any.asymmetricMatch({})).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Boolean", function() {
|
||||
var any = new jasmineUnderTest.Any(Boolean);
|
||||
it('matches a Boolean', function() {
|
||||
const any = new jasmineUnderTest.Any(Boolean);
|
||||
|
||||
expect(any.asymmetricMatch(true)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Map", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
it('matches a Map', function() {
|
||||
const any = new jasmineUnderTest.Any(Map);
|
||||
|
||||
var any = new jasmineUnderTest.Any(Map);
|
||||
|
||||
expect(any.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(any.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Set", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
it('matches a Set', function() {
|
||||
const any = new jasmineUnderTest.Any(Set);
|
||||
|
||||
var any = new jasmineUnderTest.Any(Set);
|
||||
|
||||
expect(any.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(any.asymmetricMatch(new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a TypedArray", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
it('matches a TypedArray', function() {
|
||||
const any = new jasmineUnderTest.Any(Uint32Array);
|
||||
|
||||
var any = new jasmineUnderTest.Any(Uint32Array); // eslint-disable-line compat/compat
|
||||
|
||||
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Symbol", function() {
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
it('matches a Symbol', function() {
|
||||
const any = new jasmineUnderTest.Any(Symbol);
|
||||
|
||||
var any = new jasmineUnderTest.Any(Symbol); // eslint-disable-line compat/compat
|
||||
|
||||
expect(any.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(any.asymmetricMatch(Symbol())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches another constructed object", function() {
|
||||
var Thing = function() {},
|
||||
it('matches another constructed object', function() {
|
||||
const Thing = function() {},
|
||||
any = new jasmineUnderTest.Any(Thing);
|
||||
|
||||
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
||||
});
|
||||
|
||||
it("does not treat null as an Object", function() {
|
||||
var any = new jasmineUnderTest.Any(Object);
|
||||
it('does not treat null as an Object', function() {
|
||||
const any = new jasmineUnderTest.Any(Object);
|
||||
|
||||
expect(any.asymmetricMatch(null)).toBe(false);
|
||||
});
|
||||
|
||||
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)>');
|
||||
});
|
||||
|
||||
describe("when called without an argument", function() {
|
||||
it("tells the user to pass a constructor or use jasmine.anything()", function() {
|
||||
describe('when called without an argument', function() {
|
||||
it('tells the user to pass a constructor or use jasmine.anything()', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.Any();
|
||||
}).toThrowError(TypeError, /constructor.*anything/);
|
||||
|
||||
@@ -1,76 +1,68 @@
|
||||
describe("Anything", function() {
|
||||
it("matches a string", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
describe('Anything', function() {
|
||||
it('matches a string', function() {
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch('foo')).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a number", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
it('matches a number', function() {
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(42)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an object", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
it('matches an object', function() {
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
||||
});
|
||||
|
||||
it("matches an array", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
it('matches an array', function() {
|
||||
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() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
it('matches a Map', function() {
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(anything.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Set", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
it('matches a Set', function() {
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(anything.asymmetricMatch(new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a TypedArray", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
it('matches a TypedArray', function() {
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Symbol", function() {
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
it('matches a Symbol', function() {
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(anything.asymmetricMatch(Symbol())).toBe(true);
|
||||
});
|
||||
|
||||
it("doesn't match undefined", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch()).toBe(false);
|
||||
expect(anything.asymmetricMatch(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("doesn't match null", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
const anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(null)).toBe(false);
|
||||
});
|
||||
|
||||
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,48 +1,48 @@
|
||||
describe("ArrayContaining", function() {
|
||||
it("matches any actual to an empty array", function() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining([]);
|
||||
describe('ArrayContaining', function() {
|
||||
it('matches any actual to an empty array', function() {
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining("foo");
|
||||
it('does not work when not passed an array', function() {
|
||||
const containing = new jasmineUnderTest.ArrayContaining('foo');
|
||||
|
||||
expect(function() {
|
||||
containing.asymmetricMatch([]);
|
||||
}).toThrowError(/not 'foo'/);
|
||||
});
|
||||
|
||||
it("matches when the item is in the actual", function() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('matches when the item is in the actual', function() {
|
||||
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('matches when additional items are in the actual', function() {
|
||||
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('does not match when the item is not in the actual', function() {
|
||||
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||
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() {
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('does not match when the actual is not an array', function() {
|
||||
const containing = new jasmineUnderTest.ArrayContaining(['foo']);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch("foo", matchersUtil)).toBe(false);
|
||||
expect(containing.asymmetricMatch('foo', matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToStrings itself", function() {
|
||||
var sample = [],
|
||||
it('jasmineToStrings itself', function() {
|
||||
const sample = [],
|
||||
matcher = new jasmineUnderTest.ArrayContaining(sample),
|
||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||
|
||||
@@ -52,17 +52,23 @@ describe("ArrayContaining", function() {
|
||||
expect(pp).toHaveBeenCalledWith(sample);
|
||||
});
|
||||
|
||||
it("uses custom equality testers", function() {
|
||||
var tester = function(a, b) {
|
||||
it('uses custom equality testers', function() {
|
||||
const tester = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
if (
|
||||
typeof a == 'string' &&
|
||||
typeof b == 'string' &&
|
||||
a.slice(0, 3) == 'foo' &&
|
||||
b.slice(0, 3) == 'foo'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
const containing = new jasmineUnderTest.ArrayContaining(['fooVal']);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: [tester]
|
||||
});
|
||||
|
||||
expect(containing.asymmetricMatch(["fooBar"], matchersUtil)).toBe(true);
|
||||
expect(containing.asymmetricMatch(['fooBar'], matchersUtil)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
describe("ArrayWithExactContents", function() {
|
||||
it("matches an array with the same items in a different order", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
describe('ArrayWithExactContents', function() {
|
||||
it('matches an array with the same items in a different order', function() {
|
||||
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(matcher.asymmetricMatch([2, 'a', /a/], matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it("does not work when not passed an array", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents("foo");
|
||||
it('does not work when not passed an array', function() {
|
||||
const matcher = new jasmineUnderTest.ArrayWithExactContents('foo');
|
||||
|
||||
expect(function() {
|
||||
matcher.asymmetricMatch([]);
|
||||
}).toThrowError(/not 'foo'/);
|
||||
});
|
||||
|
||||
it("does not match when an item is missing", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('does not match when an item is missing', function() {
|
||||
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(false);
|
||||
expect(matcher.asymmetricMatch(['a', 2, undefined], matchersUtil)).toBe(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("does not match when there is an extra item", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('does not match when there is an extra item', function() {
|
||||
const matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(matcher.asymmetricMatch(['a', 2], matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToStrings itself", function() {
|
||||
var sample = [],
|
||||
it('jasmineToStrings itself', function() {
|
||||
const sample = [],
|
||||
matcher = new jasmineUnderTest.ArrayWithExactContents(sample),
|
||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||
|
||||
@@ -40,17 +42,23 @@ describe("ArrayWithExactContents", function() {
|
||||
expect(pp).toHaveBeenCalledWith(sample);
|
||||
});
|
||||
|
||||
it("uses custom equality testers", function() {
|
||||
var tester = function(a, b) {
|
||||
it('uses custom equality testers', function() {
|
||||
const tester = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
if (
|
||||
typeof a == 'string' &&
|
||||
typeof b == 'string' &&
|
||||
a.slice(0, 3) == 'foo' &&
|
||||
b.slice(0, 3) == 'foo'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(["fooVal"]);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
const matcher = new jasmineUnderTest.ArrayWithExactContents(['fooVal']);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: [tester]
|
||||
});
|
||||
|
||||
expect(matcher.asymmetricMatch(["fooBar"], matchersUtil)).toBe(true);
|
||||
expect(matcher.asymmetricMatch(['fooBar'], matchersUtil)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,51 +1,48 @@
|
||||
describe("Empty", function () {
|
||||
it("matches an empty object", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
describe('Empty', function() {
|
||||
it('matches an empty object', function() {
|
||||
const empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch({})).toBe(true);
|
||||
expect(empty.asymmetricMatch({undefined: false})).toBe(false);
|
||||
expect(empty.asymmetricMatch({ undefined: false })).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty array", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
it('matches an empty array', function() {
|
||||
const empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch([])).toBe(true);
|
||||
expect(empty.asymmetricMatch([1, 12, 3])).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty string", function () {
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
it('matches an empty string', function() {
|
||||
const empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch("")).toBe(true);
|
||||
expect(empty.asymmetricMatch('')).toBe(true);
|
||||
expect(empty.asymmetricMatch('')).toBe(true);
|
||||
expect(empty.asymmetricMatch('12312')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty map", function () {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||
it('matches an empty map', function() {
|
||||
const empty = new jasmineUnderTest.Empty();
|
||||
const fullMap = new Map();
|
||||
fullMap.set('thing', 2);
|
||||
|
||||
expect(empty.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(empty.asymmetricMatch(new Map())).toBe(true);
|
||||
expect(empty.asymmetricMatch(fullMap)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty set", function () {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
var fullSet = new Set(); // eslint-disable-line compat/compat
|
||||
it('matches an empty set', function() {
|
||||
const empty = new jasmineUnderTest.Empty();
|
||||
const fullSet = new Set();
|
||||
fullSet.add(3);
|
||||
|
||||
expect(empty.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(empty.asymmetricMatch(new Set())).toBe(true);
|
||||
expect(empty.asymmetricMatch(fullSet)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches an empty typed array", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
var empty = new jasmineUnderTest.Empty();
|
||||
it('matches an empty typed array', function() {
|
||||
const empty = new jasmineUnderTest.Empty();
|
||||
|
||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(empty.asymmetricMatch(new Int16Array([1,2]))).toBe(false); // eslint-disable-line compat/compat
|
||||
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
|
||||
expect(empty.asymmetricMatch(new Int16Array([1, 2]))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
describe("Falsy", function() {
|
||||
it("is true for an empty string", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy();
|
||||
describe('Falsy', function() {
|
||||
it('is true for an empty string', function() {
|
||||
const falsy = new jasmineUnderTest.Falsy();
|
||||
|
||||
expect(falsy.asymmetricMatch("")).toBe(true);
|
||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||
expect(falsy.asymmetricMatch('asdasdad')).toBe(false);
|
||||
});
|
||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||
expect(falsy.asymmetricMatch('')).toBe(true);
|
||||
expect(falsy.asymmetricMatch('asdasdad')).toBe(false);
|
||||
});
|
||||
|
||||
it("is false for a number that is 0", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Number);
|
||||
it('is false for a number that is 0', function() {
|
||||
const falsy = new jasmineUnderTest.Falsy(Number);
|
||||
|
||||
expect(falsy.asymmetricMatch(1)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(0)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(-23)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(-3.1)).toBe(false);
|
||||
});
|
||||
expect(falsy.asymmetricMatch(1)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(0)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(-23)).toBe(false);
|
||||
expect(falsy.asymmetricMatch(-3.1)).toBe(false);
|
||||
});
|
||||
|
||||
it("is true for a null or undefined", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Function);
|
||||
it('is true for a null or undefined', function() {
|
||||
const falsy = new jasmineUnderTest.Falsy(Function);
|
||||
|
||||
expect(falsy.asymmetricMatch(null)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(undefined )).toBe(true);
|
||||
});
|
||||
expect(falsy.asymmetricMatch(null)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for NaN", function() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Object);
|
||||
it('is true for NaN', function() {
|
||||
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() {
|
||||
var falsy = new jasmineUnderTest.Falsy(Boolean);
|
||||
it('is true for a false Boolean', function() {
|
||||
const falsy = new jasmineUnderTest.Falsy(Boolean);
|
||||
|
||||
expect(falsy.asymmetricMatch(false)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(true)).toBe(false);
|
||||
});
|
||||
expect(falsy.asymmetricMatch(false)).toBe(true);
|
||||
expect(falsy.asymmetricMatch(true)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,160 +1,110 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('MapContaining', function() {
|
||||
function MapI(iterable) { // for IE11
|
||||
var map = new Map();
|
||||
iterable.forEach(function(kv) {
|
||||
map.set(kv[0], kv[1]);
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
});
|
||||
|
||||
|
||||
it('matches any actual map to an empty map', function() {
|
||||
var actualMap = new MapI([['foo', 'bar']]);
|
||||
var containing = new jasmineUnderTest.MapContaining(new Map());
|
||||
const actualMap = new Map([['foo', 'bar']]);
|
||||
const containing = new jasmineUnderTest.MapContaining(new Map());
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap)).toBe(true);
|
||||
});
|
||||
|
||||
it('matches when all the key/value pairs in sample have matches in actual', function() {
|
||||
var actualMap = new MapI([
|
||||
const actualMap = new Map([
|
||||
['foo', [1, 2, 3]],
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['other', 'any'],
|
||||
[{ foo: 'bar' }, 'baz'],
|
||||
['other', 'any']
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['foo', [1, 2, 3]],
|
||||
const containingMap = new Map([
|
||||
[{ foo: 'bar' }, 'baz'],
|
||||
['foo', [1, 2, 3]]
|
||||
]);
|
||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match when a key is not in actual', function() {
|
||||
var actualMap = new MapI([
|
||||
const actualMap = new Map([
|
||||
['foo', [1, 2, 3]],
|
||||
[{'foo': 'not a bar'}, 'baz'],
|
||||
[{ foo: 'not a bar' }, 'baz']
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['foo', [1, 2, 3]],
|
||||
const containingMap = new Map([
|
||||
[{ foo: 'bar' }, 'baz'],
|
||||
['foo', [1, 2, 3]]
|
||||
]);
|
||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it('does not match when a value is not in actual', function() {
|
||||
var actualMap = new MapI([
|
||||
['foo', [1, 2, 3]],
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
]);
|
||||
const actualMap = new Map([['foo', [1, 2, 3]], [{ foo: 'bar' }, 'baz']]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[{'foo': 'bar'}, 'baz'],
|
||||
['foo', [1, 2]],
|
||||
]);
|
||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containingMap = new Map([[{ foo: 'bar' }, 'baz'], ['foo', [1, 2]]]);
|
||||
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it('matches when all the key/value pairs in sample have asymmetric matches in actual', function() {
|
||||
var actualMap = new MapI([
|
||||
const actualMap = new Map([
|
||||
['foo1', 'not a bar'],
|
||||
['foo2', 'bar'],
|
||||
['baz', [1, 2, 3, 4]],
|
||||
['baz', [1, 2, 3, 4]]
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||
'bar'
|
||||
],
|
||||
[
|
||||
'baz',
|
||||
jasmineUnderTest.arrayContaining([2, 3])
|
||||
],
|
||||
const containingMap = new Map([
|
||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||
]);
|
||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match when a key in sample has no asymmetric matches in actual', function() {
|
||||
var actualMap = new MapI([
|
||||
['a-foo1', 'bar'],
|
||||
['baz', [1, 2, 3, 4]],
|
||||
]);
|
||||
const actualMap = new Map([['a-foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||
'bar'
|
||||
],
|
||||
[
|
||||
'baz',
|
||||
jasmineUnderTest.arrayContaining([2, 3])
|
||||
],
|
||||
const containingMap = new Map([
|
||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||
['baz', jasmineUnderTest.arrayContaining([2, 3])]
|
||||
]);
|
||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
||||
var actualMap = new MapI([
|
||||
['foo1', 'bar'],
|
||||
['baz', [1, 2, 3, 4]],
|
||||
]);
|
||||
const actualMap = new Map([['foo1', 'bar'], ['baz', [1, 2, 3, 4]]]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||
'bar'
|
||||
],
|
||||
[
|
||||
'baz',
|
||||
jasmineUnderTest.arrayContaining([4, 5])
|
||||
],
|
||||
const containingMap = new Map([
|
||||
[jasmineUnderTest.stringMatching(/^foo\d/), 'bar'],
|
||||
['baz', jasmineUnderTest.arrayContaining([4, 5])]
|
||||
]);
|
||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it('matches recursively', function() {
|
||||
var actualMap = new MapI([
|
||||
['foo', new MapI([['foo1', 1], ['foo2', 2]])],
|
||||
[new MapI([[1, 'bar1'], [2, 'bar2']]), 'bar'],
|
||||
['other', 'any'],
|
||||
const actualMap = new Map([
|
||||
['foo', new Map([['foo1', 1], ['foo2', 2]])],
|
||||
[new Map([[1, 'bar1'], [2, 'bar2']]), 'bar'],
|
||||
['other', 'any']
|
||||
]);
|
||||
|
||||
var containingMap = new MapI([
|
||||
[
|
||||
'foo',
|
||||
new jasmineUnderTest.MapContaining(new MapI([['foo1', 1]]))
|
||||
],
|
||||
[
|
||||
new jasmineUnderTest.MapContaining(new MapI([[2, 'bar2']])),
|
||||
'bar'
|
||||
],
|
||||
const containingMap = new Map([
|
||||
['foo', new jasmineUnderTest.MapContaining(new Map([['foo1', 1]]))],
|
||||
[new jasmineUnderTest.MapContaining(new Map([[2, 'bar2']])), 'bar']
|
||||
]);
|
||||
var containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.MapContaining(containingMap);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||
});
|
||||
@@ -162,30 +112,46 @@ describe('MapContaining', function() {
|
||||
it('uses custom equality testers', function() {
|
||||
function tester(a, b) {
|
||||
// treat all negative numbers as equal
|
||||
return (typeof a == 'number' && typeof b == 'number') ? (a < 0 && b < 0) : a === b;
|
||||
return typeof a == 'number' && typeof b == 'number'
|
||||
? a < 0 && b < 0
|
||||
: a === b;
|
||||
}
|
||||
var actualMap = new MapI([['foo', -1]]);
|
||||
var containing = new jasmineUnderTest.MapContaining(new MapI([['foo', -2]]));
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
const actualMap = new Map([['foo', -1]]);
|
||||
const containing = new jasmineUnderTest.MapContaining(
|
||||
new Map([['foo', -2]])
|
||||
);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: [tester]
|
||||
});
|
||||
|
||||
expect(containing.asymmetricMatch(actualMap, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match when actual is not a map', function() {
|
||||
var containingMap = new MapI([['foo', 'bar']]);
|
||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')).toBe(false);
|
||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch(-1)).toBe(false);
|
||||
expect(new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch({'foo': 'bar'})).toBe(false);
|
||||
const containingMap = new Map([['foo', 'bar']]);
|
||||
expect(
|
||||
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch('foo')
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch(-1)
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.MapContaining(containingMap).asymmetricMatch({
|
||||
foo: 'bar'
|
||||
})
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('throws an error when sample is not a map', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.MapContaining({'foo': 'bar'}).asymmetricMatch(new Map());
|
||||
new jasmineUnderTest.MapContaining({ foo: 'bar' }).asymmetricMatch(
|
||||
new Map()
|
||||
);
|
||||
}).toThrowError(/You must provide a map/);
|
||||
});
|
||||
|
||||
it('defines a `jasmineToString` method', function() {
|
||||
var sample = new Map(),
|
||||
const sample = new Map(),
|
||||
containing = new jasmineUnderTest.MapContaining(sample),
|
||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||
|
||||
|
||||
@@ -1,53 +1,50 @@
|
||||
describe("NotEmpty", function () {
|
||||
it("matches a non empty object", function () {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
describe('NotEmpty', function() {
|
||||
it('matches a non empty object', function() {
|
||||
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch({undefined: false})).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch({ undefined: false })).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch({})).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty array", function () {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
it('matches a non empty array', function() {
|
||||
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch([1, 12, 3])).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch([])).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty string", function () {
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
it('matches a non empty string', function() {
|
||||
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch('12312')).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch("")).toBe(false);
|
||||
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||
expect(notEmpty.asymmetricMatch('')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty map", function () {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
var fullMap = new Map(); // eslint-disable-line compat/compat
|
||||
it('matches a non empty map', function() {
|
||||
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
const fullMap = new Map();
|
||||
fullMap.set('one', 1);
|
||||
var emptyMap = new Map(); // eslint-disable-line compat/compat
|
||||
const emptyMap = new Map();
|
||||
|
||||
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty set", function () {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
var filledSet = new Set(); // eslint-disable-line compat/compat
|
||||
it('matches a non empty set', function() {
|
||||
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
const filledSet = new Set();
|
||||
filledSet.add(1);
|
||||
var emptySet = new Set(); // eslint-disable-line compat/compat
|
||||
const emptySet = new Set();
|
||||
|
||||
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a non empty typed array", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
var notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
it('matches a non empty typed array', function() {
|
||||
const notEmpty = new jasmineUnderTest.NotEmpty();
|
||||
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array([1,2,3]))).toBe(true); // eslint-disable-line compat/compat
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false); // eslint-disable-line compat/compat
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array([1, 2, 3]))).toBe(true);
|
||||
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,51 +1,59 @@
|
||||
describe("ObjectContaining", function() {
|
||||
describe('ObjectContaining', function() {
|
||||
it('matches any object actual to an empty object', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({});
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
it("matches any object actual to an empty object", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({foo: 1}, matchersUtil)).toBe(true);
|
||||
expect(containing.asymmetricMatch({ foo: 1 }, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it("does not match when the actual is not an object", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({});
|
||||
it('does not match when the actual is not an object', function() {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not match an empty object actual", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining("foo");
|
||||
it('does not match an empty object actual', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining('foo');
|
||||
|
||||
expect(function() {
|
||||
containing.asymmetricMatch({})
|
||||
}).toThrowError(/not 'foo'/)
|
||||
containing.asymmetricMatch({});
|
||||
}).toThrowError(/not 'foo'/);
|
||||
});
|
||||
|
||||
it("matches when the key/value pair is present in the actual", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('matches when the key/value pair is present in the actual', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"}, matchersUtil)).toBe(true);
|
||||
expect(
|
||||
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not match when the key/value pair is not present in the actual", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('does not match when the key/value pair is not present in the actual', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"}, matchersUtil)).toBe(false);
|
||||
expect(
|
||||
containing.asymmetricMatch(
|
||||
{ bar: 'barVal', quux: 'quuxVal' },
|
||||
matchersUtil
|
||||
)
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("does not match when the key is present but the value is different in the actual", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "other"});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('does not match when the key is present but the value is different in the actual', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'other' });
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"}, matchersUtil)).toBe(false);
|
||||
expect(
|
||||
containing.asymmetricMatch({ foo: 'fooVal', bar: 'barVal' }, matchersUtil)
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToString's itself", function() {
|
||||
var sample = {},
|
||||
const sample = {},
|
||||
matcher = new jasmineUnderTest.ObjectContaining(sample),
|
||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||
|
||||
@@ -53,78 +61,90 @@ describe("ObjectContaining", function() {
|
||||
'<jasmine.objectContaining(sample)>'
|
||||
);
|
||||
expect(pp).toHaveBeenCalledWith(sample);
|
||||
|
||||
});
|
||||
|
||||
it("matches recursively", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({one: new jasmineUnderTest.ObjectContaining({two: {}})});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('matches recursively', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({
|
||||
one: new jasmineUnderTest.ObjectContaining({ two: {} })
|
||||
});
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({one: {two: {}}}, matchersUtil)).toBe(true);
|
||||
expect(containing.asymmetricMatch({ one: { two: {} } }, matchersUtil)).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it("matches when key is present with undefined value", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('matches when key is present with undefined value', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({
|
||||
one: undefined
|
||||
});
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({ one: undefined }, matchersUtil)).toBe(true);
|
||||
expect(containing.asymmetricMatch({ one: undefined }, matchersUtil)).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it("does not match when key with undefined value is not present", function() {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('does not match when key with undefined value is not present', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({
|
||||
one: undefined
|
||||
});
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch({}, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches defined properties", function(){
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('matches defined properties', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
var definedPropertyObject = {};
|
||||
Object.defineProperty(definedPropertyObject, "foo", {
|
||||
get: function() { return "fooVal" }
|
||||
const definedPropertyObject = {};
|
||||
Object.defineProperty(definedPropertyObject, 'foo', {
|
||||
get: function() {
|
||||
return 'fooVal';
|
||||
}
|
||||
});
|
||||
expect(containing.asymmetricMatch(definedPropertyObject, matchersUtil)).toBe(true);
|
||||
expect(
|
||||
containing.asymmetricMatch(definedPropertyObject, matchersUtil)
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("matches prototype properties", function(){
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
it('matches prototype properties', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
var prototypeObject = {foo: "fooVal"};
|
||||
var obj;
|
||||
|
||||
if (Object.create) {
|
||||
obj = Object.create(prototypeObject);
|
||||
} else {
|
||||
function Foo() {}
|
||||
Foo.prototype = prototypeObject;
|
||||
Foo.prototype.constructor = Foo;
|
||||
obj = new Foo();
|
||||
}
|
||||
const prototypeObject = { foo: 'fooVal' };
|
||||
const obj = Object.create(prototypeObject);
|
||||
|
||||
expect(containing.asymmetricMatch(obj, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it("uses custom equality testers", function() {
|
||||
var tester = function(a, b) {
|
||||
it('uses custom equality testers', function() {
|
||||
const tester = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
if (
|
||||
typeof a == 'string' &&
|
||||
typeof b == 'string' &&
|
||||
a.slice(0, 3) == 'foo' &&
|
||||
b.slice(0, 3) == 'foo'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
const containing = new jasmineUnderTest.ObjectContaining({ foo: 'fooVal' });
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: [tester]
|
||||
});
|
||||
|
||||
expect(containing.asymmetricMatch({foo: "fooBar"}, matchersUtil)).toBe(true);
|
||||
expect(containing.asymmetricMatch({ foo: 'fooBar' }, matchersUtil)).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
describe("valuesForDiff_", function() {
|
||||
describe("when other is not an object", function() {
|
||||
it("sets self to jasmineToString()", function () {
|
||||
var containing = new jasmineUnderTest.ObjectContaining({}),
|
||||
describe('valuesForDiff_', function() {
|
||||
describe('when other is not an object', function() {
|
||||
it('sets self to jasmineToString()', function() {
|
||||
const containing = new jasmineUnderTest.ObjectContaining({}),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
result = containing.valuesForDiff_('a', pp);
|
||||
|
||||
@@ -135,27 +155,31 @@ describe("ObjectContaining", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when other is an object", function() {
|
||||
it("includes keys that are present in both other and sample", function() {
|
||||
var sample = {a: 1, b: 2},
|
||||
other = {a: 3, b: 4},
|
||||
describe('when other is an object', function() {
|
||||
it('includes keys that are present in both other and sample', function() {
|
||||
const sample = { a: 1, b: 2 },
|
||||
other = { a: 3, b: 4 },
|
||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||
result = containing.valuesForDiff_(other);
|
||||
|
||||
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
||||
expect(result.self).not.toBeInstanceOf(
|
||||
jasmineUnderTest.ObjectContaining
|
||||
);
|
||||
expect(result).toEqual({
|
||||
self: sample,
|
||||
other: other
|
||||
});
|
||||
});
|
||||
|
||||
it("includes keys that are present only in sample", function() {
|
||||
var sample = {a: 1, b: 2},
|
||||
other = {a: 3},
|
||||
it('includes keys that are present only in sample', function() {
|
||||
const sample = { a: 1, b: 2 },
|
||||
other = { a: 3 },
|
||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||
result = containing.valuesForDiff_(other);
|
||||
|
||||
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
||||
expect(result.self).not.toBeInstanceOf(
|
||||
jasmineUnderTest.ObjectContaining
|
||||
);
|
||||
expect(containing.valuesForDiff_(other)).toEqual({
|
||||
self: sample,
|
||||
other: {
|
||||
@@ -165,13 +189,15 @@ describe("ObjectContaining", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it("omits keys that are present only in other", function() {
|
||||
var sample = {a: 1, b: 2},
|
||||
other = {a: 3, b: 4, c: 5},
|
||||
it('omits keys that are present only in other', function() {
|
||||
const sample = { a: 1, b: 2 },
|
||||
other = { a: 3, b: 4, c: 5 },
|
||||
containing = new jasmineUnderTest.ObjectContaining(sample),
|
||||
result = containing.valuesForDiff_(other);
|
||||
|
||||
expect(result.self).not.toBeInstanceOf(jasmineUnderTest.ObjectContaining);
|
||||
expect(result.self).not.toBeInstanceOf(
|
||||
jasmineUnderTest.ObjectContaining
|
||||
);
|
||||
expect(result).toEqual({
|
||||
self: sample,
|
||||
other: {
|
||||
|
||||
@@ -1,93 +1,66 @@
|
||||
/* eslint-disable compat/compat */
|
||||
describe('SetContaining', function() {
|
||||
function SetI(iterable) { // for IE11
|
||||
var set = new Set();
|
||||
iterable.forEach(function(v) {
|
||||
set.add(v);
|
||||
});
|
||||
return set;
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
});
|
||||
|
||||
|
||||
it('matches any actual set to an empty set', function() {
|
||||
var actualSet = new SetI(['foo', 'bar']);
|
||||
var containing = new jasmineUnderTest.SetContaining(new Set());
|
||||
const actualSet = new Set(['foo', 'bar']);
|
||||
const containing = new jasmineUnderTest.SetContaining(new Set());
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet)).toBe(true);
|
||||
});
|
||||
|
||||
it('matches when all the values in sample have matches in actual', function() {
|
||||
var actualSet = new SetI([
|
||||
{'foo': 'bar'}, 'baz', [1, 2, 3]
|
||||
]);
|
||||
const actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||
|
||||
var containingSet = new SetI([
|
||||
[1, 2, 3], {'foo': 'bar'}
|
||||
]);
|
||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containingSet = new Set([[1, 2, 3], { foo: 'bar' }]);
|
||||
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match when a value is not in actual', function() {
|
||||
var actualSet = new SetI([
|
||||
{'foo': 'bar'}, 'baz', [1, 2, 3]
|
||||
]);
|
||||
const actualSet = new Set([{ foo: 'bar' }, 'baz', [1, 2, 3]]);
|
||||
|
||||
var containingSet = new SetI([
|
||||
[1, 2], {'foo': 'bar'}
|
||||
]);
|
||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containingSet = new Set([[1, 2], { foo: 'bar' }]);
|
||||
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it('matches when all the values in sample have asymmetric matches in actual', function() {
|
||||
var actualSet = new SetI([
|
||||
[1, 2, 3, 4], 'other', 'foo1'
|
||||
]);
|
||||
const actualSet = new Set([[1, 2, 3, 4], 'other', 'foo1']);
|
||||
|
||||
var containingSet = new SetI([
|
||||
const containingSet = new Set([
|
||||
jasmineUnderTest.stringMatching(/^foo\d/),
|
||||
jasmineUnderTest.arrayContaining([2, 3]),
|
||||
jasmineUnderTest.arrayContaining([2, 3])
|
||||
]);
|
||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match when a value in sample has no asymmetric matches in actual', function() {
|
||||
var actualSet = new SetI([
|
||||
'a-foo1', [1, 2, 3, 4], 'other'
|
||||
]);
|
||||
const actualSet = new Set(['a-foo1', [1, 2, 3, 4], 'other']);
|
||||
|
||||
var containingSet = new SetI([
|
||||
const containingSet = new Set([
|
||||
jasmine.stringMatching(/^foo\d/),
|
||||
jasmine.arrayContaining([2, 3]),
|
||||
jasmine.arrayContaining([2, 3])
|
||||
]);
|
||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(false);
|
||||
});
|
||||
|
||||
it('matches recursively', function() {
|
||||
var actualSet = new SetI([
|
||||
'foo', new SetI([1, 'bar', 2]), 'other'
|
||||
]);
|
||||
const actualSet = new Set(['foo', new Set([1, 'bar', 2]), 'other']);
|
||||
|
||||
var containingSet = new SetI([
|
||||
new jasmineUnderTest.SetContaining(new SetI(['bar'])), 'foo'
|
||||
const containingSet = new Set([
|
||||
new jasmineUnderTest.SetContaining(new Set(['bar'])),
|
||||
'foo'
|
||||
]);
|
||||
var containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
const containing = new jasmineUnderTest.SetContaining(containingSet);
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||
});
|
||||
@@ -95,30 +68,42 @@ describe('SetContaining', function() {
|
||||
it('uses custom equality testers', function() {
|
||||
function tester(a, b) {
|
||||
// treat all negative numbers as equal
|
||||
return (typeof a == 'number' && typeof b == 'number') ? (a < 0 && b < 0) : a === b;
|
||||
return typeof a == 'number' && typeof b == 'number'
|
||||
? a < 0 && b < 0
|
||||
: a === b;
|
||||
}
|
||||
var actualSet = new SetI(['foo', -1]);
|
||||
var containing = new jasmineUnderTest.SetContaining(new SetI([-2, 'foo']));
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
const actualSet = new Set(['foo', -1]);
|
||||
const containing = new jasmineUnderTest.SetContaining(new Set([-2, 'foo']));
|
||||
const matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: [tester]
|
||||
});
|
||||
|
||||
expect(containing.asymmetricMatch(actualSet, matchersUtil)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match when actual is not a set', function() {
|
||||
var containingSet = new SetI(['foo']);
|
||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')).toBe(false);
|
||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(1)).toBe(false);
|
||||
expect(new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(['foo'])).toBe(false);
|
||||
const containingSet = new Set(['foo']);
|
||||
expect(
|
||||
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch('foo')
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(1)
|
||||
).toBe(false);
|
||||
expect(
|
||||
new jasmineUnderTest.SetContaining(containingSet).asymmetricMatch(['foo'])
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('throws an error when sample is not a set', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.SetContaining({'foo': 'bar'}).asymmetricMatch(new Set());
|
||||
new jasmineUnderTest.SetContaining({ foo: 'bar' }).asymmetricMatch(
|
||||
new Set()
|
||||
);
|
||||
}).toThrowError(/You must provide a set/);
|
||||
});
|
||||
|
||||
it('defines a `jasmineToString` method', function() {
|
||||
var sample = new Set(),
|
||||
const sample = new Set(),
|
||||
containing = new jasmineUnderTest.SetContaining(sample),
|
||||
pp = jasmine.createSpy('pp').and.returnValue('sample');
|
||||
|
||||
|
||||
27
spec/core/asymmetric_equality/StringContainingSpec.js
Normal file
27
spec/core/asymmetric_equality/StringContainingSpec.js
Normal file
@@ -0,0 +1,27 @@
|
||||
describe('StringContaining', function() {
|
||||
it('searches for a provided substring when the expected is a String', function() {
|
||||
const matcher = new jasmineUnderTest.StringContaining('foo');
|
||||
|
||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||
});
|
||||
|
||||
it('raises an Error when the expected is not a String', function() {
|
||||
expect(function() {
|
||||
new jasmineUnderTest.StringContaining(/foo/);
|
||||
}).toThrowError(/not a String/);
|
||||
});
|
||||
|
||||
it('fails when the actual is not a String', function() {
|
||||
const matcher = new jasmineUnderTest.StringContaining('x');
|
||||
expect(matcher.asymmetricMatch(['x'])).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToString's itself", function() {
|
||||
const matching = new jasmineUnderTest.StringContaining('foo');
|
||||
|
||||
expect(matching.jasmineToString()).toEqual(
|
||||
'<jasmine.stringContaining("foo")>'
|
||||
);
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user