Compare commits
200 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
516fe68759 | ||
|
|
4530f9431f | ||
|
|
d4b76a4d3b | ||
|
|
764d58a7f5 | ||
|
|
9911d37f06 | ||
|
|
32f99ef99d | ||
|
|
c142490c69 | ||
|
|
24bf3489dc | ||
|
|
5afe1222f4 | ||
|
|
274011ed03 | ||
|
|
42e00b3bc5 | ||
|
|
0eca06a33b | ||
|
|
84953ec210 | ||
|
|
e15f273f06 | ||
|
|
e908b67b19 | ||
|
|
46cc48ccfa | ||
|
|
262a2fe674 | ||
|
|
50cd6fdd68 | ||
|
|
341c6df6ea | ||
|
|
3df9cc26d4 | ||
|
|
6b156ca6d1 | ||
|
|
07996b567f | ||
|
|
9a96396f65 | ||
|
|
12a47f05bf | ||
|
|
414e03bded | ||
|
|
038ab87252 | ||
|
|
f20f78f82b | ||
|
|
70bce55721 | ||
|
|
53529bdc9a | ||
|
|
c82e5947f5 | ||
|
|
f76b452816 | ||
|
|
91aab8e1b8 | ||
|
|
486a64658f | ||
|
|
1dfdc89ba9 | ||
|
|
e2a191b116 | ||
|
|
085a1f8a16 | ||
|
|
cf2f922e30 | ||
|
|
aeeb5b7107 | ||
|
|
170a6dce76 | ||
|
|
4934e420b2 | ||
|
|
1085914a76 | ||
|
|
6f119c4e5a | ||
|
|
298b5ba127 | ||
|
|
16e07a0e99 | ||
|
|
cb6de64e58 | ||
|
|
f69949ebc0 | ||
|
|
1136fddcde | ||
|
|
b943f6b736 | ||
|
|
b439e2fb37 | ||
|
|
c79ce125c0 | ||
|
|
62b815c485 | ||
|
|
65b4499dec | ||
|
|
f38527ff15 | ||
|
|
d742ada71d | ||
|
|
b6cc34d9e9 | ||
|
|
ef9f82a17d | ||
|
|
d3a3cf1ff3 | ||
|
|
c0d0513199 | ||
|
|
86a38fceb9 | ||
|
|
c74af1d900 | ||
|
|
8ea4c6d3a1 | ||
|
|
bdbaebc045 | ||
|
|
2d33765cbf | ||
|
|
bb0992bf5f | ||
|
|
ac5d8708b9 | ||
|
|
eb93d38294 | ||
|
|
0b5dce7d84 | ||
|
|
d16aa550cb | ||
|
|
2200dd084d | ||
|
|
98ead94c51 | ||
|
|
21655a82c9 | ||
|
|
0183b1642d | ||
|
|
18ed34e9be | ||
|
|
f4caf27208 | ||
|
|
a63172f53f | ||
|
|
9619acf91f | ||
|
|
b7e4c1e779 | ||
|
|
e5ada1d010 | ||
|
|
d35b65cf79 | ||
|
|
db615e4186 | ||
|
|
5906a2c05c | ||
|
|
59ad217954 | ||
|
|
b0ec95c472 | ||
|
|
13b9e669bd | ||
|
|
2eef0747a0 | ||
|
|
7ac1244f58 | ||
|
|
6ef0e93880 | ||
|
|
2be5e0a962 | ||
|
|
a42f28c734 | ||
|
|
d58f3dac56 | ||
|
|
676689b063 | ||
|
|
aaf226b9e3 | ||
|
|
419470e9df | ||
|
|
1526d5e2a8 | ||
|
|
a3cb010971 | ||
|
|
278ef9228b | ||
|
|
82eeed3c85 | ||
|
|
ae9b95269c | ||
|
|
285f06d5c4 | ||
|
|
3aece2ac74 | ||
|
|
3a9d4ee08d | ||
|
|
26a7bc6acf | ||
|
|
7b8edcb401 | ||
|
|
395b2b2d97 | ||
|
|
bd250f27c7 | ||
|
|
b4dfdd7a48 | ||
|
|
12ed3bfacd | ||
|
|
324ad0073e | ||
|
|
9f7a6ef061 | ||
|
|
908583c49b | ||
|
|
e31db20ec7 | ||
|
|
c260c67e7e | ||
|
|
554d0efab7 | ||
|
|
ea3cf14ef8 | ||
|
|
a4bdd47a8a | ||
|
|
89306551a0 | ||
|
|
0e95b04900 | ||
|
|
da91294182 | ||
|
|
bd41a97cd5 | ||
|
|
6d3953356d | ||
|
|
62f769767a | ||
|
|
03f7f76bca | ||
|
|
4c6dadb9b1 | ||
|
|
8973e4e44f | ||
|
|
b7e9594c86 | ||
|
|
6c363f11b3 | ||
|
|
0f650e1d03 | ||
|
|
78fe42ac2d | ||
|
|
20d86b2a00 | ||
|
|
516e00d7ba | ||
|
|
c1957ecd7c | ||
|
|
1f6c91de7c | ||
|
|
f6342ad4fe | ||
|
|
8cf8736cab | ||
|
|
6d0f0ed915 | ||
|
|
7ca571a746 | ||
|
|
4240b3514b | ||
|
|
ab116fbd0f | ||
|
|
da2673e02f | ||
|
|
b2dee5cb1c | ||
|
|
1414281cff | ||
|
|
2588b442e6 | ||
|
|
af41e5ea5c | ||
|
|
8834142198 | ||
|
|
1926fc11ae | ||
|
|
e7049d3183 | ||
|
|
80dba1138a | ||
|
|
9811ff71d2 | ||
|
|
301dd4f6b5 | ||
|
|
090a6234c3 | ||
|
|
8ad9abb19a | ||
|
|
8c0a8a1b33 | ||
|
|
1db81c334d | ||
|
|
8dd0ad531c | ||
|
|
f58002f0a6 | ||
|
|
4d18e63b0f | ||
|
|
4fc177d5ae | ||
|
|
acc8c23bf4 | ||
|
|
fc6ee243e9 | ||
|
|
b256741bec | ||
|
|
1d4a2b5c22 | ||
|
|
b0aac6b852 | ||
|
|
543e056056 | ||
|
|
7dfc5f506c | ||
|
|
4cce7263c4 | ||
|
|
31164106e5 | ||
|
|
f71218a44b | ||
|
|
22e9d6df20 | ||
|
|
6ddf64568e | ||
|
|
aa72b0b7cf | ||
|
|
9f3952ff87 | ||
|
|
c604012793 | ||
|
|
6aa069d586 | ||
|
|
585287b9d6 | ||
|
|
de862f8133 | ||
|
|
4e3ae726aa | ||
|
|
9ee7b4ee0b | ||
|
|
2e737f50ca | ||
|
|
c60d669940 | ||
|
|
4c491b2dc0 | ||
|
|
f9d1e2f280 | ||
|
|
270475bc61 | ||
|
|
acb9989178 | ||
|
|
1fe1bbb6ed | ||
|
|
994878e6f6 | ||
|
|
f7c160d716 | ||
|
|
578f63b9bd | ||
|
|
b1190eefb9 | ||
|
|
271908a2c4 | ||
|
|
3372af1cf1 | ||
|
|
d355fa0806 | ||
|
|
56a79bef98 | ||
|
|
2ea4e9507c | ||
|
|
c848a66faa | ||
|
|
99fd7ddb88 | ||
|
|
9672689d40 | ||
|
|
a237ac5386 | ||
|
|
88763012e4 | ||
|
|
e6a7932ec1 | ||
|
|
5ee03f02ed |
@@ -1,16 +0,0 @@
|
||||
languages:
|
||||
JavaScript: true
|
||||
ratings:
|
||||
paths:
|
||||
- "src/**/*.js"
|
||||
exclude_paths:
|
||||
- "lib/**"
|
||||
- "dist/*"
|
||||
- "grunt/**"
|
||||
- "images/*"
|
||||
- "**/*.md"
|
||||
- "**/*.yml"
|
||||
- "**/*.json"
|
||||
- "**/*.scss"
|
||||
- "**/*.erb"
|
||||
- "*.sh"
|
||||
13
.github/CONTRIBUTING.md
vendored
13
.github/CONTRIBUTING.md
vendored
@@ -16,7 +16,8 @@ Please submit pull requests via feature branches using the semi-standard workflo
|
||||
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 # Pull in changes not present in your local repository
|
||||
git fetch upstream # Fetch changes not present in your local repository
|
||||
git merge upstream/master # Sync local master with upstream repository
|
||||
git 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
|
||||
@@ -40,9 +41,9 @@ Once you've pushed a feature branch to your forked repo, you're ready to open a
|
||||
|
||||
### 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 `j$`. So there are two copies of the code loaded under test.
|
||||
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.
|
||||
|
||||
The tests should always use `j$` 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.
|
||||
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`
|
||||
|
||||
@@ -129,11 +130,9 @@ The easiest way to run the tests in **Internet Explorer** is to run a VM that ha
|
||||
1. Ensure all specs are green in browser *and* node
|
||||
1. Ensure JSHint is green with `grunt jshint`
|
||||
1. Build `jasmine.js` with `grunt buildDistribution` and run all specs again - this ensures that your changes self-test well
|
||||
|
||||
## Submitting a Pull Request
|
||||
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
|
||||
1. When we accept your pull request, we will generate these files as a separate commit and merge the entire branch into master
|
||||
* We do this because `jasmine.js` and `jasmine-html.js` are auto-generated (as you've seen in the previous steps) and accepting multiple pull requests when this auto-generated file changes causes lots of headaches
|
||||
* When we accept your pull request, we will generate these files as a separate commit and merge the entire branch into master
|
||||
|
||||
Note that we use Travis for Continuous Integration. We only accept green pull requests.
|
||||
|
||||
|
||||
45
.github/ISSUE_TEMPLATE.md
vendored
45
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,17 +1,44 @@
|
||||
### Are you creating an issue in the correct repository?
|
||||
## Are you creating an issue in the correct repository?
|
||||
|
||||
- When in doubt, create an issue here.
|
||||
- If you have an issue with the Jasmine docs, file an issue in the docs repo
|
||||
here: https://github.com/jasmine/jasmine.github.io
|
||||
- This repository is for the core Jasmine framework
|
||||
- If you are using a test runner that wraps Jasmine (Jasmine npm, karma, etc),
|
||||
consider filing an issue with that library if appropriate
|
||||
- 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 gem](https://github.com/jasmine/jasmine-gem/issues)
|
||||
- [Jasmine py](https://github.com/jasmine/jasmine-py/issues)
|
||||
- [Gulp Jasmine Browser](https://github.com/jasmine/gulp-jasmine-browser/issues)
|
||||
- [Karma](https://github.com/karma-runner/karma/issues)
|
||||
- [Grunt Contrib Jasmine](https://github.com/gruntjs/grunt-contrib-jasmine/issues)
|
||||
|
||||
### When submitting an issue, please answer the following:
|
||||
<!--- Provide a general summary of the issue in the Title above -->
|
||||
|
||||
- What version are you using?
|
||||
- What environment are you running Jasmine in (node, browser, etc)?
|
||||
- How are you running Jasmine (standalone, npm, karma, etc)?
|
||||
- If possible, include an example spec that demonstrates your issue.
|
||||
## Expected Behavior
|
||||
<!--- If you're describing a bug, tell us what should happen -->
|
||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||
|
||||
Thanks for using Jasmine!
|
||||
## Current Behavior
|
||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
||||
|
||||
## Possible Solution
|
||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||
<!--- or ideas how to implement the addition or change -->
|
||||
|
||||
## Suite that reproduces the behavior (for bugs)
|
||||
<!--- Provide a sample suite that reproduces the bug. -->
|
||||
```javascript
|
||||
describe("sample", function() {
|
||||
});
|
||||
```
|
||||
## Context
|
||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
||||
|
||||
## Your Environment
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
* Version used:
|
||||
* Environment name and version (e.g. Chrome 39, node.js 5.4):
|
||||
* Operating System and version (desktop or mobile):
|
||||
* Link to your project:
|
||||
|
||||
30
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
30
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<!--- Provide a general summary of your changes in the Title above -->
|
||||
|
||||
## Description
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
## Motivation and Context
|
||||
<!--- Why is this change required? What problem does it solve? -->
|
||||
<!--- If it fixes an open issue, please link to the issue here. -->
|
||||
|
||||
## How Has This Been Tested?
|
||||
<!--- Please describe in detail how you tested your changes. -->
|
||||
<!--- Include details of your testing environment, and the tests you ran to -->
|
||||
<!--- see how your change affects other areas of the code, etc. -->
|
||||
|
||||
## Types of changes
|
||||
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
|
||||
## Checklist:
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
- [ ] 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 added tests to cover my changes.
|
||||
- [ ] All new and existing tests passed.
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ site/
|
||||
.bundle
|
||||
tags
|
||||
Gemfile.lock
|
||||
package-lock.json
|
||||
pkg/*
|
||||
.sass-cache/*
|
||||
src/html/.sass-cache/*
|
||||
|
||||
26
.travis.yml
26
.travis.yml
@@ -24,7 +24,17 @@ matrix:
|
||||
include:
|
||||
- env:
|
||||
- USE_SAUCE=false
|
||||
- TEST_COMMAND="bash travis-node-script.sh"
|
||||
- TEST_COMMAND="bash travis-node-script.sh v4"
|
||||
- env:
|
||||
- USE_SAUCE=false
|
||||
- TEST_COMMAND="bash travis-node-script.sh v8"
|
||||
- env:
|
||||
- USE_SAUCE=false
|
||||
- TEST_COMMAND="bash travis-node-script.sh v9"
|
||||
- env:
|
||||
- JASMINE_BROWSER="safari"
|
||||
- SAUCE_OS="OS X 10.12"
|
||||
- SAUCE_BROWSER_VERSION=10
|
||||
- env:
|
||||
- JASMINE_BROWSER="safari"
|
||||
- SAUCE_OS="OS X 10.11"
|
||||
@@ -38,9 +48,9 @@ matrix:
|
||||
- SAUCE_OS="OS X 10.9"
|
||||
- SAUCE_BROWSER_VERSION=7
|
||||
- env:
|
||||
- JASMINE_BROWSER="safari"
|
||||
- SAUCE_OS="OS X 10.8"
|
||||
- SAUCE_BROWSER_VERSION=6
|
||||
- JASMINE_BROWSER="MicrosoftEdge"
|
||||
- SAUCE_OS="Windows 10"
|
||||
- SAUCE_BROWSER_VERSION="15"
|
||||
- env:
|
||||
- JASMINE_BROWSER="internet explorer"
|
||||
- SAUCE_OS="Windows 8.1"
|
||||
@@ -49,14 +59,6 @@ matrix:
|
||||
- JASMINE_BROWSER="internet explorer"
|
||||
- SAUCE_OS="Windows 8"
|
||||
- SAUCE_BROWSER_VERSION=10
|
||||
- env:
|
||||
- JASMINE_BROWSER="internet explorer"
|
||||
- SAUCE_OS="Windows 7"
|
||||
- SAUCE_BROWSER_VERSION=9
|
||||
- env:
|
||||
- JASMINE_BROWSER="internet explorer"
|
||||
- SAUCE_OS="Windows 7"
|
||||
- SAUCE_BROWSER_VERSION=8
|
||||
- env:
|
||||
- JASMINE_BROWSER="chrome"
|
||||
- SAUCE_OS="Linux"
|
||||
|
||||
46
CODE_OF_CONDUCT.md
Normal file
46
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at jasmine-maintainers@googlegroups.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
@@ -1,4 +1,5 @@
|
||||
recursive-include . *.py
|
||||
prune node_modules
|
||||
include lib/jasmine-core/*.js
|
||||
include lib/jasmine-core/*.css
|
||||
include images/*.png
|
||||
|
||||
17
README.md
17
README.md
@@ -1,11 +1,8 @@
|
||||
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/master/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
|
||||
|
||||
[](https://travis-ci.org/jasmine/jasmine)
|
||||
[](https://codeclimate.com/github/pivotal/jasmine)
|
||||
|
||||
=======
|
||||
|
||||
**A JavaScript Testing Framework**
|
||||
# A JavaScript Testing Framework
|
||||
|
||||
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
||||
|
||||
@@ -43,17 +40,17 @@ To install Jasmine standalone on your local box (where **_{#.#.#}_** below is su
|
||||
Add the following to your HTML file:
|
||||
|
||||
```html
|
||||
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-core/jasmine_favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-core/jasmine.css">
|
||||
<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-core/jasmine.js"></script>
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-core/jasmine-html.js"></script>
|
||||
<script type="text/javascript" src="jasmine/lib/jasmine-core/boot.js"></script>
|
||||
<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>
|
||||
```
|
||||
|
||||
## Supported environments
|
||||
|
||||
Jasmine tests itself across many browsers (Safari, Chrome, Firefox, PhantomJS, and new Internet Explorer) as well as node. To see the exact version tests are run against look at our [.travis.yml](https://github.com/jasmine/jasmine/blob/master/.travis.yml)
|
||||
Jasmine tests itself across many browsers (Safari, Chrome, Firefox, PhantomJS, Microsoft Edge, and new Internet Explorer) as well as nodejs. To see the exact version tests are run against look at our [.travis.yml](https://github.com/jasmine/jasmine/blob/master/.travis.yml)
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
@@ -7,9 +7,7 @@ Follow the instructions in `CONTRIBUTING.md` during development.
|
||||
|
||||
### Git Rules
|
||||
|
||||
Please work on feature branches.
|
||||
|
||||
Please attempt to keep commits to `master` small, but cohesive. If a feature is contained in a bunch of small commits (e.g., it has several wip commits or small work), please squash them when merging back to `master`.
|
||||
Please attempt to keep commits to `master` small, but cohesive. If a feature is contained in a bunch of small commits (e.g., it has several wip commits or small work), please squash them when pushing to `master`.
|
||||
|
||||
### Version
|
||||
|
||||
@@ -40,7 +38,10 @@ When ready to release - specs are all green and the stories are done:
|
||||
|
||||
### Release the Python egg
|
||||
|
||||
1. `python setup.py register sdist upload` You will need pypi credentials to upload the 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,6 +1,6 @@
|
||||
{
|
||||
"name": "jasmine-core",
|
||||
"homepage": "http://jasmine.github.io",
|
||||
"homepage": "https://jasmine.github.io",
|
||||
"authors": [
|
||||
"slackersoft <gregg@slackersoft.net>"
|
||||
],
|
||||
|
||||
@@ -2,7 +2,6 @@ var standaloneLibDir = "lib/jasmine-" + jasmineVersion;
|
||||
|
||||
function root(path) { return "./" + path; }
|
||||
function libJasmineCore(path) { return root("lib/jasmine-core/" + path); }
|
||||
function libConsole() { return "lib/console/" }
|
||||
function dist(path) { return root("dist/" + path); }
|
||||
|
||||
module.exports = {
|
||||
@@ -29,14 +28,6 @@ module.exports = {
|
||||
expand: true,
|
||||
cwd: libJasmineCore("")
|
||||
},
|
||||
{
|
||||
src: [
|
||||
"console.js"
|
||||
],
|
||||
dest: standaloneLibDir,
|
||||
expand: true,
|
||||
cwd: libConsole()
|
||||
},
|
||||
{
|
||||
src: [ "boot.js" ],
|
||||
dest: standaloneLibDir,
|
||||
|
||||
@@ -15,7 +15,8 @@ module.exports = {
|
||||
'src/html/HtmlReporter.js',
|
||||
'src/html/HtmlSpecFilter.js',
|
||||
'src/html/ResultsNode.js',
|
||||
'src/html/QueryString.js'
|
||||
'src/html/QueryString.js',
|
||||
'src/html/**/*.js'
|
||||
],
|
||||
dest: 'lib/jasmine-core/jasmine-html.js'
|
||||
},
|
||||
@@ -44,13 +45,6 @@ module.exports = {
|
||||
src: ['lib/jasmine-core/boot/node_boot.js'],
|
||||
dest: 'lib/jasmine-core/node_boot.js'
|
||||
},
|
||||
console: {
|
||||
src: [
|
||||
'src/console/requireConsole.js',
|
||||
'src/console/ConsoleReporter.js'
|
||||
],
|
||||
dest: 'lib/console/console.js'
|
||||
},
|
||||
options: {
|
||||
banner: license(),
|
||||
process: {
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2008-2017 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.
|
||||
*/
|
||||
function getJasmineRequireObj() {
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
return exports;
|
||||
} else {
|
||||
window.jasmineRequire = window.jasmineRequire || {};
|
||||
return window.jasmineRequire;
|
||||
}
|
||||
}
|
||||
|
||||
getJasmineRequireObj().console = function(jRequire, j$) {
|
||||
j$.ConsoleReporter = jRequire.ConsoleReporter();
|
||||
};
|
||||
|
||||
getJasmineRequireObj().ConsoleReporter = function() {
|
||||
|
||||
var noopTimer = {
|
||||
start: function(){},
|
||||
elapsed: function(){ return 0; }
|
||||
};
|
||||
|
||||
function ConsoleReporter(options) {
|
||||
var print = options.print,
|
||||
showColors = options.showColors || false,
|
||||
onComplete = options.onComplete || function() {},
|
||||
timer = options.timer || noopTimer,
|
||||
specCount,
|
||||
failureCount,
|
||||
failedSpecs = [],
|
||||
pendingCount,
|
||||
ansi = {
|
||||
green: '\x1B[32m',
|
||||
red: '\x1B[31m',
|
||||
yellow: '\x1B[33m',
|
||||
none: '\x1B[0m'
|
||||
},
|
||||
failedSuites = [];
|
||||
|
||||
print('ConsoleReporter is deprecated and will be removed in a future version.');
|
||||
|
||||
this.jasmineStarted = function() {
|
||||
specCount = 0;
|
||||
failureCount = 0;
|
||||
pendingCount = 0;
|
||||
print('Started');
|
||||
printNewline();
|
||||
timer.start();
|
||||
};
|
||||
|
||||
this.jasmineDone = function() {
|
||||
printNewline();
|
||||
for (var i = 0; i < failedSpecs.length; i++) {
|
||||
specFailureDetails(failedSpecs[i]);
|
||||
}
|
||||
|
||||
if(specCount > 0) {
|
||||
printNewline();
|
||||
|
||||
var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' +
|
||||
failureCount + ' ' + plural('failure', failureCount);
|
||||
|
||||
if (pendingCount) {
|
||||
specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount);
|
||||
}
|
||||
|
||||
print(specCounts);
|
||||
} else {
|
||||
print('No specs found');
|
||||
}
|
||||
|
||||
printNewline();
|
||||
var seconds = timer.elapsed() / 1000;
|
||||
print('Finished in ' + seconds + ' ' + plural('second', seconds));
|
||||
printNewline();
|
||||
|
||||
for(i = 0; i < failedSuites.length; i++) {
|
||||
suiteFailureDetails(failedSuites[i]);
|
||||
}
|
||||
|
||||
onComplete(failureCount === 0);
|
||||
};
|
||||
|
||||
this.specDone = function(result) {
|
||||
specCount++;
|
||||
|
||||
if (result.status == 'pending') {
|
||||
pendingCount++;
|
||||
print(colored('yellow', '*'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.status == 'passed') {
|
||||
print(colored('green', '.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.status == 'failed') {
|
||||
failureCount++;
|
||||
failedSpecs.push(result);
|
||||
print(colored('red', 'F'));
|
||||
}
|
||||
};
|
||||
|
||||
this.suiteDone = function(result) {
|
||||
if (result.failedExpectations && result.failedExpectations.length > 0) {
|
||||
failureCount++;
|
||||
failedSuites.push(result);
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
function printNewline() {
|
||||
print('\n');
|
||||
}
|
||||
|
||||
function colored(color, str) {
|
||||
return showColors ? (ansi[color] + str + ansi.none) : str;
|
||||
}
|
||||
|
||||
function plural(str, count) {
|
||||
return count == 1 ? str : str + 's';
|
||||
}
|
||||
|
||||
function repeat(thing, times) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < times; i++) {
|
||||
arr.push(thing);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
function indent(str, spaces) {
|
||||
var lines = (str || '').split('\n');
|
||||
var newArr = [];
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
newArr.push(repeat(' ', spaces).join('') + lines[i]);
|
||||
}
|
||||
return newArr.join('\n');
|
||||
}
|
||||
|
||||
function specFailureDetails(result) {
|
||||
printNewline();
|
||||
print(result.fullName);
|
||||
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
var failedExpectation = result.failedExpectations[i];
|
||||
printNewline();
|
||||
print(indent(failedExpectation.message, 2));
|
||||
print(indent(failedExpectation.stack, 2));
|
||||
}
|
||||
|
||||
printNewline();
|
||||
}
|
||||
|
||||
function suiteFailureDetails(result) {
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
printNewline();
|
||||
print(colored('red', 'An error was thrown in an afterAll'));
|
||||
printNewline();
|
||||
print(colored('red', 'AfterAll ' + result.failedExpectations[i].message));
|
||||
|
||||
}
|
||||
printNewline();
|
||||
}
|
||||
}
|
||||
|
||||
return ConsoleReporter;
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2017 Pivotal Labs
|
||||
Copyright (c) 2008-2018 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
@@ -73,14 +73,17 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var filterSpecs = !!queryString.getParam("spec");
|
||||
|
||||
var catchingExceptions = queryString.getParam("catch");
|
||||
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
|
||||
var stoppingOnSpecFailure = queryString.getParam("failFast");
|
||||
env.stopOnSpecFailure(stoppingOnSpecFailure);
|
||||
|
||||
var throwingExpectationFailures = queryString.getParam("throwFailures");
|
||||
env.throwOnExpectationFailure(throwingExpectationFailures);
|
||||
|
||||
var random = queryString.getParam("random");
|
||||
env.randomizeTests(random);
|
||||
|
||||
if (random !== undefined && random !== "") {
|
||||
env.randomizeTests(random);
|
||||
}
|
||||
|
||||
var seed = queryString.getParam("seed");
|
||||
if (seed) {
|
||||
@@ -93,9 +96,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); },
|
||||
onThrowExpectationsClick: function() { queryString.navigateWithNewParam("throwFailures", !env.throwingExpectationFailures()); },
|
||||
onRandomClick: function() { queryString.navigateWithNewParam("random", !env.randomTests()); },
|
||||
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); },
|
||||
|
||||
@@ -51,14 +51,17 @@
|
||||
|
||||
var filterSpecs = !!queryString.getParam("spec");
|
||||
|
||||
var catchingExceptions = queryString.getParam("catch");
|
||||
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
|
||||
var stoppingOnSpecFailure = queryString.getParam("failFast");
|
||||
env.stopOnSpecFailure(stoppingOnSpecFailure);
|
||||
|
||||
var throwingExpectationFailures = queryString.getParam("throwFailures");
|
||||
env.throwOnExpectationFailure(throwingExpectationFailures);
|
||||
|
||||
var random = queryString.getParam("random");
|
||||
env.randomizeTests(random);
|
||||
|
||||
if (random !== undefined && random !== "") {
|
||||
env.randomizeTests(random);
|
||||
}
|
||||
|
||||
var seed = queryString.getParam("seed");
|
||||
if (seed) {
|
||||
@@ -71,9 +74,7 @@
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); },
|
||||
onThrowExpectationsClick: function() { queryString.navigateWithNewParam("throwFailures", !env.throwingExpectationFailures()); },
|
||||
onRandomClick: function() { queryString.navigateWithNewParam("random", !env.randomTests()); },
|
||||
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); },
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
module.exports = function(jasmineRequire) {
|
||||
var jasmine = jasmineRequire.core(jasmineRequire);
|
||||
|
||||
var consoleFns = require('../console/console.js');
|
||||
consoleFns.console(consoleFns, jasmine);
|
||||
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2017 Pivotal Labs
|
||||
Copyright (c) 2008-2018 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
@@ -25,6 +25,7 @@ jasmineRequire.html = function(j$) {
|
||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||
j$.QueryString = jasmineRequire.QueryString();
|
||||
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
||||
j$.matchers.toHaveClass = jasmineRequire.toHaveClass(j$);
|
||||
};
|
||||
|
||||
jasmineRequire.HtmlReporter = function(j$) {
|
||||
@@ -34,24 +35,63 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
elapsed: function() { return 0; }
|
||||
};
|
||||
|
||||
function ResultsStateBuilder() {
|
||||
this.topResults = new j$.ResultsNode({}, '', null);
|
||||
this.currentParent = this.topResults;
|
||||
this.specsExecuted = 0;
|
||||
this.failureCount = 0;
|
||||
this.pendingSpecCount = 0;
|
||||
}
|
||||
|
||||
ResultsStateBuilder.prototype.suiteStarted = function(result) {
|
||||
this.currentParent.addChild(result, 'suite');
|
||||
this.currentParent = this.currentParent.last();
|
||||
};
|
||||
|
||||
ResultsStateBuilder.prototype.suiteDone = function(result) {
|
||||
this.currentParent.updateResult(result);
|
||||
if (this.currentParent !== this.topResults) {
|
||||
this.currentParent = this.currentParent.parent;
|
||||
}
|
||||
|
||||
if (result.status === 'failed') {
|
||||
this.failureCount++;
|
||||
}
|
||||
};
|
||||
|
||||
ResultsStateBuilder.prototype.specStarted = function(result) {
|
||||
};
|
||||
|
||||
ResultsStateBuilder.prototype.specDone = function(result) {
|
||||
this.currentParent.addChild(result, 'spec');
|
||||
|
||||
if (result.status !== 'excluded') {
|
||||
this.specsExecuted++;
|
||||
}
|
||||
|
||||
if (result.status === 'failed') {
|
||||
this.failureCount++;
|
||||
}
|
||||
|
||||
if (result.status == 'pending') {
|
||||
this.pendingSpecCount++;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function HtmlReporter(options) {
|
||||
var env = options.env || {},
|
||||
getContainer = options.getContainer,
|
||||
createElement = options.createElement,
|
||||
createTextNode = options.createTextNode,
|
||||
onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
|
||||
onThrowExpectationsClick = options.onThrowExpectationsClick || function() {},
|
||||
onRandomClick = options.onRandomClick || function() {},
|
||||
navigateWithNewParam = options.navigateWithNewParam || function() {},
|
||||
addToExistingQueryString = options.addToExistingQueryString || defaultQueryString,
|
||||
filterSpecs = options.filterSpecs,
|
||||
timer = options.timer || noopTimer,
|
||||
results = [],
|
||||
specsExecuted = 0,
|
||||
failureCount = 0,
|
||||
pendingSpecCount = 0,
|
||||
htmlReporterMain,
|
||||
symbols,
|
||||
failedSuites = [];
|
||||
deprecationWarnings = [];
|
||||
|
||||
this.initialize = function() {
|
||||
clearPrior();
|
||||
@@ -77,40 +117,33 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
var summary = createDom('div', {className: 'jasmine-summary'});
|
||||
|
||||
var topResults = new j$.ResultsNode({}, '', null),
|
||||
currentParent = topResults;
|
||||
var stateBuilder = new ResultsStateBuilder();
|
||||
|
||||
this.suiteStarted = function(result) {
|
||||
currentParent.addChild(result, 'suite');
|
||||
currentParent = currentParent.last();
|
||||
stateBuilder.suiteStarted(result);
|
||||
};
|
||||
|
||||
this.suiteDone = function(result) {
|
||||
if (result.status == 'failed') {
|
||||
failedSuites.push(result);
|
||||
}
|
||||
stateBuilder.suiteDone(result);
|
||||
|
||||
if (currentParent == topResults) {
|
||||
return;
|
||||
if (result.status === 'failed') {
|
||||
failures.push(failureDom(result));
|
||||
}
|
||||
|
||||
currentParent = currentParent.parent;
|
||||
addDeprecationWarnings(result);
|
||||
};
|
||||
|
||||
this.specStarted = function(result) {
|
||||
currentParent.addChild(result, 'spec');
|
||||
stateBuilder.specStarted(result);
|
||||
};
|
||||
|
||||
var failures = [];
|
||||
this.specDone = function(result) {
|
||||
stateBuilder.specDone(result);
|
||||
|
||||
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
|
||||
console.error('Spec \'' + result.fullName + '\' has no expectations.');
|
||||
}
|
||||
|
||||
if (result.status != 'disabled') {
|
||||
specsExecuted++;
|
||||
}
|
||||
|
||||
if (!symbols){
|
||||
symbols = find('.jasmine-symbol-summary');
|
||||
}
|
||||
@@ -122,30 +155,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
));
|
||||
|
||||
if (result.status == 'failed') {
|
||||
failureCount++;
|
||||
|
||||
var failure =
|
||||
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
|
||||
createDom('div', {className: 'jasmine-description'},
|
||||
createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName)
|
||||
),
|
||||
createDom('div', {className: 'jasmine-messages'})
|
||||
);
|
||||
var messages = failure.childNodes[1];
|
||||
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
var expectation = result.failedExpectations[i];
|
||||
messages.appendChild(createDom('div', {className: 'jasmine-result-message'}, expectation.message));
|
||||
messages.appendChild(createDom('div', {className: 'jasmine-stack-trace'}, expectation.stack));
|
||||
}
|
||||
|
||||
failures.push(failure);
|
||||
if (result.status === 'failed') {
|
||||
failures.push(failureDom(result));
|
||||
}
|
||||
|
||||
if (result.status == 'pending') {
|
||||
pendingSpecCount++;
|
||||
}
|
||||
addDeprecationWarnings(result);
|
||||
};
|
||||
|
||||
this.jasmineDone = function(doneResult) {
|
||||
@@ -154,63 +168,11 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
var order = doneResult && doneResult.order;
|
||||
alert.appendChild(createDom('span', {className: 'jasmine-duration'}, 'finished in ' + timer.elapsed() / 1000 + 's'));
|
||||
|
||||
banner.appendChild(
|
||||
createDom('div', { className: 'jasmine-run-options' },
|
||||
createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
||||
createDom('div', { className: 'jasmine-payload' },
|
||||
createDom('div', { className: 'jasmine-exceptions' },
|
||||
createDom('input', {
|
||||
className: 'jasmine-raise',
|
||||
id: 'jasmine-raise-exceptions',
|
||||
type: 'checkbox'
|
||||
}),
|
||||
createDom('label', { className: 'jasmine-label', 'for': 'jasmine-raise-exceptions' }, 'raise exceptions')),
|
||||
createDom('div', { className: 'jasmine-throw-failures' },
|
||||
createDom('input', {
|
||||
className: 'jasmine-throw',
|
||||
id: 'jasmine-throw-failures',
|
||||
type: 'checkbox'
|
||||
}),
|
||||
createDom('label', { className: 'jasmine-label', 'for': 'jasmine-throw-failures' }, 'stop spec on expectation failure')),
|
||||
createDom('div', { className: 'jasmine-random-order' },
|
||||
createDom('input', {
|
||||
className: 'jasmine-random',
|
||||
id: 'jasmine-random-order',
|
||||
type: 'checkbox'
|
||||
}),
|
||||
createDom('label', { className: 'jasmine-label', 'for': 'jasmine-random-order' }, 'run tests in random order'))
|
||||
)
|
||||
));
|
||||
banner.appendChild(optionsMenu(env));
|
||||
|
||||
var raiseCheckbox = find('#jasmine-raise-exceptions');
|
||||
|
||||
raiseCheckbox.checked = !env.catchingExceptions();
|
||||
raiseCheckbox.onclick = onRaiseExceptionsClick;
|
||||
|
||||
var throwCheckbox = find('#jasmine-throw-failures');
|
||||
throwCheckbox.checked = env.throwingExpectationFailures();
|
||||
throwCheckbox.onclick = onThrowExpectationsClick;
|
||||
|
||||
var randomCheckbox = find('#jasmine-random-order');
|
||||
randomCheckbox.checked = env.randomTests();
|
||||
randomCheckbox.onclick = onRandomClick;
|
||||
|
||||
var optionsMenu = find('.jasmine-run-options'),
|
||||
optionsTrigger = optionsMenu.querySelector('.jasmine-trigger'),
|
||||
optionsPayload = optionsMenu.querySelector('.jasmine-payload'),
|
||||
isOpen = /\bjasmine-open\b/;
|
||||
|
||||
optionsTrigger.onclick = function() {
|
||||
if (isOpen.test(optionsPayload.className)) {
|
||||
optionsPayload.className = optionsPayload.className.replace(isOpen, '');
|
||||
} else {
|
||||
optionsPayload.className += ' jasmine-open';
|
||||
}
|
||||
};
|
||||
|
||||
if (specsExecuted < totalSpecsDefined) {
|
||||
var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
|
||||
var skippedLink = order && order.random ? '?random=true' : '?';
|
||||
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
||||
var skippedMessage = 'Ran ' + stateBuilder.specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
|
||||
var skippedLink = addToExistingQueryString('spec', '');
|
||||
alert.appendChild(
|
||||
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
|
||||
createDom('a', {href: skippedLink, title: 'Run all specs'}, skippedMessage)
|
||||
@@ -218,15 +180,22 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
);
|
||||
}
|
||||
var statusBarMessage = '';
|
||||
var statusBarClassName = 'jasmine-bar ';
|
||||
var statusBarClassName = 'jasmine-overall-result jasmine-bar ';
|
||||
var globalFailures = (doneResult && doneResult.failedExpectations) || [];
|
||||
var failed = stateBuilder.failureCount + globalFailures.length > 0;
|
||||
|
||||
if (totalSpecsDefined > 0) {
|
||||
statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
|
||||
if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
|
||||
statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
|
||||
if (totalSpecsDefined > 0 || failed) {
|
||||
statusBarMessage += pluralize('spec', stateBuilder.specsExecuted) + ', ' + pluralize('failure', stateBuilder.failureCount);
|
||||
if (stateBuilder.pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', stateBuilder.pendingSpecCount); }
|
||||
}
|
||||
|
||||
if (doneResult.overallStatus === 'passed') {
|
||||
statusBarClassName += ' jasmine-passed ';
|
||||
} else if (doneResult.overallStatus === 'incomplete') {
|
||||
statusBarClassName += ' jasmine-incomplete ';
|
||||
statusBarMessage = 'Incomplete: ' + doneResult.incompleteReason + ', ' + statusBarMessage;
|
||||
} else {
|
||||
statusBarClassName += 'jasmine-skipped';
|
||||
statusBarMessage += 'No specs found';
|
||||
statusBarClassName += ' jasmine-failed ';
|
||||
}
|
||||
|
||||
var seedBar;
|
||||
@@ -240,66 +209,38 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage, seedBar));
|
||||
|
||||
var errorBarClassName = 'jasmine-bar jasmine-errored';
|
||||
var errorBarMessagePrefix = 'AfterAll ';
|
||||
var afterAllMessagePrefix = 'AfterAll ';
|
||||
|
||||
for(var i = 0; i < failedSuites.length; i++) {
|
||||
var failedSuite = failedSuites[i];
|
||||
for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
|
||||
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failedSuite.failedExpectations[j].message));
|
||||
for(i = 0; i < globalFailures.length; i++) {
|
||||
alert.appendChild(createDom('span', {className: errorBarClassName}, globalFailureMessage(globalFailures[i])));
|
||||
}
|
||||
|
||||
function globalFailureMessage(failure) {
|
||||
if (failure.globalErrorType === 'load') {
|
||||
var prefix = 'Error during loading: ' + failure.message;
|
||||
|
||||
if (failure.filename) {
|
||||
return prefix + ' in ' + failure.filename + ' line ' + failure.lineno;
|
||||
} else {
|
||||
return prefix;
|
||||
}
|
||||
} else {
|
||||
return afterAllMessagePrefix + failure.message;
|
||||
}
|
||||
}
|
||||
|
||||
var globalFailures = (doneResult && doneResult.failedExpectations) || [];
|
||||
for(i = 0; i < globalFailures.length; i++) {
|
||||
var failure = globalFailures[i];
|
||||
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message));
|
||||
addDeprecationWarnings(doneResult);
|
||||
|
||||
var warningBarClassName = 'jasmine-bar jasmine-warning';
|
||||
for(i = 0; i < deprecationWarnings.length; i++) {
|
||||
var warning = deprecationWarnings[i];
|
||||
alert.appendChild(createDom('span', {className: warningBarClassName}, 'DEPRECATION: ' + warning));
|
||||
}
|
||||
|
||||
var results = find('.jasmine-results');
|
||||
results.appendChild(summary);
|
||||
|
||||
summaryList(topResults, summary);
|
||||
|
||||
function summaryList(resultsTree, domParent) {
|
||||
var specListNode;
|
||||
for (var i = 0; i < resultsTree.children.length; i++) {
|
||||
var resultNode = resultsTree.children[i];
|
||||
if (filterSpecs && !hasActiveSpec(resultNode)) {
|
||||
continue;
|
||||
}
|
||||
if (resultNode.type == 'suite') {
|
||||
var suiteListNode = createDom('ul', {className: 'jasmine-suite', id: 'suite-' + resultNode.result.id},
|
||||
createDom('li', {className: 'jasmine-suite-detail'},
|
||||
createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description)
|
||||
)
|
||||
);
|
||||
|
||||
summaryList(resultNode, suiteListNode);
|
||||
domParent.appendChild(suiteListNode);
|
||||
}
|
||||
if (resultNode.type == 'spec') {
|
||||
if (domParent.getAttribute('class') != 'jasmine-specs') {
|
||||
specListNode = createDom('ul', {className: 'jasmine-specs'});
|
||||
domParent.appendChild(specListNode);
|
||||
}
|
||||
var specDescription = resultNode.result.description;
|
||||
if(noExpectations(resultNode.result)) {
|
||||
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
||||
}
|
||||
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
|
||||
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
|
||||
}
|
||||
specListNode.appendChild(
|
||||
createDom('li', {
|
||||
className: 'jasmine-' + resultNode.result.status,
|
||||
id: 'spec-' + resultNode.result.id
|
||||
},
|
||||
createDom('a', {href: specHref(resultNode.result)}, specDescription)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
summaryList(stateBuilder.topResults, summary);
|
||||
|
||||
if (failures.length) {
|
||||
alert.appendChild(
|
||||
@@ -329,6 +270,164 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
return this;
|
||||
|
||||
function failureDom(result) {
|
||||
var failure =
|
||||
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
|
||||
failureDescription(result, stateBuilder.currentParent),
|
||||
createDom('div', {className: 'jasmine-messages'})
|
||||
);
|
||||
var messages = failure.childNodes[1];
|
||||
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
var expectation = result.failedExpectations[i];
|
||||
messages.appendChild(createDom('div', {className: 'jasmine-result-message'}, expectation.message));
|
||||
messages.appendChild(createDom('div', {className: 'jasmine-stack-trace'}, expectation.stack));
|
||||
}
|
||||
|
||||
return failure;
|
||||
}
|
||||
|
||||
function summaryList(resultsTree, domParent) {
|
||||
var specListNode;
|
||||
for (var i = 0; i < resultsTree.children.length; i++) {
|
||||
var resultNode = resultsTree.children[i];
|
||||
if (filterSpecs && !hasActiveSpec(resultNode)) {
|
||||
continue;
|
||||
}
|
||||
if (resultNode.type === 'suite') {
|
||||
var suiteListNode = createDom('ul', {className: 'jasmine-suite', id: 'suite-' + resultNode.result.id},
|
||||
createDom('li', {className: 'jasmine-suite-detail jasmine-' + resultNode.result.status},
|
||||
createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description)
|
||||
)
|
||||
);
|
||||
|
||||
summaryList(resultNode, suiteListNode);
|
||||
domParent.appendChild(suiteListNode);
|
||||
}
|
||||
if (resultNode.type === 'spec') {
|
||||
if (domParent.getAttribute('class') !== 'jasmine-specs') {
|
||||
specListNode = createDom('ul', {className: 'jasmine-specs'});
|
||||
domParent.appendChild(specListNode);
|
||||
}
|
||||
var specDescription = resultNode.result.description;
|
||||
if(noExpectations(resultNode.result)) {
|
||||
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
|
||||
}
|
||||
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
|
||||
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
|
||||
}
|
||||
specListNode.appendChild(
|
||||
createDom('li', {
|
||||
className: 'jasmine-' + resultNode.result.status,
|
||||
id: 'spec-' + resultNode.result.id
|
||||
},
|
||||
createDom('a', {href: specHref(resultNode.result)}, specDescription)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function optionsMenu(env) {
|
||||
var optionsMenuDom = createDom('div', { className: 'jasmine-run-options' },
|
||||
createDom('span', { className: 'jasmine-trigger' }, 'Options'),
|
||||
createDom('div', { className: 'jasmine-payload' },
|
||||
createDom('div', { className: 'jasmine-stop-on-failure' },
|
||||
createDom('input', {
|
||||
className: 'jasmine-fail-fast',
|
||||
id: 'jasmine-fail-fast',
|
||||
type: 'checkbox'
|
||||
}),
|
||||
createDom('label', { className: 'jasmine-label', 'for': 'jasmine-fail-fast' }, 'stop execution on spec failure')),
|
||||
createDom('div', { className: 'jasmine-throw-failures' },
|
||||
createDom('input', {
|
||||
className: 'jasmine-throw',
|
||||
id: 'jasmine-throw-failures',
|
||||
type: 'checkbox'
|
||||
}),
|
||||
createDom('label', { className: 'jasmine-label', 'for': 'jasmine-throw-failures' }, 'stop spec on expectation failure')),
|
||||
createDom('div', { className: 'jasmine-random-order' },
|
||||
createDom('input', {
|
||||
className: 'jasmine-random',
|
||||
id: 'jasmine-random-order',
|
||||
type: 'checkbox'
|
||||
}),
|
||||
createDom('label', { className: 'jasmine-label', 'for': 'jasmine-random-order' }, 'run tests in random order'))
|
||||
)
|
||||
);
|
||||
|
||||
var failFastCheckbox = optionsMenuDom.querySelector('#jasmine-fail-fast');
|
||||
failFastCheckbox.checked = env.stoppingOnSpecFailure();
|
||||
failFastCheckbox.onclick = function() {
|
||||
navigateWithNewParam('failFast', !env.stoppingOnSpecFailure());
|
||||
};
|
||||
|
||||
var throwCheckbox = optionsMenuDom.querySelector('#jasmine-throw-failures');
|
||||
throwCheckbox.checked = env.throwingExpectationFailures();
|
||||
throwCheckbox.onclick = function() {
|
||||
navigateWithNewParam('throwFailures', !env.throwingExpectationFailures());
|
||||
};
|
||||
|
||||
var randomCheckbox = optionsMenuDom.querySelector('#jasmine-random-order');
|
||||
randomCheckbox.checked = env.randomTests();
|
||||
randomCheckbox.onclick = function() {
|
||||
navigateWithNewParam('random', !env.randomTests());
|
||||
};
|
||||
|
||||
var optionsTrigger = optionsMenuDom.querySelector('.jasmine-trigger'),
|
||||
optionsPayload = optionsMenuDom.querySelector('.jasmine-payload'),
|
||||
isOpen = /\bjasmine-open\b/;
|
||||
|
||||
optionsTrigger.onclick = function() {
|
||||
if (isOpen.test(optionsPayload.className)) {
|
||||
optionsPayload.className = optionsPayload.className.replace(isOpen, '');
|
||||
} else {
|
||||
optionsPayload.className += ' jasmine-open';
|
||||
}
|
||||
};
|
||||
|
||||
return optionsMenuDom;
|
||||
}
|
||||
|
||||
function failureDescription(result, suite) {
|
||||
var wrapper = createDom('div', {className: 'jasmine-description'},
|
||||
createDom('a', {title: result.description, href: specHref(result)}, result.description)
|
||||
);
|
||||
var suiteLink;
|
||||
|
||||
while (suite && suite.parent) {
|
||||
wrapper.insertBefore(createTextNode(' > '), wrapper.firstChild);
|
||||
suiteLink = createDom('a', {href: suiteHref(suite)}, suite.result.description);
|
||||
wrapper.insertBefore(suiteLink, wrapper.firstChild);
|
||||
|
||||
suite = suite.parent;
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function suiteHref(suite) {
|
||||
var els = [];
|
||||
|
||||
while (suite && suite.parent) {
|
||||
els.unshift(suite.result.description);
|
||||
suite = suite.parent;
|
||||
}
|
||||
|
||||
return addToExistingQueryString('spec', els.join(' '));
|
||||
}
|
||||
|
||||
function addDeprecationWarnings(result) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function find(selector) {
|
||||
return getContainer().querySelector('.jasmine_html-reporter ' + selector);
|
||||
}
|
||||
@@ -396,7 +495,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function hasActiveSpec(resultNode) {
|
||||
if (resultNode.type == 'spec' && resultNode.result.status != 'disabled') {
|
||||
if (resultNode.type == 'spec' && resultNode.result.status != 'excluded') {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -441,6 +540,10 @@ jasmineRequire.ResultsNode = function() {
|
||||
this.last = function() {
|
||||
return this.children[this.children.length - 1];
|
||||
};
|
||||
|
||||
this.updateResult = function(result) {
|
||||
this.result = result;
|
||||
};
|
||||
}
|
||||
|
||||
return ResultsNode;
|
||||
@@ -497,3 +600,37 @@ jasmineRequire.QueryString = function() {
|
||||
|
||||
return QueryString;
|
||||
};
|
||||
|
||||
jasmineRequire.toHaveClass = function(j$) {
|
||||
/**
|
||||
* {@link expect} the actual value to be a DOM element that has the expected class
|
||||
* @function
|
||||
* @name matchers#toHaveClass
|
||||
* @param {Object} expected - The class name to test for
|
||||
* @example
|
||||
* var el = document.createElement('div');
|
||||
* el.className = 'foo bar baz';
|
||||
* expect(el).toHaveClass('bar');
|
||||
*/
|
||||
function toHaveClass(util, customEqualityTesters) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
if (!isElement(actual)) {
|
||||
throw new Error(j$.pp(actual) + ' is not a DOM element');
|
||||
}
|
||||
|
||||
return {
|
||||
pass: actual.classList.contains(expected)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function isElement(maybeEl) {
|
||||
return maybeEl &&
|
||||
maybeEl.classList &&
|
||||
j$.isFunction_(maybeEl.classList.contains);
|
||||
}
|
||||
|
||||
return toHaveClass;
|
||||
};
|
||||
|
||||
@@ -18,8 +18,8 @@ body { overflow-y: scroll; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-passed:before { color: #007069; content: "\02022"; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-failed { line-height: 9px; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-failed:before { color: #ca3a11; content: "\d7"; font-weight: bold; margin-left: -1px; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-disabled { font-size: 14px; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-disabled:before { color: #bababa; content: "\02022"; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-excluded { font-size: 14px; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-excluded:before { color: #bababa; content: "\02022"; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-pending { line-height: 17px; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-pending:before { color: #ba9d37; content: "*"; }
|
||||
.jasmine_html-reporter .jasmine-symbol-summary li.jasmine-empty { font-size: 14px; }
|
||||
@@ -29,10 +29,17 @@ body { overflow-y: scroll; }
|
||||
.jasmine_html-reporter .jasmine-run-options .jasmine-payload { position: absolute; display: none; right: -1px; border: 1px solid #8a4182; background-color: #eee; white-space: nowrap; padding: 4px 8px; }
|
||||
.jasmine_html-reporter .jasmine-run-options .jasmine-payload.jasmine-open { display: block; }
|
||||
.jasmine_html-reporter .jasmine-bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-failed { background-color: #ca3a11; }
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-failed, .jasmine_html-reporter .jasmine-bar.jasmine-errored { background-color: #ca3a11; border-bottom: 1px solid #eee; }
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-passed { background-color: #007069; }
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-incomplete { background-color: #bababa; }
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-skipped { background-color: #bababa; }
|
||||
<<<<<<< HEAD
|
||||
||||||| merged common ancestors
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-errored { background-color: #ca3a11; }
|
||||
=======
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-errored { background-color: #ca3a11; }
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-warning { background-color: #ba9d37; color: #333; }
|
||||
>>>>>>> master
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-menu { background-color: #fff; color: #aaa; }
|
||||
.jasmine_html-reporter .jasmine-bar.jasmine-menu a { color: #333; }
|
||||
.jasmine_html-reporter .jasmine-bar a { color: white; }
|
||||
@@ -46,12 +53,12 @@ body { overflow-y: scroll; }
|
||||
.jasmine_html-reporter .jasmine-summary li.jasmine-failed a { color: #ca3a11; }
|
||||
.jasmine_html-reporter .jasmine-summary li.jasmine-empty a { color: #ba9d37; }
|
||||
.jasmine_html-reporter .jasmine-summary li.jasmine-pending a { color: #ba9d37; }
|
||||
.jasmine_html-reporter .jasmine-summary li.jasmine-disabled a { color: #bababa; }
|
||||
.jasmine_html-reporter .jasmine-summary li.jasmine-excluded a { color: #bababa; }
|
||||
.jasmine_html-reporter .jasmine-description + .jasmine-suite { margin-top: 0; }
|
||||
.jasmine_html-reporter .jasmine-suite { margin-top: 14px; }
|
||||
.jasmine_html-reporter .jasmine-suite a { color: #333; }
|
||||
.jasmine_html-reporter .jasmine-failures .jasmine-spec-detail { margin-bottom: 28px; }
|
||||
.jasmine_html-reporter .jasmine-failures .jasmine-spec-detail .jasmine-description { background-color: #ca3a11; }
|
||||
.jasmine_html-reporter .jasmine-failures .jasmine-spec-detail .jasmine-description { background-color: #ca3a11; color: white; }
|
||||
.jasmine_html-reporter .jasmine-failures .jasmine-spec-detail .jasmine-description a { color: white; }
|
||||
.jasmine_html-reporter .jasmine-result-message { padding-top: 14px; color: #333; white-space: pre; }
|
||||
.jasmine_html-reporter .jasmine-result-message span.jasmine-result { display: block; }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2008-2017 Pivotal Labs
|
||||
Copyright (c) 2008-2018 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
@@ -23,9 +23,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
module.exports = function(jasmineRequire) {
|
||||
var jasmine = jasmineRequire.core(jasmineRequire);
|
||||
|
||||
var consoleFns = require('../console/console.js');
|
||||
consoleFns.console(consoleFns, jasmine);
|
||||
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
#
|
||||
module Jasmine
|
||||
module Core
|
||||
VERSION = "2.6.2"
|
||||
VERSION = "3.0.0"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jasmine-core",
|
||||
"license": "MIT",
|
||||
"version": "2.6.2",
|
||||
"version": "3.0.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jasmine/jasmine.git"
|
||||
@@ -19,7 +19,7 @@
|
||||
"homepage": "http://jasmine.github.io",
|
||||
"main": "./lib/jasmine-core.js",
|
||||
"devDependencies": {
|
||||
"glob": "~7.0.5",
|
||||
"glob": "~7.1.2",
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-cli": "^1.2.0",
|
||||
"grunt-contrib-compass": "^1.1.1",
|
||||
|
||||
17
release_notes/2.6.3.md
Normal file
17
release_notes/2.6.3.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Jasmine 2.6.3 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a patch release to fix some regressions and performance problems in the 2.6.0 release
|
||||
|
||||
## Changes
|
||||
|
||||
* Make sure the queue runner goes async for async specs
|
||||
- Fixes [#1327](https://github.com/jasmine/jasmine/issues/1327)
|
||||
- Fixes [#1334](https://github.com/jasmine/jasmine/issues/1334)
|
||||
- Fixes [jasmine/gulp-jasmine-browser#48](https://github.com/jasmine/gulp-jasmine-browser/issues/48)
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
17
release_notes/2.6.4.md
Normal file
17
release_notes/2.6.4.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Jasmine 2.6.4 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a patch release to fix some regressions and performance problems in the 2.6.0 release
|
||||
|
||||
## Changes
|
||||
|
||||
* Break into a `setTimeout` every once in a while allowing the CPU to run other things that used the real `setTimeout`
|
||||
- Fixes [#1327](https://github.com/jasmine/jasmine/issues/1327)
|
||||
- See [#1334](https://github.com/jasmine/jasmine/issues/1334)
|
||||
- Fixes [jasmine/gulp-jasmine-browser#48](https://github.com/jasmine/gulp-jasmine-browser/issues/48)
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
61
release_notes/2.7.0.md
Normal file
61
release_notes/2.7.0.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Jasmine 2.7.0 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release contains a number of fixes and pull requests.
|
||||
|
||||
## Pull Requests & Issues
|
||||
|
||||
|
||||
* Add class UserContext
|
||||
- Merges [#1400](https://github.com/jasmine/jasmine/issues/1400) from @darthjee
|
||||
|
||||
* Send unfocused tests through the same queue as focused tests
|
||||
- Merges [#1399](https://github.com/jasmine/jasmine/issues/1399) from @jberney
|
||||
|
||||
* PrettyPrinter allows an object to have a `toString` that isn't a function
|
||||
- Fixes [#1389](https://github.com/jasmine/jasmine/issues/1389)
|
||||
|
||||
* Fix rounding in toBeCloseTo
|
||||
- Fixes [#1382](https://github.com/jasmine/jasmine/issues/1382)
|
||||
|
||||
* When stop on failure is enabled, skip subsequent it() and beforeEach(). Note: afterEach() functions are still run, because skipping them is highly likely to pollute specs that run after the failure.
|
||||
- Fixes [#577](https://github.com/jasmine/jasmine/issues/577)
|
||||
- Fixes [#807](https://github.com/jasmine/jasmine/issues/807)
|
||||
|
||||
* Only clear out the `spec` param for Run all link
|
||||
- Fixes [#1369](https://github.com/jasmine/jasmine/issues/1369)
|
||||
|
||||
* Pretty printer will now use MAX_PRETTY_PRINT_ARRAY_LENGTH for objects
|
||||
- Fixes [#1291](https://github.com/jasmine/jasmine/issues/1291)
|
||||
- Fixes [#1360](https://github.com/jasmine/jasmine/issues/1360)
|
||||
|
||||
* updated package glob from 7.0.5 to 7.1.2
|
||||
- Merges [#1368](https://github.com/jasmine/jasmine/issues/1368) from @EsrefDurna
|
||||
|
||||
* Fix bower.json url to be https instead of http
|
||||
- Merges [#1365](https://github.com/jasmine/jasmine/issues/1365) from @kant
|
||||
|
||||
* Fail when one of the arguments passed into toBeCloseTo matcher is null
|
||||
- Merges [#1362](https://github.com/jasmine/jasmine/issues/1362) from @beatrichartz
|
||||
|
||||
* Fixed HTML snippet in README
|
||||
- Closes [#1366](https://github.com/jasmine/jasmine/issues/1366).
|
||||
|
||||
* Report the random seed at the beginning and end of execution. This allows reporters to provide the seed to the user even in cases where Jasmine crashes before completing.
|
||||
- Merges [#1348](https://github.com/jasmine/jasmine/issues/1348) from @sgravrock
|
||||
|
||||
* Add ES6 map support to Jasmine
|
||||
- Merges [#1340](https://github.com/jasmine/jasmine/issues/1340) from @rmehlinger
|
||||
- Fixes [#1257](https://github.com/jasmine/jasmine/issues/1257)
|
||||
|
||||
* Added support for async before/it/after functions that return promises and added support for ES2017 async functions
|
||||
- Merges [#1356](https://github.com/jasmine/jasmine/issues/1356) from @sgravrock
|
||||
- Fixes [#1336](https://github.com/jasmine/jasmine/issues/1336)
|
||||
- Fixes [#1270](https://github.com/jasmine/jasmine/issues/1270)
|
||||
- Fixes [#1350](https://github.com/jasmine/jasmine/issues/1350)
|
||||
- Fixes [#1320](https://github.com/jasmine/jasmine/issues/1320)
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
52
release_notes/2.8.0.md
Normal file
52
release_notes/2.8.0.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Jasmine 2.8.0 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release contains a number of fixes and pull requests.
|
||||
2.8 should be the last 2.x release of Jasmine, as we aim for 3.0.
|
||||
|
||||
## Changes
|
||||
|
||||
* Create CODE_OF_CONDUCT.md
|
||||
* Add jsdocs for reporter events
|
||||
* Update jsApiReporter docs to link to new suite and spec results
|
||||
* Add explicit docs for the callback function passed to `it` etc.
|
||||
* Update afterAll documentation
|
||||
|
||||
## Pull Requests & Issues
|
||||
|
||||
* Add 'nothing' matcher and tests
|
||||
- Merges [#1412](https://github.com/jasmine/jasmine/issues/1412) from @ksvitkovsky
|
||||
- Fixes [#1221](https://github.com/jasmine/jasmine/issues/1221)
|
||||
|
||||
|
||||
* Make toEqual matcher report the difference between array elements when arrays have different length
|
||||
- Closes [#1375](https://github.com/jasmine/jasmine/issues/1375) from @kiewic
|
||||
|
||||
|
||||
* Add arrayWithExactContents asymmetric matcher
|
||||
- Fixes [#817](https://github.com/jasmine/jasmine/issues/817)
|
||||
|
||||
|
||||
* Ensure no message added on asym. match success
|
||||
- Closes [#1408](https://github.com/jasmine/jasmine/issues/1408) from @ksvitkovsky
|
||||
- Fixes [#1388](https://github.com/jasmine/jasmine/issues/1388)
|
||||
|
||||
|
||||
* Better primitives detection for saveArgsByValue
|
||||
- Closes [#1407](https://github.com/jasmine/jasmine/issues/1407) from @ksvitkovsky
|
||||
- Fixes [#1403](https://github.com/jasmine/jasmine/issues/1403)
|
||||
|
||||
|
||||
* Better pretty printing for typed arrays
|
||||
- Closes [#1404](https://github.com/jasmine/jasmine/issues/1404) from @ksvitkovsky
|
||||
- Fixes [#1180](https://github.com/jasmine/jasmine/issues/1180)
|
||||
|
||||
|
||||
* Rewrite ES6 Set and Map comparison to ignore insertion order
|
||||
- Merges [#1406](https://github.com/jasmine/jasmine/issues/1406) from @theefer
|
||||
- Fixes [#1402](https://github.com/jasmine/jasmine/issues/1402)
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
99
release_notes/2.9.0.md
Normal file
99
release_notes/2.9.0.md
Normal file
@@ -0,0 +1,99 @@
|
||||
# Jasmine 2.9 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release contains a number of fixes and pull requests.
|
||||
|
||||
## Changes
|
||||
|
||||
* Fixed DelayedFunctionScheduler IE 8 compatibility issue
|
||||
* Fixed SPEC HAS NO EXPECTATIONS warning in HTML reporter
|
||||
* Correctly remove spies of window.onerror on IE
|
||||
* Truncate pretty printer output that is more than j$.MAX_PRETTY_PRINT_CHARS long
|
||||
* Reduced pretty printer limits to much smaller values
|
||||
* Update contributing for new naming of `jasmineUnderTest`
|
||||
* Allowed async functions to be passed into spy#callFake
|
||||
|
||||
## Pull Requests & Issues
|
||||
|
||||
* Added complete support for Set also for IE11.
|
||||
- Merges [#1478](https://github.com/jasmine/jasmine/issues/1478) from @Volox
|
||||
- Fixes [#1355](https://github.com/jasmine/jasmine/issues/1355)
|
||||
|
||||
|
||||
* Added complete support for Map also for IE11.
|
||||
- Merges [#1477](https://github.com/jasmine/jasmine/issues/1477) from @Volox
|
||||
- Fixes [#1472](https://github.com/jasmine/jasmine/issues/1472)
|
||||
|
||||
|
||||
* Use timeout objects when in node
|
||||
- Merges [#1470](https://github.com/jasmine/jasmine/issues/1470) from @chris--young
|
||||
- Fixes [#1469](https://github.com/jasmine/jasmine/issues/1469)
|
||||
|
||||
|
||||
* Fixed `pending()` for `async`/promise-returning specs
|
||||
- Fixes [#1449](https://github.com/jasmine/jasmine/issues/1449)
|
||||
- Fixes [#1450](https://github.com/jasmine/jasmine/issues/1450)
|
||||
|
||||
|
||||
* Added test steps for other major node versions
|
||||
- Merges [#1448](https://github.com/jasmine/jasmine/issues/1448) from @mrlannigan
|
||||
|
||||
|
||||
* Fix equality computation for ES6 Sets.
|
||||
- Merges [#1445](https://github.com/jasmine/jasmine/issues/1445) from @b-3-n
|
||||
- Fixes [#1444](https://github.com/jasmine/jasmine/issues/1444)
|
||||
|
||||
|
||||
* Add instruction to sync local master with upstream
|
||||
- Merges [#1440](https://github.com/jasmine/jasmine/issues/1440) from aaronang
|
||||
|
||||
|
||||
* Add some unit tests that exercise jasmine.anything() and Map matching.
|
||||
- Merges [#1437](https://github.com/jasmine/jasmine/issues/1437) from @voithos
|
||||
|
||||
|
||||
* Add special handling of asymmetric matcher objects as keys in Maps.
|
||||
- Merges [#1436](https://github.com/jasmine/jasmine/issues/1436) from @voithos
|
||||
- Fixes [#1432](https://github.com/jasmine/jasmine/issues/1432)
|
||||
|
||||
|
||||
* Add support for jasmine.any(Symbol).
|
||||
- Merge [#1435](https://github.com/jasmine/jasmine/issues/1435) from @voithos
|
||||
- Fixes [#1431](https://github.com/jasmine/jasmine/issues/1431)
|
||||
|
||||
|
||||
* Throw an error for invalid nesting of a suite functions
|
||||
- Merges [#1411](https://github.com/jasmine/jasmine/issues/1411) from @ksvitkovsky
|
||||
- Fixes [#1295](https://github.com/jasmine/jasmine/issues/1295)
|
||||
|
||||
|
||||
* Deep clone args before passing them to reporters
|
||||
- Merges [#1424](https://github.com/jasmine/jasmine/issues/1424) from @aj-dev
|
||||
|
||||
|
||||
* Fix "Before Committing" section of CONTRIBUTING.md.
|
||||
- Merges [#1429](https://github.com/jasmine/jasmine/issues/1429) from @voithos
|
||||
|
||||
|
||||
* Fix lint warning in CallTracker.
|
||||
- Merges [#1428](https://github.com/jasmine/jasmine/issues/1428) from @voithos
|
||||
|
||||
|
||||
* clearTimeout should now correctly clear a timeout that is also scheduled to run at the same tick.
|
||||
- Merges [#1427](https://github.com/jasmine/jasmine/issues/1427) from @leahciMic
|
||||
- Fixes [#1426](https://github.com/jasmine/jasmine/issues/1426)
|
||||
|
||||
|
||||
* Add a note about `defineProperty` for `spyOnProperty`
|
||||
- Fixes [#1415](https://github.com/jasmine/jasmine/issues/1415)
|
||||
|
||||
|
||||
* Add Promise checking to eq
|
||||
- Merges [#1386](https://github.com/jasmine/jasmine/issues/1386) from @sderickson
|
||||
- Fixes [#1314](https://github.com/jasmine/jasmine/issues/1314)
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
15
release_notes/2.9.1.md
Normal file
15
release_notes/2.9.1.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Jasmine Core 2.9.1 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a hotfix release to fix a breaking change from the 2.9.0 release
|
||||
|
||||
## Changes
|
||||
|
||||
* Clear timeouts when starting to process a milli instead of at the end
|
||||
- Fixes #1482
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
19
release_notes/2.99.md
Normal file
19
release_notes/2.99.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Jasmine-Core 2.99 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release is part of the upgrade path to Jasmine 3.0. It deprecates some functionality that will change.
|
||||
|
||||
## Changes
|
||||
|
||||
* Add ability to report deprecation warnings from within the suite and display them in the HTML reporter
|
||||
* Add deprecation messages for things that will change/break in 3.0
|
||||
* * done for async functionality will now add a failure if it is invoked with an Error
|
||||
* * Env.catchExceptions and the query param are going away, in favor of a more fully functional fail fast handler
|
||||
* * jasmine.Any(Object) will no longer match null
|
||||
* * Unhandled errors during suite load will be caught and reported as failures by Jasmine
|
||||
* * Calling execute more than once on the same spec will definitely fail in 3.0
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
82
release_notes/3.0.md
Normal file
82
release_notes/3.0.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# Jasmine-Core 3.0 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
Jasmine 3.0 is a major release of Jasmine, and as such includes some breaking changes in addition to various new features.
|
||||
|
||||
There is also a 2.99 release of Jasmine that will present deprecation warnings for suites that will encounter different behavior in 3.0.
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
* Replace old "catch exceptions" logic with proper fail fast with error reporting
|
||||
- Fixes [#414](https://github.com/jasmine/jasmine/issues/414)
|
||||
- Fixes [jasmine/jasmine-npm#16](https://github.com/jasmine/jasmine/jasmine-npm/issues/16)
|
||||
|
||||
* Detect an Error passed to `done` and add an expectation failure
|
||||
- Fixes [#567](https://github.com/jasmine/jasmine/issues/567)
|
||||
|
||||
* Unify status for xdescribe and xit
|
||||
- Ensure *All's only execute if at least one child will run
|
||||
- Specs will report a status of `excluded` instead of disabled
|
||||
- Fixes [#1418](https://github.com/jasmine/jasmine/issues/1418)
|
||||
|
||||
* Suite level errors all report the same way (on suiteDone)
|
||||
|
||||
* Refactor QueueRunner and remove references to functions that Jasmine is done with
|
||||
|
||||
* expect(null).toEqual(jasmine.any(Object)) no longer passes
|
||||
- Fixes [#1255](https://github.com/jasmine/jasmine/issues/1255)
|
||||
|
||||
* Default to running tests in random order
|
||||
|
||||
## Changes
|
||||
|
||||
* Remove node modules from python wheel, and update languages
|
||||
|
||||
* Allow reporter callbacks to be asynchronous
|
||||
- Fixes [#842](https://github.com/jasmine/jasmine/issues/842)
|
||||
|
||||
* Allow adding custom spy strategies
|
||||
|
||||
* Add the ability to specify the strategy to use for a spy based on which parameters are passed
|
||||
|
||||
* Added links to re-run the suites containing a failing spec
|
||||
|
||||
* Added a toHaveClass matcher
|
||||
|
||||
* More informative pretty-printing of DOM elements
|
||||
|
||||
* Allow jasmine-npm to handle its own load errors
|
||||
|
||||
* Treat random= as a no-op rather than disabling randomization
|
||||
|
||||
* Use prototype for spy strategy for better memory management
|
||||
|
||||
* Remove console.js altogether
|
||||
|
||||
* Add safari 10 and update readme to include edge
|
||||
|
||||
* Determine overall status in core, not reporters
|
||||
|
||||
* Filter Jasmine frames from stack traces
|
||||
|
||||
* Treat afterAll errors at any level as failures
|
||||
|
||||
* Improved reporting of load errors and afterAll errors
|
||||
- Pass file and line number to reporters when present
|
||||
- Show file and line number in the HTML reporter when present
|
||||
- Visually separate adjacent errors in the HTML reporter
|
||||
|
||||
* Report loading errors as loading errors, not afterAll errors
|
||||
|
||||
* HTML reporter reports overall failure if there are any global errors
|
||||
|
||||
* Fail if error events (e.g. syntax errors) occur during loading
|
||||
|
||||
* Allow use of a predicate function to validate thrown exceptions
|
||||
|
||||
* Check truthiness of toThrowError args, not arg count
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
3
setup.py
3
setup.py
@@ -23,9 +23,6 @@ setup(
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.2',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
describe("ConsoleReporter", function() {
|
||||
var out;
|
||||
|
||||
beforeEach(function() {
|
||||
out = (function() {
|
||||
var output = "";
|
||||
return {
|
||||
print: function(str) {
|
||||
output += str;
|
||||
},
|
||||
getOutput: function() {
|
||||
return output.replace('ConsoleReporter is deprecated and will be removed in a future version.', '');
|
||||
},
|
||||
clear: function() {
|
||||
output = "";
|
||||
}
|
||||
};
|
||||
}());
|
||||
});
|
||||
|
||||
it("reports that the suite has started to the console", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
|
||||
expect(out.getOutput()).toEqual("Started\n");
|
||||
});
|
||||
|
||||
it("starts the provided timer when jasmine starts", function() {
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start']),
|
||||
reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
timer: timerSpy
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
|
||||
expect(timerSpy.start).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports a passing spec as a dot", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.specDone({status: "passed"});
|
||||
|
||||
expect(out.getOutput()).toEqual(".");
|
||||
});
|
||||
|
||||
it("does not report a disabled spec", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.specDone({status: "disabled"});
|
||||
|
||||
expect(out.getOutput()).toEqual("");
|
||||
});
|
||||
|
||||
it("reports a failing spec as an 'F'", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.specDone({status: "failed"});
|
||||
|
||||
expect(out.getOutput()).toEqual("F");
|
||||
});
|
||||
|
||||
it("reports a pending spec as a '*'", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.specDone({status: "pending"});
|
||||
|
||||
expect(out.getOutput()).toEqual("*");
|
||||
});
|
||||
|
||||
it("alerts user if there are no specs", function(){
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
out.clear();
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/No specs found/);
|
||||
});
|
||||
|
||||
it("reports a summary when done (singular spec and time)", function() {
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
timer: timerSpy
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
reporter.specDone({status: "passed"});
|
||||
|
||||
timerSpy.elapsed.and.returnValue(1000);
|
||||
|
||||
out.clear();
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/1 spec, 0 failures/);
|
||||
expect(out.getOutput()).not.toMatch(/0 pending specs/);
|
||||
expect(out.getOutput()).toMatch("Finished in 1 second\n");
|
||||
});
|
||||
|
||||
it("reports a summary when done (pluralized specs and seconds)", function() {
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
timer: timerSpy
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
reporter.specDone({status: "passed"});
|
||||
reporter.specDone({status: "pending"});
|
||||
reporter.specDone({
|
||||
status: "failed",
|
||||
description: "with a failing spec",
|
||||
fullName: "A suite with a failing spec",
|
||||
failedExpectations: [
|
||||
{
|
||||
passed: false,
|
||||
message: "Expected true to be false.",
|
||||
expected: false,
|
||||
actual: true,
|
||||
stack: "foo\nbar\nbaz"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
out.clear();
|
||||
|
||||
timerSpy.elapsed.and.returnValue(100);
|
||||
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/3 specs, 1 failure, 1 pending spec/);
|
||||
expect(out.getOutput()).toMatch("Finished in 0.1 seconds\n");
|
||||
});
|
||||
|
||||
it("reports a summary when done that includes stack traces for a failing suite", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
reporter.specDone({status: "passed"});
|
||||
reporter.specDone({
|
||||
status: "failed",
|
||||
description: "with a failing spec",
|
||||
fullName: "A suite with a failing spec",
|
||||
failedExpectations: [
|
||||
{
|
||||
passed: false,
|
||||
message: "Expected true to be false.",
|
||||
expected: false,
|
||||
actual: true,
|
||||
stack: "foo bar baz"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
out.clear();
|
||||
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/true to be false/);
|
||||
expect(out.getOutput()).toMatch(/foo bar baz/);
|
||||
});
|
||||
|
||||
describe('onComplete callback', function(){
|
||||
var onComplete, reporter;
|
||||
|
||||
beforeEach(function() {
|
||||
onComplete = jasmine.createSpy('onComplete');
|
||||
reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
onComplete: onComplete
|
||||
});
|
||||
reporter.jasmineStarted();
|
||||
});
|
||||
|
||||
it("is called when the suite is done", function() {
|
||||
reporter.jasmineDone();
|
||||
expect(onComplete).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it('calls it with false if there are spec failures', function() {
|
||||
reporter.specDone({status: "failed", failedExpectations: []});
|
||||
reporter.jasmineDone();
|
||||
expect(onComplete).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
it('calls it with false if there are suite failures', function() {
|
||||
reporter.specDone({status: "passed"});
|
||||
reporter.suiteDone({failedExpectations: [{ message: 'bananas' }] });
|
||||
reporter.jasmineDone();
|
||||
expect(onComplete).toHaveBeenCalledWith(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with color", function() {
|
||||
it("reports that the suite has started to the console", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
showColors: true
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
|
||||
expect(out.getOutput()).toEqual("Started\n");
|
||||
});
|
||||
|
||||
it("reports a passing spec as a dot", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
showColors: true
|
||||
});
|
||||
|
||||
reporter.specDone({status: "passed"});
|
||||
|
||||
expect(out.getOutput()).toEqual("\x1B[32m.\x1B[0m");
|
||||
});
|
||||
|
||||
it("does not report a disabled spec", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
showColors: true
|
||||
});
|
||||
|
||||
reporter.specDone({status: 'disabled'});
|
||||
|
||||
expect(out.getOutput()).toEqual("");
|
||||
});
|
||||
|
||||
it("reports a failing spec as an 'F'", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
showColors: true
|
||||
});
|
||||
|
||||
reporter.specDone({status: 'failed'});
|
||||
|
||||
expect(out.getOutput()).toEqual("\x1B[31mF\x1B[0m");
|
||||
});
|
||||
|
||||
it("displays all afterAll exceptions", function() {
|
||||
var reporter = new jasmineUnderTest.ConsoleReporter({
|
||||
print: out.print,
|
||||
showColors: true
|
||||
});
|
||||
|
||||
reporter.suiteDone({ failedExpectations: [{ message: 'After All Exception' }] });
|
||||
reporter.suiteDone({ failedExpectations: [{ message: 'Some Other Exception' }] });
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/After All Exception/);
|
||||
expect(out.getOutput()).toMatch(/Some Other Exception/);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -117,4 +117,14 @@ describe("CallTracker", function() {
|
||||
expect(callTracker.mostRecent().args[1]).not.toBe(arrayArg);
|
||||
expect(callTracker.mostRecent().args[1]).toEqual(arrayArg);
|
||||
});
|
||||
|
||||
it('saves primitive arguments by value', function() {
|
||||
var callTracker = new jasmineUnderTest.CallTracker(),
|
||||
args = [undefined, null, false, '', /\s/, 0, 1.2, NaN];
|
||||
|
||||
callTracker.saveArgumentsByValue();
|
||||
callTracker.track({ object: {}, args: args });
|
||||
|
||||
expect(callTracker.mostRecent().args).toEqual(args);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,6 +21,34 @@ describe("ClearStack", function() {
|
||||
expect(setImmediate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses setTimeout instead of setImmediate every 10 calls to make sure we release the CPU", function() {
|
||||
var setImmediate = jasmine.createSpy('setImmediate'),
|
||||
setTimeout = jasmine.createSpy('setTimeout'),
|
||||
global = { setImmediate: setImmediate, setTimeout: setTimeout },
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
|
||||
expect(setImmediate).toHaveBeenCalled();
|
||||
expect(setTimeout).not.toHaveBeenCalled();
|
||||
|
||||
clearStack(function() { });
|
||||
expect(setImmediate.calls.count()).toEqual(9);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
|
||||
clearStack(function() { });
|
||||
expect(setImmediate.calls.count()).toEqual(10);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("uses MessageChannels when available", function() {
|
||||
var fakeChannel = {
|
||||
port1: {},
|
||||
@@ -37,6 +65,41 @@ describe("ClearStack", function() {
|
||||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
it("uses setTimeout instead of MessageChannel every 10 calls to make sure we release the CPU", function() {
|
||||
var fakeChannel = {
|
||||
port1: {},
|
||||
port2: {
|
||||
postMessage: jasmine.createSpy('postMessage').and.callFake(function() {
|
||||
fakeChannel.port1.onmessage();
|
||||
})
|
||||
}
|
||||
},
|
||||
setTimeout = jasmine.createSpy('setTimeout'),
|
||||
global = { MessageChannel: function() { return fakeChannel; }, setTimeout: setTimeout },
|
||||
clearStack = jasmineUnderTest.getClearStack(global);
|
||||
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
clearStack(function() { });
|
||||
|
||||
expect(fakeChannel.port2.postMessage).toHaveBeenCalled();
|
||||
expect(setTimeout).not.toHaveBeenCalled();
|
||||
|
||||
clearStack(function() { });
|
||||
expect(fakeChannel.port2.postMessage.calls.count()).toEqual(9);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
|
||||
clearStack(function() { });
|
||||
expect(fakeChannel.port2.postMessage.calls.count()).toEqual(10);
|
||||
expect(setTimeout.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("calls setTimeout when onmessage is called recursively", function() {
|
||||
var fakeChannel = {
|
||||
port1: {},
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
describe("Clock", function() {
|
||||
|
||||
var 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"),
|
||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||
@@ -294,13 +296,19 @@ describe("Clock", function() {
|
||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||
delayedFn = jasmine.createSpy('delayedFn'),
|
||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||
timeout = new clock.FakeTimeout();
|
||||
|
||||
clock.install();
|
||||
clock.setTimeout(delayedFn, 0, 'a', 'b');
|
||||
|
||||
expect(fakeSetTimeout).not.toHaveBeenCalled();
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b']);
|
||||
|
||||
if (!NODE_JS) {
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b']);
|
||||
} else {
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], false, timeout);
|
||||
}
|
||||
});
|
||||
|
||||
it("returns an id for the delayed function", function() {
|
||||
@@ -312,12 +320,16 @@ describe("Clock", function() {
|
||||
delayedFn = jasmine.createSpy('delayedFn'),
|
||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||
timeoutId;
|
||||
timeout;
|
||||
|
||||
clock.install();
|
||||
timeoutId = clock.setTimeout(delayedFn, 0);
|
||||
timeout = clock.setTimeout(delayedFn, 0);
|
||||
|
||||
expect(timeoutId).toEqual(123);
|
||||
if (!NODE_JS) {
|
||||
expect(timeout).toEqual(123);
|
||||
} else {
|
||||
expect(timeout.constructor.name).toEqual('FakeTimeout');
|
||||
}
|
||||
});
|
||||
|
||||
it("clears the scheduled function with the scheduler", function() {
|
||||
@@ -342,13 +354,19 @@ describe("Clock", function() {
|
||||
fakeGlobal = { setInterval: fakeSetInterval },
|
||||
delayedFn = jasmine.createSpy('delayedFn'),
|
||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||
timeout = new clock.FakeTimeout;
|
||||
|
||||
clock.install();
|
||||
clock.setInterval(delayedFn, 0, 'a', 'b');
|
||||
|
||||
expect(fakeSetInterval).not.toHaveBeenCalled();
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], true);
|
||||
|
||||
if (!NODE_JS) {
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], true);
|
||||
} else {
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], true, timeout);
|
||||
}
|
||||
});
|
||||
|
||||
it("returns an id for the delayed function", function() {
|
||||
@@ -360,12 +378,16 @@ describe("Clock", function() {
|
||||
delayedFn = jasmine.createSpy('delayedFn'),
|
||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||
intervalId;
|
||||
interval;
|
||||
|
||||
clock.install();
|
||||
intervalId = clock.setInterval(delayedFn, 0);
|
||||
interval = clock.setInterval(delayedFn, 0);
|
||||
|
||||
expect(intervalId).toEqual(123);
|
||||
if (!NODE_JS) {
|
||||
expect(interval).toEqual(123);
|
||||
} else {
|
||||
expect(interval.constructor.name).toEqual('FakeTimeout');
|
||||
}
|
||||
});
|
||||
|
||||
it("clears the scheduled function with the scheduler", function() {
|
||||
@@ -389,37 +411,6 @@ describe("Clock", function() {
|
||||
clock.tick(50);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it("on IE < 9, fails if extra args are passed to fake clock", function() {
|
||||
//fail, because this would break in IE9.
|
||||
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||
fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||
delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
|
||||
fn = jasmine.createSpy('fn'),
|
||||
fakeGlobal = {
|
||||
setTimeout: fakeSetTimeout,
|
||||
setInterval: fakeSetInterval
|
||||
},
|
||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||
|
||||
fakeSetTimeout.apply = null;
|
||||
fakeSetInterval.apply = null;
|
||||
|
||||
clock.install();
|
||||
|
||||
clock.setTimeout(fn, 0);
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(fn, 0, []);
|
||||
expect(function() {
|
||||
clock.setTimeout(fn, 0, 'extra');
|
||||
}).toThrow();
|
||||
|
||||
clock.setInterval(fn, 0);
|
||||
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(fn, 0, [], true);
|
||||
expect(function() {
|
||||
clock.setInterval(fn, 0, 'extra');
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Clock (acceptance)", function() {
|
||||
@@ -679,4 +670,41 @@ describe("Clock (acceptance)", function() {
|
||||
|
||||
expect(actualTimes).toEqual([baseTime.getTime(), baseTime.getTime() + 1, baseTime.getTime() + 3]);
|
||||
})
|
||||
|
||||
it('correctly clears a scheduled timeout while the Clock is advancing', function () {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = {Date: Date, setTimeout: undefined},
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(global, function () { return delayedFunctionScheduler; }, mockDate);
|
||||
|
||||
clock.install();
|
||||
|
||||
var timerId2;
|
||||
|
||||
global.setTimeout(function () {
|
||||
global.clearTimeout(timerId2);
|
||||
}, 100);
|
||||
|
||||
timerId2 = global.setTimeout(fail, 100);
|
||||
|
||||
clock.tick(100);
|
||||
});
|
||||
|
||||
it('correctly clears a scheduled interval while the Clock is advancing', function () {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = {Date: Date, setTimeout: undefined},
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(global, function () { return delayedFunctionScheduler; }, mockDate);
|
||||
|
||||
clock.install();
|
||||
|
||||
var timerId2;
|
||||
var timerId1 = global.setInterval(function () {
|
||||
global.clearInterval(timerId2);
|
||||
}, 100);
|
||||
|
||||
timerId2 = global.setInterval(fail, 100);
|
||||
|
||||
clock.tick(400);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -216,21 +216,23 @@ describe("DelayedFunctionScheduler", function() {
|
||||
|
||||
it("removes functions during a tick that runs the function", function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn'),
|
||||
spy = jasmine.createSpy('fn'),
|
||||
spyAndRemove = jasmine.createSpy('fn'),
|
||||
fnDelay = 10,
|
||||
timeoutKey;
|
||||
|
||||
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
|
||||
scheduler.scheduleFunction(function () {
|
||||
spyAndRemove.and.callFake(function() {
|
||||
scheduler.removeFunctionWithId(timeoutKey);
|
||||
}, 2 * fnDelay);
|
||||
});
|
||||
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
scheduler.scheduleFunction(spyAndRemove, fnDelay);
|
||||
|
||||
scheduler.tick(3 * fnDelay);
|
||||
timeoutKey = scheduler.scheduleFunction(spy, fnDelay, [], true);
|
||||
|
||||
expect(fn).toHaveBeenCalled();
|
||||
expect(fn.calls.count()).toBe(2);
|
||||
scheduler.tick(2 * fnDelay);
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
expect(spyAndRemove).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("removes functions during the first tick that runs the function", function() {
|
||||
@@ -252,6 +254,22 @@ describe("DelayedFunctionScheduler", function() {
|
||||
expect(fn.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it("does not remove a function that hasn't been added yet", function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn'),
|
||||
fnDelay = 10,
|
||||
timeoutKey;
|
||||
|
||||
scheduler.removeFunctionWithId('foo');
|
||||
scheduler.scheduleFunction(fn, fnDelay, [], false, 'foo');
|
||||
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
|
||||
scheduler.tick(fnDelay + 1);
|
||||
|
||||
expect(fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("updates the mockDate per scheduled time", function () {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
tickDate = jasmine.createSpy('tickDate');
|
||||
|
||||
@@ -91,6 +91,13 @@ describe("Env", function() {
|
||||
env.it('pending spec');
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.it('async', jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#xit', function() {
|
||||
@@ -114,6 +121,13 @@ describe("Env", function() {
|
||||
env.xit('pending spec');
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.xit('async', jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fit', function () {
|
||||
@@ -130,6 +144,13 @@ describe("Env", function() {
|
||||
env.beforeEach(undefined);
|
||||
}).toThrowError(/beforeEach expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.beforeEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#beforeAll', function () {
|
||||
@@ -138,6 +159,13 @@ describe("Env", function() {
|
||||
env.beforeAll(undefined);
|
||||
}).toThrowError(/beforeAll expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.beforeAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterEach', function () {
|
||||
@@ -146,6 +174,13 @@ describe("Env", function() {
|
||||
env.afterEach(undefined);
|
||||
}).toThrowError(/afterEach expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.afterEach(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#afterAll', function () {
|
||||
@@ -154,5 +189,12 @@ describe("Env", function() {
|
||||
env.afterAll(undefined);
|
||||
}).toThrowError(/afterAll expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
|
||||
});
|
||||
|
||||
it('accepts an async function', function() {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
expect(function() {
|
||||
env.afterAll(jasmine.getEnv().makeAsyncAwaitFunction());
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,15 +47,72 @@ describe("ExceptionFormatter", function() {
|
||||
});
|
||||
|
||||
describe("#stack", function() {
|
||||
it("formats stack traces from Webkit, Firefox, node.js or IE10+", function() {
|
||||
if (jasmine.getEnv().ieVersion < 10 || jasmine.getEnv().safariVersion < 6) { return; }
|
||||
|
||||
it("formats stack traces", function() {
|
||||
var error;
|
||||
try { throw new Error("an error") } catch(e) { error = e; }
|
||||
|
||||
expect(new jasmineUnderTest.ExceptionFormatter().stack(error)).toMatch(/ExceptionFormatterSpec\.js.*\d+/)
|
||||
});
|
||||
|
||||
it("filters Jasmine stack frames from V8 style traces", function() {
|
||||
var error = {
|
||||
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'
|
||||
};
|
||||
var subject = new jasmineUnderTest.ExceptionFormatter({
|
||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
expect(result).toEqual('Error: nope\n' +
|
||||
' 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("filters Jamine stack frames from Webkit style traces", function() {
|
||||
var 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({
|
||||
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
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("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({
|
||||
jasmineFile: jasmine.util.jasmineFile()
|
||||
});
|
||||
var result = subject.stack(error);
|
||||
var lines = result.split('\n');
|
||||
|
||||
if (lines[0].match(/an error/)) {
|
||||
lines.shift();
|
||||
}
|
||||
|
||||
expect(lines[0]).toMatch(/ExceptionFormatterSpec.js/);
|
||||
expect(lines[1]).toMatch(/<Jasmine>/);
|
||||
|
||||
// Node has some number of additional frames below Jasmine.
|
||||
for (i = 2; i < lines.length; i++) {
|
||||
expect(lines[i]).not.toMatch(/jasmine.js/);
|
||||
}
|
||||
});
|
||||
|
||||
it("returns null if no Error provided", function() {
|
||||
expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull();
|
||||
});
|
||||
|
||||
@@ -5,64 +5,42 @@ describe('Exceptions:', function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
describe('with break on exception', function() {
|
||||
it('should not catch the exception', function() {
|
||||
env.catchExceptions(false);
|
||||
env.describe('suite for break on exceptions', function() {
|
||||
env.it('should break when an exception is thrown', function() {
|
||||
throw new Error('I should hit a breakpoint!');
|
||||
});
|
||||
it('should handle exceptions thrown, but continue', function(done) {
|
||||
var 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', function() {
|
||||
throw new Error();
|
||||
});
|
||||
var spy = jasmine.createSpy('spy');
|
||||
|
||||
try {
|
||||
env.execute();
|
||||
spy();
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
env.it('should be a passing test that runs after exceptions are thrown from a async test', secondTest);
|
||||
});
|
||||
|
||||
var expectations = function() {
|
||||
expect(secondTest).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
});
|
||||
|
||||
describe("with catch on exception", function() {
|
||||
it('should handle exceptions thrown, but continue', function(done) {
|
||||
var 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', function() {
|
||||
throw new Error();
|
||||
});
|
||||
env.it('should be a passing test that runs after exceptions are thrown from a async test', secondTest);
|
||||
it("should handle exceptions thrown directly in top-level describe blocks and continue", function(done) {
|
||||
var secondDescribe = jasmine.createSpy("second describe");
|
||||
env.describe("a suite that throws an exception", function () {
|
||||
env.it("is a test that should pass", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
var expectations = function() {
|
||||
expect(secondTest).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
throw new Error("top level error");
|
||||
});
|
||||
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
||||
|
||||
it("should handle exceptions thrown directly in top-level describe blocks and continue", function(done) {
|
||||
var secondDescribe = jasmine.createSpy("second describe");
|
||||
env.describe("a suite that throws an exception", function () {
|
||||
env.it("is a test that should pass", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
var expectations = function() {
|
||||
expect(secondDescribe).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
throw new Error("top level error");
|
||||
});
|
||||
env.describe("a suite that doesn't throw an exception", secondDescribe);
|
||||
|
||||
var expectations = function() {
|
||||
expect(secondDescribe).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
});
|
||||
env.addReporter({ jasmineDone: expectations });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ describe("JsApiReporter", function() {
|
||||
};
|
||||
suiteResult2 = {
|
||||
id: 2,
|
||||
status: 'finished'
|
||||
status: 'passed'
|
||||
};
|
||||
|
||||
reporter.suiteStarted(suiteStarted1);
|
||||
|
||||
@@ -17,7 +17,10 @@ describe("jasmineUnderTest.pp", function () {
|
||||
describe('stringify sets', function() {
|
||||
it("should stringify sets properly", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
expect(jasmineUnderTest.pp(new Set([1, 2]))).toEqual("Set( 1, 2 )");
|
||||
var set = new Set();
|
||||
set.add(1);
|
||||
set.add(2);
|
||||
expect(jasmineUnderTest.pp(set)).toEqual("Set( 1, 2 )");
|
||||
});
|
||||
|
||||
it("should truncate sets with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
|
||||
@@ -26,13 +29,43 @@ describe("jasmineUnderTest.pp", function () {
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(new Set(["a", "b", "c"]))).toEqual("Set( 'a', 'b', ... )");
|
||||
var set = new Set();
|
||||
set.add('a');
|
||||
set.add('b');
|
||||
set.add('c');
|
||||
expect(jasmineUnderTest.pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
describe('stringify maps', function() {
|
||||
it("should stringify maps properly", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var map = new Map();
|
||||
map.set(1,2);
|
||||
expect(jasmineUnderTest.pp(map)).toEqual("Map( [ 1, 2 ] )");
|
||||
});
|
||||
|
||||
it("should truncate maps with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
var map = new Map();
|
||||
map.set("a",1);
|
||||
map.set("b",2);
|
||||
map.set("c",3);
|
||||
expect(jasmineUnderTest.pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
describe('stringify arrays', function() {
|
||||
it("should stringify arrays properly", function() {
|
||||
expect(jasmineUnderTest.pp([1, 2])).toEqual("[ 1, 2 ]");
|
||||
@@ -99,6 +132,53 @@ describe("jasmineUnderTest.pp", function () {
|
||||
}, bar: [1, 2, 3]})).toEqual("Object({ foo: Function, bar: [ 1, 2, 3 ] })");
|
||||
});
|
||||
|
||||
it("should truncate objects with too many keys", function () {
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = {a: 1, b: 2, c: 3};
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(long)).toEqual("Object({ a: 1, b: 2, ... })");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||
}
|
||||
});
|
||||
|
||||
function withMaxChars(maxChars, fn) {
|
||||
var originalMaxChars = jasmineUnderTest.MAX_PRETTY_PRINT_CHARS;
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_CHARS = maxChars;
|
||||
fn();
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_CHARS = originalMaxChars;
|
||||
}
|
||||
}
|
||||
|
||||
it("should truncate outputs that are too long", function() {
|
||||
var big = [
|
||||
{ a: 1, b: "a long string" },
|
||||
{}
|
||||
];
|
||||
|
||||
withMaxChars(34, function() {
|
||||
expect(jasmineUnderTest.pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
||||
});
|
||||
});
|
||||
|
||||
it("should not serialize more objects after hitting MAX_PRETTY_PRINT_CHARS", function() {
|
||||
var a = { jasmineToString: function() { return 'object a'; } },
|
||||
b = { jasmineToString: function() { return 'object b'; } },
|
||||
c = { jasmineToString: jasmine.createSpy('c jasmineToString').and.returnValue('') },
|
||||
d = { jasmineToString: jasmine.createSpy('d jasmineToString').and.returnValue('') };
|
||||
|
||||
withMaxChars(30, function() {
|
||||
jasmineUnderTest.pp([{a: a, b: b, c: c}, d]);
|
||||
expect(c.jasmineToString).not.toHaveBeenCalled();
|
||||
expect(d.jasmineToString).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
||||
expect(jasmineUnderTest.pp({constructor: function() {}})).toContain("null({");
|
||||
expect(jasmineUnderTest.pp({constructor: 'foo'})).toContain("null({");
|
||||
@@ -184,16 +264,21 @@ describe("jasmineUnderTest.pp", function () {
|
||||
|
||||
it("should stringify spy objects properly", function() {
|
||||
var TestObject = {
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env();
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env();
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() {return [];}});
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {return [];},
|
||||
createSpy: function(name, originalFn) {
|
||||
return jasmineUnderTest.Spy(name, originalFn);
|
||||
}
|
||||
});
|
||||
|
||||
spyRegistry.spyOn(TestObject, 'someFunction');
|
||||
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual("spy on someFunction");
|
||||
|
||||
expect(jasmineUnderTest.pp(jasmineUnderTest.createSpy("something"))).toEqual("spy on something");
|
||||
expect(jasmineUnderTest.pp(env.createSpy("something"))).toEqual("spy on something");
|
||||
});
|
||||
|
||||
it("should stringify objects that implement jasmineToString", function () {
|
||||
@@ -218,11 +303,15 @@ describe("jasmineUnderTest.pp", function () {
|
||||
toString: function () { return Object.prototype.toString.call(this); }
|
||||
};
|
||||
|
||||
if (jasmine.getEnv().ieVersion < 9) {
|
||||
expect(jasmineUnderTest.pp(objFromOtherContext)).toEqual("Object({ foo: 'bar' })");
|
||||
} else {
|
||||
expect(jasmineUnderTest.pp(objFromOtherContext)).toEqual("Object({ foo: 'bar', toString: Function })");
|
||||
}
|
||||
expect(jasmineUnderTest.pp(objFromOtherContext)).toEqual("Object({ foo: 'bar', toString: Function })");
|
||||
});
|
||||
|
||||
it("should stringify objects have have a toString that isn't a function", function() {
|
||||
var obj = {
|
||||
toString: "foo"
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.pp(obj)).toEqual("Object({ toString: 'foo' })");
|
||||
});
|
||||
|
||||
it("should stringify objects from anonymous constructors with custom toString", function () {
|
||||
@@ -235,8 +324,6 @@ describe("jasmineUnderTest.pp", function () {
|
||||
});
|
||||
|
||||
it("should handle objects with null prototype", function() {
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var obj = Object.create(null);
|
||||
obj.foo = 'bar';
|
||||
|
||||
|
||||
@@ -19,6 +19,26 @@ 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') },
|
||||
@@ -31,7 +51,7 @@ describe("QueueRunner", function() {
|
||||
queueRunner.execute();
|
||||
|
||||
var context = queueableFn1.fn.calls.first().object;
|
||||
expect(context).toEqual({});
|
||||
expect(context).toEqual(new jasmineUnderTest.UserContext());
|
||||
expect(queueableFn2.fn.calls.first().object).toBe(context);
|
||||
expect(asyncContext).toBe(context);
|
||||
});
|
||||
@@ -115,6 +135,52 @@ 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
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
expect(queueableFn2.fn).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(failFn).toHaveBeenCalledWith(err);
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not cause an explicit fail if execution is being stopped", function() {
|
||||
var err = new jasmineUnderTest.StopExecutionError('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
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
expect(queueableFn2.fn).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
|
||||
var timeout = 3,
|
||||
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
|
||||
@@ -189,6 +255,7 @@ describe("QueueRunner", function() {
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
jasmine.clock().tick(1);
|
||||
expect(onComplete).toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL);
|
||||
@@ -197,12 +264,13 @@ describe("QueueRunner", function() {
|
||||
|
||||
it("only moves to the next spec the first time you call done", function() {
|
||||
var queueableFn = { fn: function(done) {done(); done();} },
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn]
|
||||
});
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn]
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick(1);
|
||||
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
@@ -211,10 +279,10 @@ describe("QueueRunner", function() {
|
||||
setTimeout(done, 1);
|
||||
throw new Error('error!');
|
||||
} },
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn]
|
||||
});
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFn') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn]
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick(1);
|
||||
@@ -271,6 +339,114 @@ describe("QueueRunner", function() {
|
||||
expect(onException).toHaveBeenCalledWith(errorWithMessage(/^foo$/));
|
||||
expect(nextQueueableFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("handles exceptions thrown while waiting for the stack to clear", function() {
|
||||
var queueableFn = { fn: function(done) { done() } },
|
||||
global = {},
|
||||
errorListeners = [],
|
||||
globalErrors = {
|
||||
pushListener: function(f) { errorListeners.push(f); },
|
||||
popListener: function() { errorListeners.pop(); }
|
||||
},
|
||||
clearStack = jasmine.createSpy('clearStack'),
|
||||
onException = jasmine.createSpy('onException'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
globalErrors: globalErrors,
|
||||
clearStack: clearStack,
|
||||
onException: onException
|
||||
}),
|
||||
error = new Error('nope');
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick();
|
||||
expect(clearStack).toHaveBeenCalled();
|
||||
expect(errorListeners.length).toEqual(1);
|
||||
errorListeners[0](error);
|
||||
clearStack.calls.argsFor(0)[0]();
|
||||
expect(onException).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with a function that returns a promise", function() {
|
||||
function StubPromise() {}
|
||||
|
||||
StubPromise.prototype.then = function(resolve, reject) {
|
||||
this.resolveHandler = resolve;
|
||||
this.rejectHandler = reject;
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.clock().install();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it("runs the function asynchronously, advancing once the promise is settled", function() {
|
||||
var onComplete = jasmine.createSpy('onComplete'),
|
||||
fnCallback = jasmine.createSpy('fnCallback'),
|
||||
p1 = new StubPromise(),
|
||||
p2 = new StubPromise(),
|
||||
queueableFn1 = { fn: function() {
|
||||
setTimeout(function() {
|
||||
p1.resolveHandler();
|
||||
}, 100);
|
||||
return p1;
|
||||
} };
|
||||
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();
|
||||
expect(onComplete).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(fnCallback).toHaveBeenCalled();
|
||||
expect(onComplete).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(onComplete).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("handles a rejected promise like an unhandled exception", function() {
|
||||
var promise = new StubPromise(),
|
||||
queueableFn1 = { fn: function() {
|
||||
setTimeout(function() {
|
||||
promise.rejectHandler('foo')
|
||||
}, 100);
|
||||
return promise;
|
||||
} },
|
||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||
failFn = jasmine.createSpy('fail'),
|
||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1, queueableFn2],
|
||||
onException: onExceptionCallback
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(onExceptionCallback).not.toHaveBeenCalled();
|
||||
expect(queueableFn2.fn).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(onExceptionCallback).toHaveBeenCalledWith('foo');
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("calls exception handlers when an exception is thrown in a fn", function() {
|
||||
@@ -289,20 +465,6 @@ describe("QueueRunner", function() {
|
||||
expect(onExceptionCallback).toHaveBeenCalledWith(jasmine.any(Error));
|
||||
});
|
||||
|
||||
it("rethrows an exception if told to", function() {
|
||||
var queueableFn = { fn: function() {
|
||||
throw new Error('fake error');
|
||||
} },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
catchException: function(e) { return false; }
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
queueRunner.execute();
|
||||
}).toThrowError('fake error');
|
||||
});
|
||||
|
||||
it("continues running the functions even after an exception is thrown in an async spec", function() {
|
||||
var queueableFn = { fn: function(done) { throw new Error("error"); } },
|
||||
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
|
||||
@@ -314,30 +476,103 @@ describe("QueueRunner", function() {
|
||||
expect(nextQueueableFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("handles exceptions thrown while waiting for the stack to clear", function() {
|
||||
var queueableFn = { fn: function(done) { done() } },
|
||||
global = {},
|
||||
errorListeners = [],
|
||||
globalErrors = {
|
||||
pushListener: function(f) { errorListeners.push(f); },
|
||||
popListener: function() { errorListeners.pop(); }
|
||||
},
|
||||
clearStack = jasmine.createSpy('clearStack'),
|
||||
onException = jasmine.createSpy('onException'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
globalErrors: globalErrors,
|
||||
clearStack: clearStack,
|
||||
onException: onException
|
||||
}),
|
||||
error = new Error('nope');
|
||||
describe("When configured to complete on first error", function() {
|
||||
it("skips to cleanup functions on the first exception", function() {
|
||||
var queueableFn = { fn: function() { throw new Error("error"); } },
|
||||
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
|
||||
cleanupFn = { fn: jasmine.createSpy("cleanup") },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
expect(clearStack).toHaveBeenCalled();
|
||||
expect(errorListeners.length).toEqual(1);
|
||||
errorListeners[0](error);
|
||||
clearStack.calls.argsFor(0)[0]();
|
||||
expect(onException).toHaveBeenCalledWith(error);
|
||||
queueRunner.execute();
|
||||
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
|
||||
expect(cleanupFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not skip when a cleanup function throws", function() {
|
||||
var queueableFn = { fn: function() { } },
|
||||
cleanupFn1 = { fn: function() { throw new Error("error"); } },
|
||||
cleanupFn2 = { fn: jasmine.createSpy("cleanupFn2") },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn],
|
||||
cleanupFns: [cleanupFn1, cleanupFn2],
|
||||
completeOnFirstError: true
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
expect(cleanupFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("with an asynchronous function", function() {
|
||||
beforeEach(function() {
|
||||
jasmine.clock().install();
|
||||
});
|
||||
|
||||
afterEach(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(); },
|
||||
},
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true,
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
errorListeners[errorListeners.length - 1](new Error('error'));
|
||||
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
|
||||
expect(cleanupFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("skips to cleanup functions when next.fail is called", function() {
|
||||
var queueableFn = { fn: function(done) {
|
||||
done.fail('nope');
|
||||
} },
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true,
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick();
|
||||
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
|
||||
expect(cleanupFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("skips to cleanup functions when next is called with an Error", function() {
|
||||
var queueableFn = { fn: function(done) {
|
||||
done(new Error('nope'));
|
||||
} },
|
||||
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
|
||||
cleanupFn = { fn: jasmine.createSpy('cleanup') },
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn, nextQueueableFn],
|
||||
cleanupFns: [cleanupFn],
|
||||
completeOnFirstError: true,
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick();
|
||||
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
|
||||
expect(cleanupFn.fn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("calls a provided complete callback when done", function() {
|
||||
@@ -353,23 +588,83 @@ describe("QueueRunner", function() {
|
||||
expect(completeCallback).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls a provided stack clearing function when done", function() {
|
||||
var asyncFn = { fn: function(done) { done() } },
|
||||
afterFn = { fn: jasmine.createSpy('afterFn') },
|
||||
completeCallback = jasmine.createSpy('completeCallback'),
|
||||
clearStack = jasmine.createSpy('clearStack'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [asyncFn, afterFn],
|
||||
clearStack: clearStack,
|
||||
onComplete: completeCallback
|
||||
});
|
||||
describe("clearing the stack", function() {
|
||||
beforeEach(function() {
|
||||
jasmine.clock().install();
|
||||
});
|
||||
|
||||
clearStack.and.callFake(function(fn) { fn(); });
|
||||
afterEach(function() {
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
expect(afterFn.fn).toHaveBeenCalled();
|
||||
expect(clearStack).toHaveBeenCalled();
|
||||
clearStack.calls.argsFor(0)[0]();
|
||||
expect(completeCallback).toHaveBeenCalled();
|
||||
it("calls a provided stack clearing function when done", function() {
|
||||
var asyncFn = { fn: function(done) { done() } },
|
||||
afterFn = { fn: jasmine.createSpy('afterFn') },
|
||||
completeCallback = jasmine.createSpy('completeCallback'),
|
||||
clearStack = jasmine.createSpy('clearStack'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [asyncFn, afterFn],
|
||||
clearStack: clearStack,
|
||||
onComplete: completeCallback
|
||||
});
|
||||
|
||||
clearStack.and.callFake(function(fn) { fn(); });
|
||||
|
||||
queueRunner.execute();
|
||||
jasmine.clock().tick();
|
||||
expect(afterFn.fn).toHaveBeenCalled();
|
||||
expect(clearStack).toHaveBeenCalled();
|
||||
clearStack.calls.argsFor(0)[0]();
|
||||
expect(completeCallback).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when user context has not been defined', function() {
|
||||
beforeEach(function() {
|
||||
var fn;
|
||||
|
||||
this.fn = fn = jasmine.createSpy('fn1');
|
||||
this.queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [{ fn: fn }]
|
||||
});
|
||||
});
|
||||
|
||||
it('runs the functions on the scope of a UserContext', function() {
|
||||
var calls = [],
|
||||
context;
|
||||
|
||||
this.fn.and.callFake(function() {
|
||||
context = this;
|
||||
});
|
||||
|
||||
this.queueRunner.execute();
|
||||
|
||||
expect(context.constructor).toBe(jasmineUnderTest.UserContext);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when user context has been defined', function() {
|
||||
beforeEach(function() {
|
||||
var fn, context;
|
||||
|
||||
this.fn = fn = jasmine.createSpy('fn1');
|
||||
this.context = context = new jasmineUnderTest.UserContext();
|
||||
this.queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [{ fn: fn }],
|
||||
userContext: context
|
||||
});
|
||||
});
|
||||
|
||||
it('runs the functions on the scope of a UserContext', function() {
|
||||
var calls = [],
|
||||
context;
|
||||
this.fn.and.callFake(function() {
|
||||
context = this;
|
||||
});
|
||||
|
||||
this.queueRunner.execute();
|
||||
|
||||
expect(context).toBe(this.context);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,70 +9,131 @@ describe("ReportDispatcher", function() {
|
||||
});
|
||||
|
||||
it("dispatches requested methods to added reporters", function() {
|
||||
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
|
||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar'], queueRunnerFactory),
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
|
||||
anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
|
||||
dispatcher.addReporter(reporter);
|
||||
dispatcher.addReporter(anotherReporter);
|
||||
|
||||
dispatcher.foo(123, 456);
|
||||
dispatcher.foo(123, 456, completeCallback);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
queueableFns: [{fn: jasmine.any(Function)}, {fn: jasmine.any(Function)}],
|
||||
isReporter: true
|
||||
}));
|
||||
|
||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
||||
expect(reporter.foo.calls.mostRecent().object).toBe(reporter);
|
||||
|
||||
fns[1].fn();
|
||||
expect(anotherReporter.foo).toHaveBeenCalledWith(123, 456);
|
||||
expect(anotherReporter.foo.calls.mostRecent().object).toBe(anotherReporter);
|
||||
|
||||
dispatcher.bar('a', 'b');
|
||||
queueRunnerFactory.calls.reset();
|
||||
|
||||
dispatcher.bar('a', 'b', completeCallback);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
queueableFns: [{fn: jasmine.any(Function)}, {fn: jasmine.any(Function)}],
|
||||
isReporter: true
|
||||
}));
|
||||
|
||||
fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter.bar).toHaveBeenCalledWith('a', 'b');
|
||||
|
||||
fns[1].fn();
|
||||
expect(anotherReporter.bar).toHaveBeenCalledWith('a', 'b');
|
||||
});
|
||||
|
||||
it("does not dispatch to a reporter if the reporter doesn't accept the method", function() {
|
||||
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo']),
|
||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
dispatcher = new jasmineUnderTest.ReportDispatcher(['foo'], queueRunnerFactory),
|
||||
reporter = jasmine.createSpyObj('reporter', ['baz']);
|
||||
|
||||
dispatcher.addReporter(reporter);
|
||||
|
||||
expect(function() {
|
||||
dispatcher.foo(123, 456);
|
||||
}).not.toThrow();
|
||||
dispatcher.foo(123, 456);
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
queueableFns: []
|
||||
}));
|
||||
});
|
||||
|
||||
it("allows providing a fallback reporter in case there's no other report", function() {
|
||||
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
|
||||
it("allows providing a fallback reporter in case there's no other reporter", function() {
|
||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar'], queueRunnerFactory),
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
|
||||
dispatcher.provideFallbackReporter(reporter);
|
||||
dispatcher.foo(123, 456);
|
||||
dispatcher.foo(123, 456, completeCallback);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
queueableFns: [{fn: jasmine.any(Function)}],
|
||||
isReporter: true
|
||||
}));
|
||||
|
||||
var 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 report is provided", function() {
|
||||
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
|
||||
it("does not call fallback reporting methods when another reporter is provided", function() {
|
||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar'], queueRunnerFactory),
|
||||
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
|
||||
fallbackReporter = jasmine.createSpyObj('otherReporter', ['foo', 'bar']);
|
||||
fallbackReporter = jasmine.createSpyObj('otherReporter', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
|
||||
dispatcher.provideFallbackReporter(fallbackReporter);
|
||||
dispatcher.addReporter(reporter);
|
||||
dispatcher.foo(123, 456);
|
||||
dispatcher.foo(123, 456, completeCallback);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
queueableFns: [{fn: jasmine.any(Function)}],
|
||||
isReporter: true
|
||||
}));
|
||||
|
||||
var 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 dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
|
||||
var queueRunnerFactory = jasmine.createSpy('queueRunner'),
|
||||
dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar'], queueRunnerFactory),
|
||||
reporter1 = jasmine.createSpyObj('reporter1', ['foo', 'bar']),
|
||||
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']);
|
||||
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']),
|
||||
completeCallback = jasmine.createSpy('complete');
|
||||
|
||||
dispatcher.addReporter(reporter1);
|
||||
dispatcher.foo(123);
|
||||
dispatcher.foo(123, completeCallback);
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
queueableFns: [{fn: jasmine.any(Function)}],
|
||||
isReporter: true
|
||||
}));
|
||||
|
||||
var fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter1.foo).toHaveBeenCalledWith(123);
|
||||
|
||||
dispatcher.clearReporters();
|
||||
dispatcher.addReporter(reporter2);
|
||||
dispatcher.bar(456);
|
||||
dispatcher.bar(456, completeCallback);
|
||||
|
||||
expect(queueRunnerFactory).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
queueableFns: [{fn: jasmine.any(Function)}],
|
||||
isReporter: true
|
||||
}));
|
||||
|
||||
fns = queueRunnerFactory.calls.mostRecent().args[0].queueableFns;
|
||||
fns[0].fn();
|
||||
expect(reporter1.bar).not.toHaveBeenCalled();
|
||||
expect(reporter2.bar).toHaveBeenCalledWith(456);
|
||||
});
|
||||
|
||||
@@ -55,6 +55,7 @@ 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.
|
||||
|
||||
@@ -82,6 +83,7 @@ describe("Spec", function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -103,8 +105,26 @@ describe("Spec", function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(allSpecFns).toEqual([before, queueableFn, after]);
|
||||
var options = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
expect(options.queueableFns).toEqual([{fn: jasmine.any(Function)}, before, queueableFn]);
|
||||
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'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
beforeAndAfterFns: function() {
|
||||
return {befores: [], afters: []}
|
||||
},
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(fakeQueueRunner).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
isLeaf: true
|
||||
}));
|
||||
});
|
||||
|
||||
it("is marked pending if created without a function body", function() {
|
||||
@@ -122,7 +142,7 @@ describe("Spec", function() {
|
||||
expect(spec.status()).toBe('pending');
|
||||
});
|
||||
|
||||
it("can be disabled, but still calls callbacks", function() {
|
||||
it("can be excluded at execution time by a parent", function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
startCallback = jasmine.createSpy('startCallback'),
|
||||
specBody = jasmine.createSpy('specBody'),
|
||||
@@ -134,40 +154,22 @@ describe("Spec", function() {
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
});
|
||||
|
||||
spec.disable();
|
||||
spec.execute('cally-back', true);
|
||||
|
||||
expect(spec.status()).toBe('disabled');
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(fakeQueueRunner).not.toHaveBeenCalled();
|
||||
expect(fakeQueueRunner).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
onComplete: jasmine.any(Function),
|
||||
queueableFns: [{fn: jasmine.any(Function)}],
|
||||
cleanupFns: [{fn: jasmine.any(Function)}]
|
||||
}));
|
||||
expect(specBody).not.toHaveBeenCalled();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[0].fn();
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
args.cleanupFns[0].fn();
|
||||
expect(resultCallback).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("can be disabled at execution time by a parent", function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
startCallback = jasmine.createSpy('startCallback'),
|
||||
specBody = jasmine.createSpy('specBody'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
onStart:startCallback,
|
||||
queueableFn: { fn: specBody },
|
||||
resultCallback: resultCallback,
|
||||
queueRunnerFactory: fakeQueueRunner
|
||||
});
|
||||
|
||||
spec.execute(undefined, false);
|
||||
|
||||
expect(spec.result.status).toBe('disabled');
|
||||
|
||||
expect(fakeQueueRunner).not.toHaveBeenCalled();
|
||||
expect(specBody).not.toHaveBeenCalled();
|
||||
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
expect(resultCallback).toHaveBeenCalled();
|
||||
expect(spec.result.status).toBe('excluded');
|
||||
});
|
||||
|
||||
it("can be marked pending, but still calls callbacks when executed", function() {
|
||||
@@ -191,9 +193,12 @@ describe("Spec", function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(fakeQueueRunner).not.toHaveBeenCalled();
|
||||
expect(fakeQueueRunner).toHaveBeenCalled();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.queueableFns[0].fn();
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
args.cleanupFns[0].fn('things');
|
||||
expect(resultCallback).toHaveBeenCalledWith({
|
||||
id: spec.id,
|
||||
status: 'pending',
|
||||
@@ -201,8 +206,9 @@ describe("Spec", function() {
|
||||
fullName: 'a suite with a spec',
|
||||
failedExpectations: [],
|
||||
passedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
pendingReason: ''
|
||||
});
|
||||
}, 'things');
|
||||
});
|
||||
|
||||
it("should call the done callback on execution complete", function() {
|
||||
@@ -219,6 +225,23 @@ describe("Spec", function() {
|
||||
expect(done).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should call the done callback with an error if the spec is failed", function() {
|
||||
var done = jasmine.createSpy('done callback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
catchExceptions: function() { return false; },
|
||||
resultCallback: function() {},
|
||||
queueRunnerFactory: function(attrs) {
|
||||
spec.result.status = 'failed';
|
||||
attrs.onComplete();
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute(done);
|
||||
|
||||
expect(done).toHaveBeenCalledWith(jasmine.any(jasmineUnderTest.StopExecutionError));
|
||||
});
|
||||
|
||||
it("#status returns passing by default", function() {
|
||||
var spec = new jasmineUnderTest.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
|
||||
expect(spec.status()).toBe('passed');
|
||||
@@ -238,11 +261,12 @@ describe("Spec", function() {
|
||||
});
|
||||
|
||||
it("keeps track of passed and failed expectations", function() {
|
||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: jasmine.createSpy("spec body") },
|
||||
expectationResultFactory: function (data) { return data; },
|
||||
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
spec.addExpectationResult(true, 'expectation1');
|
||||
@@ -250,19 +274,21 @@ describe("Spec", function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].cleanupFns[0].fn();
|
||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual(['expectation1']);
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual(['expectation2']);
|
||||
});
|
||||
|
||||
it("throws an ExpectationFailed error upon receiving a failed expectation when 'throwOnExpectationFailure' is set", function() {
|
||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) { return data; },
|
||||
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
|
||||
resultCallback: resultCallback,
|
||||
throwOnExpectationFailure: true
|
||||
});
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) { return data; },
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback,
|
||||
throwOnExpectationFailure: true
|
||||
});
|
||||
|
||||
spec.addExpectationResult(true, 'passed');
|
||||
expect(function() {
|
||||
@@ -271,6 +297,7 @@ describe("Spec", function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
fakeQueueRunner.calls.mostRecent().args[0].cleanupFns[0].fn();
|
||||
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual(['passed']);
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual(['failed']);
|
||||
});
|
||||
@@ -337,17 +364,20 @@ describe("Spec", function() {
|
||||
});
|
||||
|
||||
it("should log a failure when handling an exception", function() {
|
||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) { return data; },
|
||||
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
spec.onException('foo');
|
||||
spec.execute();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.cleanupFns[0].fn();
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([{
|
||||
error: 'foo',
|
||||
matcherName: '',
|
||||
@@ -358,63 +388,20 @@ describe("Spec", function() {
|
||||
});
|
||||
|
||||
it("should not log an additional failure when handling an ExpectationFailed error", function() {
|
||||
var resultCallback = jasmine.createSpy('resultCallback'),
|
||||
var fakeQueueRunner = jasmine.createSpy('queueRunner'),
|
||||
resultCallback = jasmine.createSpy('resultCallback'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} },
|
||||
expectationResultFactory: function(data) { return data; },
|
||||
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
|
||||
queueRunnerFactory: fakeQueueRunner,
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
spec.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||
spec.execute();
|
||||
|
||||
var args = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
args.cleanupFns[0].fn();
|
||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]);
|
||||
});
|
||||
|
||||
it("retrieves a result with updated status", function() {
|
||||
var spec = new jasmineUnderTest.Spec({ queueableFn: { fn: function() {} } });
|
||||
|
||||
expect(spec.getResult().status).toBe('passed');
|
||||
});
|
||||
|
||||
it("retrives a result with disabled status", function() {
|
||||
var spec = new jasmineUnderTest.Spec({ queueableFn: { fn: function() {} } });
|
||||
spec.disable();
|
||||
|
||||
expect(spec.getResult().status).toBe('disabled');
|
||||
});
|
||||
|
||||
it("retrives a result with pending status", function() {
|
||||
var spec = new jasmineUnderTest.Spec({ queueableFn: { fn: function() {} } });
|
||||
spec.pend();
|
||||
|
||||
expect(spec.getResult().status).toBe('pending');
|
||||
});
|
||||
|
||||
it("should not be executable when disabled", function() {
|
||||
var spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} }
|
||||
});
|
||||
spec.disable();
|
||||
|
||||
expect(spec.isExecutable()).toBe(false);
|
||||
});
|
||||
|
||||
it("should be executable when pending", function() {
|
||||
var spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} }
|
||||
});
|
||||
spec.pend();
|
||||
|
||||
expect(spec.isExecutable()).toBe(true);
|
||||
});
|
||||
|
||||
it("should be executable when not disabled or pending", function() {
|
||||
var spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: function() {} }
|
||||
});
|
||||
|
||||
expect(spec.isExecutable()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
describe("SpyRegistry", function() {
|
||||
function createSpy(name, originalFn) {
|
||||
return jasmineUnderTest.Spy(name, originalFn);
|
||||
}
|
||||
|
||||
describe("#spyOn", function() {
|
||||
it("checks for the existence of the object", function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy});
|
||||
expect(function() {
|
||||
spyRegistry.spyOn(void 0, 'pants');
|
||||
}).toThrowError(/could not find an object/);
|
||||
@@ -43,7 +47,10 @@ describe("SpyRegistry", function() {
|
||||
|
||||
it("checks if it has already been spied upon", function() {
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy
|
||||
}),
|
||||
subject = { spiedFunc: function() {} };
|
||||
|
||||
spyRegistry.spyOn(subject, 'spiedFunc');
|
||||
@@ -54,9 +61,6 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
it("checks if it can be spied upon", function() {
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var scope = {};
|
||||
|
||||
function myFunc() {
|
||||
@@ -84,7 +88,7 @@ describe("SpyRegistry", function() {
|
||||
|
||||
it("overrides the method on the object and returns the spy", function() {
|
||||
var originalFunctionWasCalled = false,
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||
subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
|
||||
|
||||
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
|
||||
@@ -94,9 +98,6 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
describe("#spyOnProperty", function() {
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
it("checks for the existence of the object", function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
||||
expect(function() {
|
||||
@@ -137,7 +138,7 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
it("checks if it has already been spied upon", function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||
subject = {};
|
||||
|
||||
Object.defineProperty(subject, 'spiedProp', {
|
||||
@@ -176,7 +177,7 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
it("overrides the property getter on the object and returns the spy", function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||
subject = {},
|
||||
returnValue = 1;
|
||||
|
||||
@@ -195,7 +196,7 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
it("overrides the property setter on the object and returns the spy", function() {
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||
subject = {},
|
||||
returnValue = 1;
|
||||
|
||||
@@ -216,7 +217,10 @@ describe("SpyRegistry", function() {
|
||||
describe("#clearSpies", function() {
|
||||
it("restores the original functions on the spied-upon objects", function() {
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy
|
||||
}),
|
||||
originalFunction = function() {},
|
||||
subject = { spiedFunc: originalFunction };
|
||||
|
||||
@@ -228,7 +232,10 @@ describe("SpyRegistry", function() {
|
||||
|
||||
it("restores the original functions, even when that spy has been replace and re-spied upon", function() {
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy
|
||||
}),
|
||||
originalFunction = function() {},
|
||||
subject = { spiedFunc: originalFunction };
|
||||
|
||||
@@ -246,11 +253,11 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
it("does not add a property that the spied-upon object didn't originally have", function() {
|
||||
// IE 8 doesn't support `Object.create`
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy
|
||||
}),
|
||||
originalFunction = function() {},
|
||||
subjectParent = {spiedFunc: originalFunction};
|
||||
|
||||
@@ -266,11 +273,11 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
it("restores the original function when it\'s inherited and cannot be deleted", function() {
|
||||
// IE 8 doesn't support `Object.create` or `Object.defineProperty`
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy
|
||||
}),
|
||||
originalFunction = function() {},
|
||||
subjectParent = {spiedFunc: originalFunction};
|
||||
|
||||
@@ -287,15 +294,34 @@ describe("SpyRegistry", function() {
|
||||
|
||||
expect(jasmineUnderTest.isSpy(subject.spiedFunc)).toBe(false);
|
||||
});
|
||||
|
||||
it("restores window.onerror by overwriting, not deleting", function() {
|
||||
function FakeWindow() {
|
||||
}
|
||||
FakeWindow.prototype.onerror = function() {};
|
||||
|
||||
var spies = [],
|
||||
global = new FakeWindow(),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy,
|
||||
global: global
|
||||
});
|
||||
|
||||
spyRegistry.spyOn(global, 'onerror');
|
||||
spyRegistry.clearSpies();
|
||||
expect(global.onerror).toBe(FakeWindow.prototype.onerror);
|
||||
expect(global.hasOwnProperty('onerror')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('spying on properties', function() {
|
||||
it("restores the original properties on the spied-upon objects", function() {
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy
|
||||
}),
|
||||
originalReturn = 1,
|
||||
subject = {};
|
||||
|
||||
@@ -311,11 +337,11 @@ describe("SpyRegistry", function() {
|
||||
});
|
||||
|
||||
it("does not add a property that the spied-upon object didn't originally have", function() {
|
||||
// IE 8 doesn't support `Object.create`
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy
|
||||
}),
|
||||
originalReturn = 1,
|
||||
subjectParent = {};
|
||||
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
describe('Spies', function () {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
describe("createSpy", function() {
|
||||
var TestClass;
|
||||
|
||||
@@ -9,7 +15,7 @@ describe('Spies', function () {
|
||||
});
|
||||
|
||||
it("preserves the properties of the spied function", function() {
|
||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
|
||||
expect(spy.bob).toEqual("test");
|
||||
});
|
||||
@@ -18,19 +24,19 @@ describe('Spies', function () {
|
||||
TestClass.prototype.someFunction.and = "turkey";
|
||||
|
||||
expect(function() {
|
||||
jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
}).toThrowError("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
|
||||
});
|
||||
|
||||
it("adds a spyStrategy and callTracker to the spy", function() {
|
||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
|
||||
expect(spy.and).toEqual(jasmine.any(jasmineUnderTest.SpyStrategy));
|
||||
expect(spy.calls).toEqual(jasmine.any(jasmineUnderTest.CallTracker));
|
||||
});
|
||||
|
||||
it("tracks the argument of calls", function () {
|
||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var trackSpy = spyOn(spy.calls, "track");
|
||||
|
||||
spy("arg");
|
||||
@@ -39,7 +45,7 @@ describe('Spies', function () {
|
||||
});
|
||||
|
||||
it("tracks the context of calls", function () {
|
||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var trackSpy = spyOn(spy.calls, "track");
|
||||
|
||||
var contextObject = { spyMethod: spy };
|
||||
@@ -49,7 +55,7 @@ describe('Spies', function () {
|
||||
});
|
||||
|
||||
it("tracks the return value of calls", function () {
|
||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||
var trackSpy = spyOn(spy.calls, "track");
|
||||
|
||||
spy.and.returnValue("return value");
|
||||
@@ -71,7 +77,7 @@ describe('Spies', function () {
|
||||
|
||||
for (var arity = 0; arity < functions.length; arity++) {
|
||||
var someFunction = functions[arity],
|
||||
spy = jasmineUnderTest.createSpy(someFunction.name, someFunction);
|
||||
spy = env.createSpy(someFunction.name, someFunction);
|
||||
|
||||
expect(spy.length).toEqual(arity);
|
||||
}
|
||||
@@ -80,48 +86,92 @@ 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 = jasmineUnderTest.createSpyObj('BaseName', {'method1': 42, 'method2': 'special sauce' });
|
||||
var spyObj = env.createSpyObj('BaseName', {'method1': 42, 'method2': 'special sauce' });
|
||||
|
||||
expect(spyObj.method1()).toEqual(42);
|
||||
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
|
||||
expect(spyObj.method1.and.identity).toEqual('BaseName.method1');
|
||||
|
||||
expect(spyObj.method2()).toEqual('special sauce');
|
||||
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
|
||||
expect(spyObj.method2.and.identity).toEqual('BaseName.method2');
|
||||
});
|
||||
|
||||
|
||||
it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() {
|
||||
var spyObj = jasmineUnderTest.createSpyObj('BaseName', ['method1', 'method2']);
|
||||
var spyObj = env.createSpyObj('BaseName', ['method1', 'method2']);
|
||||
|
||||
expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
|
||||
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
|
||||
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
|
||||
expect(spyObj.method1.and.identity).toEqual('BaseName.method1');
|
||||
expect(spyObj.method2.and.identity).toEqual('BaseName.method2');
|
||||
});
|
||||
|
||||
it("should allow you to omit the baseName", function() {
|
||||
var spyObj = jasmineUnderTest.createSpyObj(['method1', 'method2']);
|
||||
var spyObj = env.createSpyObj(['method1', 'method2']);
|
||||
|
||||
expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
|
||||
expect(spyObj.method1.and.identity()).toEqual('unknown.method1');
|
||||
expect(spyObj.method2.and.identity()).toEqual('unknown.method2');
|
||||
expect(spyObj.method1.and.identity).toEqual('unknown.method1');
|
||||
expect(spyObj.method2.and.identity).toEqual('unknown.method2');
|
||||
});
|
||||
|
||||
it("should throw if you do not pass an array or object argument", function() {
|
||||
expect(function() {
|
||||
jasmineUnderTest.createSpyObj('BaseName');
|
||||
env.createSpyObj('BaseName');
|
||||
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
||||
});
|
||||
|
||||
it("should throw if you pass an empty array argument", function() {
|
||||
expect(function() {
|
||||
jasmineUnderTest.createSpyObj('BaseName', []);
|
||||
env.createSpyObj('BaseName', []);
|
||||
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
||||
});
|
||||
|
||||
it("should throw if you pass an empty object argument", function() {
|
||||
expect(function() {
|
||||
jasmineUnderTest.createSpyObj('BaseName', {});
|
||||
env.createSpyObj('BaseName', {});
|
||||
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
||||
});
|
||||
});
|
||||
|
||||
it("can use different strategies for different arguments", function() {
|
||||
var spy = env.createSpy('foo');
|
||||
spy.and.returnValue(42);
|
||||
spy.withArgs('baz', 'grault').and.returnValue(-1);
|
||||
spy.withArgs('thud').and.returnValue('bob');
|
||||
|
||||
expect(spy('foo')).toEqual(42);
|
||||
expect(spy('baz', 'grault')).toEqual(-1);
|
||||
expect(spy('thud')).toEqual('bob');
|
||||
expect(spy('baz', 'grault', 'waldo')).toEqual(42);
|
||||
});
|
||||
|
||||
it("uses custom equality testers when selecting a strategy", function() {
|
||||
var spy = env.createSpy('foo');
|
||||
spy.and.returnValue(42);
|
||||
spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
|
||||
|
||||
expect(spy('foo')).toEqual(-1);
|
||||
expect(spy({})).toEqual(42);
|
||||
});
|
||||
|
||||
it("can reconfigure an argument-specific strategy", function() {
|
||||
var spy = env.createSpy('foo');
|
||||
spy.withArgs('foo').and.returnValue(42);
|
||||
spy.withArgs('foo').and.returnValue(17);
|
||||
expect(spy('foo')).toEqual(17);
|
||||
});
|
||||
|
||||
describe("When withArgs is used without a base strategy", function() {
|
||||
it("uses the matching strategy", function() {
|
||||
var 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');
|
||||
spy.withArgs('bar').and.returnValue(-1);
|
||||
|
||||
expect(function() { spy('baz', {qux: 42}); }).toThrowError('Spy \'foo\' receieved a call with arguments [ \'baz\', Object({ qux: 42 }) ] but all configured strategies specify other arguments.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,13 +3,13 @@ describe("SpyStrategy", function() {
|
||||
it("defaults its name to unknown", function() {
|
||||
var spyStrategy = new jasmineUnderTest.SpyStrategy();
|
||||
|
||||
expect(spyStrategy.identity()).toEqual("unknown");
|
||||
expect(spyStrategy.identity).toEqual("unknown");
|
||||
});
|
||||
|
||||
it("takes a name", function() {
|
||||
var spyStrategy = new jasmineUnderTest.SpyStrategy({name: "foo"});
|
||||
|
||||
expect(spyStrategy.identity()).toEqual("foo");
|
||||
expect(spyStrategy.identity).toEqual("foo");
|
||||
});
|
||||
|
||||
it("stubs an original function, if provided", function() {
|
||||
@@ -27,7 +27,7 @@ describe("SpyStrategy", function() {
|
||||
returnValue;
|
||||
|
||||
spyStrategy.callThrough();
|
||||
returnValue = spyStrategy.exec("foo");
|
||||
returnValue = spyStrategy.exec(null, ["foo"]);
|
||||
|
||||
expect(originalFn).toHaveBeenCalled();
|
||||
expect(originalFn.calls.mostRecent().args).toEqual(["foo"]);
|
||||
@@ -92,12 +92,78 @@ describe("SpyStrategy", function() {
|
||||
expect(returnValue).toEqual(67);
|
||||
});
|
||||
|
||||
it("allows a fake async function to be called instead", function(done) {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
var originalFn = jasmine.createSpy("original"),
|
||||
fakeFn = jasmine.createSpy("fake").and.callFake(eval("async () => { return 67; }")),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
||||
returnValue;
|
||||
|
||||
spyStrategy.callFake(fakeFn);
|
||||
spyStrategy.exec().then(function (returnValue) {
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
expect(fakeFn).toHaveBeenCalled();
|
||||
expect(returnValue).toEqual(67);
|
||||
done();
|
||||
}).catch(function (err) {
|
||||
done.fail(err);
|
||||
})
|
||||
});
|
||||
|
||||
it("allows a custom strategy to be used", function() {
|
||||
var plan = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue('custom strategy result'),
|
||||
customStrategy = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue(plan),
|
||||
originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
customStrategies: {
|
||||
doSomething: customStrategy
|
||||
}
|
||||
});
|
||||
|
||||
spyStrategy.doSomething(1, 2, 3);
|
||||
expect(customStrategy).toHaveBeenCalledWith(1, 2, 3);
|
||||
expect(spyStrategy.exec(null, ['some', 'args']))
|
||||
.toEqual('custom strategy result');
|
||||
expect(plan).toHaveBeenCalledWith('some', 'args');
|
||||
});
|
||||
|
||||
it("throws an error if a custom strategy doesn't return a function", function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
customStrategies: {
|
||||
doSomething: function() { return 'not a function' }
|
||||
}
|
||||
});
|
||||
|
||||
expect(function() { spyStrategy.doSomething(1, 2, 3) }).toThrowError('Spy strategy must return a function');
|
||||
});
|
||||
|
||||
it("does not allow custom strategies to overwrite existing methods", function() {
|
||||
var spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: function() {},
|
||||
customStrategies: {
|
||||
exec: function() {}
|
||||
}
|
||||
});
|
||||
|
||||
expect(spyStrategy.exec).toBe(jasmineUnderTest.SpyStrategy.prototype.exec);
|
||||
});
|
||||
|
||||
it('throws an error when a non-function is passed to callFake strategy', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
||||
invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/];
|
||||
|
||||
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
|
||||
spyOn(jasmineUnderTest, 'isAsyncFunction_').and.returnValue(false);
|
||||
|
||||
expect(function () {
|
||||
spyStrategy.callFake(function() {});
|
||||
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
||||
|
||||
expect(function () {
|
||||
spyStrategy.callFake(function() {});
|
||||
|
||||
166
spec/core/StackTraceSpec.js
Normal file
166
spec/core/StackTraceSpec.js
Normal file
@@ -0,0 +1,166 @@
|
||||
describe("StackTrace", function() {
|
||||
it("understands Chrome/IE/Edge style traces", function() {
|
||||
var raw =
|
||||
'Error: nope\n' +
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)';
|
||||
|
||||
var result = new jasmineUnderTest.StackTrace(raw);
|
||||
|
||||
expect(result.message).toEqual('Error: nope');
|
||||
expect(result.style).toEqual('v8');
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw: ' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||
func: 'UserContext.<anonymous>',
|
||||
file: 'http://localhost:8888/__spec__/core/UtilSpec.js',
|
||||
line: 115
|
||||
},
|
||||
{
|
||||
raw: ' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)',
|
||||
func: 'QueueRunner.run',
|
||||
file: 'http://localhost:8888/__jasmine__/jasmine.js',
|
||||
line: 4320
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("understands Node style traces", function() {
|
||||
var raw = 'Error\n' +
|
||||
' at /somewhere/jasmine/lib/jasmine-core/jasmine.js:4255:9\n' +
|
||||
' at QueueRunner.complete [as onComplete] (/somewhere/jasmine/lib/jasmine-core/jasmine.js:579:9)\n' +
|
||||
' at Immediate.<anonymous> (/somewhere/jasmine/lib/jasmine-core/jasmine.js:4314:12)\n' +
|
||||
' at runCallback (timers.js:672:20)';
|
||||
var result = new jasmineUnderTest.StackTrace(raw);
|
||||
|
||||
expect(result.message).toEqual('Error');
|
||||
expect(result.style).toEqual('v8');
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw: ' at /somewhere/jasmine/lib/jasmine-core/jasmine.js:4255:9',
|
||||
func: undefined,
|
||||
file: '/somewhere/jasmine/lib/jasmine-core/jasmine.js',
|
||||
line: 4255
|
||||
},
|
||||
{
|
||||
raw: ' at QueueRunner.complete [as onComplete] (/somewhere/jasmine/lib/jasmine-core/jasmine.js:579:9)',
|
||||
func: 'QueueRunner.complete [as onComplete]',
|
||||
file: '/somewhere/jasmine/lib/jasmine-core/jasmine.js',
|
||||
line: 579
|
||||
},
|
||||
{
|
||||
raw: ' at Immediate.<anonymous> (/somewhere/jasmine/lib/jasmine-core/jasmine.js:4314:12)',
|
||||
func: 'Immediate.<anonymous>',
|
||||
file: '/somewhere/jasmine/lib/jasmine-core/jasmine.js',
|
||||
line: 4314
|
||||
},
|
||||
{
|
||||
raw: ' at runCallback (timers.js:672:20)',
|
||||
func: 'runCallback',
|
||||
file: 'timers.js',
|
||||
line: 672
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("understands Safari/Firefox/Phantom-OS X style traces", function() {
|
||||
var raw =
|
||||
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
|
||||
'run@http://localhost:8888/__jasmine__/jasmine.js:4320:27';
|
||||
var result = new jasmineUnderTest.StackTrace(raw);
|
||||
|
||||
expect(result.message).toBeFalsy();
|
||||
expect(result.style).toEqual('webkit');
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw: 'http://localhost:8888/__spec__/core/UtilSpec.js:115:28',
|
||||
func: undefined,
|
||||
file: 'http://localhost:8888/__spec__/core/UtilSpec.js',
|
||||
line: 115
|
||||
},
|
||||
{
|
||||
raw: 'run@http://localhost:8888/__jasmine__/jasmine.js:4320:27',
|
||||
func: 'run',
|
||||
file: 'http://localhost:8888/__jasmine__/jasmine.js',
|
||||
line: 4320
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not mistake gibberish for Safari/Firefox/Phantom-OS X style traces", function() {
|
||||
var raw = 'randomcharsnotincludingwhitespace';
|
||||
var result = new jasmineUnderTest.StackTrace(raw);
|
||||
expect(result.style).toBeNull();
|
||||
expect(result.frames).toEqual([
|
||||
{ raw: raw }
|
||||
]);
|
||||
});
|
||||
|
||||
it("understands Phantom-Linux style traces", function() {
|
||||
var raw =
|
||||
' 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(raw);
|
||||
|
||||
expect(result.message).toBeFalsy();
|
||||
expect(result.style).toEqual('v8');
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw: ' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||
func: 'UserContext.<anonymous>',
|
||||
file: 'http://localhost:8888/__spec__/core/UtilSpec.js',
|
||||
line: 115
|
||||
},
|
||||
{
|
||||
raw: ' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)',
|
||||
func: 'QueueRunner.run',
|
||||
file: 'http://localhost:8888/__jasmine__/jasmine.js',
|
||||
line: 4320
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("ignores blank lines", function() {
|
||||
var raw =
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n';
|
||||
|
||||
var result = new jasmineUnderTest.StackTrace(raw);
|
||||
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw: ' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||
func: 'UserContext.<anonymous>',
|
||||
file: 'http://localhost:8888/__spec__/core/UtilSpec.js',
|
||||
line: 115
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("omits properties except 'raw' for frames that are not understood", function() {
|
||||
var raw =
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' but this is quite unexpected\n' +
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)';
|
||||
|
||||
var result = new jasmineUnderTest.StackTrace(raw);
|
||||
expect(result.style).toEqual('v8');
|
||||
expect(result.frames).toEqual([
|
||||
{
|
||||
raw: ' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||
func: 'UserContext.<anonymous>',
|
||||
file: 'http://localhost:8888/__spec__/core/UtilSpec.js',
|
||||
line: 115
|
||||
},
|
||||
{
|
||||
raw: ' but this is quite unexpected'
|
||||
},
|
||||
{
|
||||
raw: ' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)',
|
||||
func: 'QueueRunner.run',
|
||||
file: 'http://localhost:8888/__jasmine__/jasmine.js',
|
||||
line: 4320
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -67,11 +67,10 @@ describe("Suite", function() {
|
||||
expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
|
||||
});
|
||||
|
||||
it('has a status of failed if any afterAll expectations have failed', function() {
|
||||
it('has a status of failed if any expectations have failed', function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
expectationResultFactory: function() { return 'hi'; }
|
||||
});
|
||||
suite.addChild({ result: { status: 'done' } });
|
||||
|
||||
suite.addExpectationResult(false);
|
||||
expect(suite.status()).toBe('failed');
|
||||
@@ -80,7 +79,7 @@ describe("Suite", function() {
|
||||
it("retrieves a result with updated status", function() {
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
|
||||
expect(suite.getResult().status).toBe('finished');
|
||||
expect(suite.getResult().status).toBe('passed');
|
||||
});
|
||||
|
||||
it("retrieves a result with pending status", function() {
|
||||
@@ -90,41 +89,11 @@ describe("Suite", function() {
|
||||
expect(suite.getResult().status).toBe('pending');
|
||||
});
|
||||
|
||||
it("is executable if not pending", function() {
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
|
||||
expect(suite.isExecutable()).toBe(true);
|
||||
});
|
||||
|
||||
it("is not executable if pending", function() {
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
suite.pend();
|
||||
|
||||
expect(suite.isExecutable()).toBe(false);
|
||||
});
|
||||
|
||||
it("tells all children about expectation failures, even if one throws", function() {
|
||||
var suite = new jasmineUnderTest.Suite({}),
|
||||
child1 = { addExpectationResult: jasmine.createSpy('child1#expectationResult'), result: {} },
|
||||
child2 = { addExpectationResult: jasmine.createSpy('child2#expectationResult'), result: {} };
|
||||
|
||||
suite.addChild(child1);
|
||||
suite.addChild(child2);
|
||||
|
||||
child1.addExpectationResult.and.throwError('foo');
|
||||
|
||||
suite.addExpectationResult('stuff');
|
||||
|
||||
expect(child1.addExpectationResult).toHaveBeenCalledWith('stuff');
|
||||
expect(child2.addExpectationResult).toHaveBeenCalledWith('stuff');
|
||||
});
|
||||
|
||||
it("throws an ExpectationFailed when receiving a failed expectation in an afterAll when throwOnExpectationFailure is set", function() {
|
||||
it("throws an ExpectationFailed when receiving a failed expectation when throwOnExpectationFailure is set", function() {
|
||||
var suite = new jasmineUnderTest.Suite({
|
||||
expectationResultFactory: function(data) { return data; },
|
||||
throwOnExpectationFailure: true
|
||||
});
|
||||
suite.addChild({ result: { status: 'done' } });
|
||||
|
||||
expect(function() {
|
||||
suite.addExpectationResult(false, 'failed');
|
||||
@@ -134,12 +103,21 @@ describe("Suite", function() {
|
||||
expect(suite.result.failedExpectations).toEqual(['failed']);
|
||||
});
|
||||
|
||||
it("does not add an additional failure when an expectation fails in an afterAll", function(){
|
||||
it("does not add an additional failure when an expectation fails", function(){
|
||||
var suite = new jasmineUnderTest.Suite({});
|
||||
suite.addChild({ result: { status: 'done' } });
|
||||
|
||||
suite.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
||||
|
||||
expect(suite.getResult().failedExpectations).toEqual([]);
|
||||
})
|
||||
});
|
||||
|
||||
describe('#sharedUserContext', function() {
|
||||
beforeEach(function() {
|
||||
this.suite = new jasmineUnderTest.Suite({});
|
||||
});
|
||||
|
||||
it('returns a UserContext', function() {
|
||||
expect(this.suite.sharedUserContext().constructor).toBe(jasmineUnderTest.UserContext);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,27 +8,24 @@ describe("TreeProcessor", function() {
|
||||
this.canBeReentered = function() {
|
||||
return !attrs.noReenter;
|
||||
};
|
||||
this.isExecutable = function() {
|
||||
return attrs.executable !== false;
|
||||
};
|
||||
this.markedPending = attrs.markedPending || false;
|
||||
this.sharedUserContext = function() {
|
||||
return attrs.userContext || {};
|
||||
};
|
||||
this.getResult = jasmine.createSpy(this.id + '#execute');
|
||||
this.beforeAllFns = attrs.beforeAllFns || [];
|
||||
this.afterAllFns = attrs.afterAllFns || [];
|
||||
this.cleanupBeforeAfter = function() { };
|
||||
}
|
||||
|
||||
function Leaf(attrs) {
|
||||
attrs = attrs || {};
|
||||
this.id = 'leaf' + leafNumber++;
|
||||
this.isExecutable = function() {
|
||||
return attrs.executable !== false;
|
||||
};
|
||||
this.markedPending = attrs.markedPending || false;
|
||||
this.execute = jasmine.createSpy(this.id + '#execute');
|
||||
}
|
||||
|
||||
it("processes a single executable leaf", function() {
|
||||
it("processes a single leaf", function() {
|
||||
var leaf = new Leaf(),
|
||||
processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
|
||||
result = processor.processTree();
|
||||
@@ -36,20 +33,22 @@ describe("TreeProcessor", function() {
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
expect(result[leaf.id]).toEqual({
|
||||
executable: true,
|
||||
excluded: false,
|
||||
willExecute: true,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
});
|
||||
|
||||
it("processes a single non-executable leaf", function() {
|
||||
var leaf = new Leaf({ executable: false }),
|
||||
it("processes a single pending leaf", function() {
|
||||
var leaf = new Leaf({ markedPending: true }),
|
||||
processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
|
||||
result = processor.processTree();
|
||||
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
expect(result[leaf.id]).toEqual({
|
||||
executable: false,
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
});
|
||||
@@ -62,7 +61,26 @@ describe("TreeProcessor", function() {
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
expect(result[leaf.id]).toEqual({
|
||||
executable: false,
|
||||
excluded: true,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
});
|
||||
|
||||
it("processes a single excluded leaf", function() {
|
||||
var leaf = new Leaf(),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: leaf,
|
||||
runnableIds: [leaf.id],
|
||||
excludeNode: function(node) { return true; }
|
||||
}),
|
||||
result = processor.processTree();
|
||||
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
expect(result[leaf.id]).toEqual({
|
||||
excluded: true,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
});
|
||||
@@ -76,18 +94,20 @@ describe("TreeProcessor", function() {
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
expect(result[parent.id]).toEqual({
|
||||
executable: true,
|
||||
excluded: false,
|
||||
willExecute: true,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[leaf.id]).toEqual({
|
||||
executable: true,
|
||||
excluded: false,
|
||||
willExecute: true,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
});
|
||||
|
||||
it("processes a tree with a single non-executable leaf, with the root specified", function() {
|
||||
var leaf = new Leaf({ executable: false }),
|
||||
it("processes a tree with a single pending leaf, with the root specified", function() {
|
||||
var leaf = new Leaf({ markedPending: true }),
|
||||
parent = new Node({ children: [leaf] }),
|
||||
processor = new jasmineUnderTest.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
|
||||
result = processor.processTree();
|
||||
@@ -95,61 +115,77 @@ describe("TreeProcessor", function() {
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
expect(result[parent.id]).toEqual({
|
||||
executable: false,
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[leaf.id]).toEqual({
|
||||
executable: false,
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
});
|
||||
|
||||
it("processes a complicated tree with the root specified", function() {
|
||||
var nonExecutable = new Leaf({ executable: false }),
|
||||
executable = new Leaf({ executable: true }),
|
||||
parent = new Node({ children: [nonExecutable, executable] }),
|
||||
var pendingLeaf = new Leaf({ markedPending: true }),
|
||||
executableLeaf = new Leaf({ markedPending: false }),
|
||||
parent = new Node({ children: [pendingLeaf, executableLeaf] }),
|
||||
childless = new Node(),
|
||||
childOfDisabled = new Leaf({ executable: true }),
|
||||
disabledNode = new Node({ executable: false, children: [childOfDisabled] }),
|
||||
root = new Node({ children: [parent, childless, disabledNode] }),
|
||||
childOfPending = new Leaf({ markedPending: true }),
|
||||
pendingNode = new Node({ markedPending: true, children: [childOfPending] }),
|
||||
parentOfPendings = new Node({ markedPending: false, children: [childless, pendingNode] }),
|
||||
root = new Node({ children: [parent, parentOfPendings] }),
|
||||
processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [root.id] }),
|
||||
result = processor.processTree();
|
||||
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
expect(result[root.id]).toEqual({
|
||||
executable: true,
|
||||
excluded: false,
|
||||
willExecute: true,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[parentOfPendings.id]).toEqual({
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[childless.id]).toEqual({
|
||||
executable: false,
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[nonExecutable.id]).toEqual({
|
||||
executable: false,
|
||||
expect(result[pendingLeaf.id]).toEqual({
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[executable.id]).toEqual({
|
||||
executable: true,
|
||||
expect(result[executableLeaf.id]).toEqual({
|
||||
excluded: false,
|
||||
willExecute: true,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[parent.id]).toEqual({
|
||||
executable: true,
|
||||
excluded: false,
|
||||
willExecute: true,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[disabledNode.id]).toEqual({
|
||||
executable: false,
|
||||
expect(result[pendingNode.id]).toEqual({
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
|
||||
expect(result[childOfDisabled.id]).toEqual({
|
||||
executable: false,
|
||||
expect(result[childOfPending.id]).toEqual({
|
||||
excluded: false,
|
||||
willExecute: false,
|
||||
segments: jasmine.any(Array)
|
||||
});
|
||||
});
|
||||
@@ -218,7 +254,7 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
||||
|
||||
expect(leaf.execute).toHaveBeenCalledWith('foo', true);
|
||||
expect(leaf.execute).toHaveBeenCalledWith('foo', false);
|
||||
});
|
||||
|
||||
it("runs a node with no children", function() {
|
||||
@@ -248,19 +284,20 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn(nodeDone);
|
||||
|
||||
expect(nodeStart).toHaveBeenCalledWith(node);
|
||||
expect(queueRunner).toHaveBeenCalledWith({
|
||||
onComplete: jasmine.any(Function),
|
||||
queueableFns: [],
|
||||
queueableFns: [{ fn: jasmine.any(Function) }],
|
||||
userContext: { node: 'context' },
|
||||
onException: jasmine.any(Function)
|
||||
});
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
|
||||
expect(nodeStart).toHaveBeenCalledWith(node, 'foo');
|
||||
|
||||
node.getResult.and.returnValue({ my: 'result' });
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].onComplete();
|
||||
expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' });
|
||||
expect(nodeDone).toHaveBeenCalled();
|
||||
expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' }, nodeDone);
|
||||
});
|
||||
|
||||
it("runs a node with children", function() {
|
||||
@@ -282,25 +319,25 @@ describe("TreeProcessor", function() {
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(queueableFns.length).toBe(2);
|
||||
expect(queueableFns.length).toBe(3);
|
||||
|
||||
queueableFns[0].fn('foo');
|
||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', true);
|
||||
queueableFns[1].fn('foo');
|
||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', false);
|
||||
|
||||
queueableFns[1].fn('bar');
|
||||
expect(leaf2.execute).toHaveBeenCalledWith('bar', true);
|
||||
queueableFns[2].fn('bar');
|
||||
expect(leaf2.execute).toHaveBeenCalledWith('bar', false);
|
||||
});
|
||||
|
||||
it("runs a disabled node", function() {
|
||||
it("runs an excluded node with leaf", function() {
|
||||
var leaf1 = new Leaf(),
|
||||
node = new Node({ children: [leaf1], executable: false }),
|
||||
node = new Node({ children: [leaf1] }),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
nodeStart = jasmine.createSpy('nodeStart'),
|
||||
nodeComplete = jasmine.createSpy('nodeComplete'),
|
||||
processor = new jasmineUnderTest.TreeProcessor({
|
||||
tree: root,
|
||||
runnableIds: [node.id],
|
||||
runnableIds: [],
|
||||
queueRunnerFactory: queueRunner,
|
||||
nodeStart: nodeStart,
|
||||
nodeComplete: nodeComplete
|
||||
@@ -312,18 +349,19 @@ describe("TreeProcessor", function() {
|
||||
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
queueableFns[0].fn(nodeDone);
|
||||
|
||||
expect(nodeStart).toHaveBeenCalledWith(node);
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(queueableFns.length).toBe(1);
|
||||
expect(queueableFns.length).toBe(2);
|
||||
|
||||
queueableFns[0].fn('foo');
|
||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', false);
|
||||
queueableFns[0].fn('bar');
|
||||
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
|
||||
|
||||
queueableFns[1].fn('foo');
|
||||
expect(leaf1.execute).toHaveBeenCalledWith('foo', true);
|
||||
|
||||
node.getResult.and.returnValue({ im: 'disabled' });
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].onComplete();
|
||||
expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' });
|
||||
expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' }, nodeDone);
|
||||
});
|
||||
|
||||
it("runs beforeAlls for a node with children", function() {
|
||||
@@ -348,7 +386,7 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
|
||||
expect(queueableFns).toEqual(['beforeAll1', 'beforeAll2', { fn: jasmine.any(Function) }]);
|
||||
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, 'beforeAll1', 'beforeAll2', { fn: jasmine.any(Function) }]);
|
||||
});
|
||||
|
||||
it("runs afterAlls for a node with children", function() {
|
||||
@@ -373,7 +411,7 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
|
||||
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, 'afterAll1', 'afterAll2']);
|
||||
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, { fn: jasmine.any(Function) }, 'afterAll1', 'afterAll2']);
|
||||
});
|
||||
|
||||
it("does not run beforeAlls or afterAlls for a node with no children", function() {
|
||||
@@ -397,16 +435,16 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
|
||||
expect(queueableFns).toEqual([]);
|
||||
expect(queueableFns).toEqual([{fn: jasmine.any(Function)}]);
|
||||
});
|
||||
|
||||
it("does not run beforeAlls or afterAlls for a disabled node", function() {
|
||||
var leaf = new Leaf(),
|
||||
it("does not run beforeAlls or afterAlls for a node with only pending children", function() {
|
||||
var leaf = new Leaf({ markedPending: true }),
|
||||
node = new Node({
|
||||
children: [leaf],
|
||||
beforeAllFns: ['before'],
|
||||
afterAllFns: ['after'],
|
||||
executable: false
|
||||
markedPending: false
|
||||
}),
|
||||
root = new Node({ children: [node] }),
|
||||
queueRunner = jasmine.createSpy('queueRunner'),
|
||||
@@ -424,7 +462,7 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
|
||||
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }]);
|
||||
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, { fn: jasmine.any(Function) }]);
|
||||
});
|
||||
|
||||
it("runs leaves in the order specified", function() {
|
||||
@@ -451,7 +489,7 @@ describe("TreeProcessor", function() {
|
||||
expect(leaf1.execute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("runs specified leaves before non-specified leaves", function() {
|
||||
it("runs specified leaves before non-specified leaves within a parent node", function() {
|
||||
var specified = new Leaf(),
|
||||
nonSpecified = new Leaf(),
|
||||
root = new Node({ children: [nonSpecified, specified] }),
|
||||
@@ -468,11 +506,11 @@ describe("TreeProcessor", function() {
|
||||
queueableFns[0].fn();
|
||||
|
||||
expect(nonSpecified.execute).not.toHaveBeenCalled();
|
||||
expect(specified.execute).toHaveBeenCalledWith(undefined, true);
|
||||
expect(specified.execute).toHaveBeenCalledWith(undefined, false);
|
||||
|
||||
queueableFns[1].fn();
|
||||
|
||||
expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, false);
|
||||
expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, true);
|
||||
});
|
||||
|
||||
it("runs nodes and leaves with a specified order", function() {
|
||||
@@ -493,7 +531,7 @@ describe("TreeProcessor", function() {
|
||||
|
||||
expect(specifiedLeaf.execute).not.toHaveBeenCalled();
|
||||
var nodeQueueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
nodeQueueableFns[0].fn();
|
||||
nodeQueueableFns[1].fn();
|
||||
|
||||
expect(childLeaf.execute).toHaveBeenCalled();
|
||||
|
||||
@@ -522,8 +560,8 @@ describe("TreeProcessor", function() {
|
||||
expect(queueableFns.length).toBe(5);
|
||||
|
||||
queueableFns[0].fn();
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(leaf1.execute).toHaveBeenCalled();
|
||||
|
||||
queueableFns[1].fn();
|
||||
@@ -531,8 +569,8 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns[2].fn();
|
||||
expect(queueRunner.calls.count()).toBe(3);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(leaf2.execute).toHaveBeenCalled();
|
||||
|
||||
queueableFns[3].fn();
|
||||
@@ -540,8 +578,8 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns[4].fn();
|
||||
expect(queueRunner.calls.count()).toBe(4);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(leaf3.execute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -567,12 +605,12 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns[0].fn();
|
||||
expect(queueRunner.calls.count()).toBe(2);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(queueRunner.calls.count()).toBe(3);
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(leaf1.execute).toHaveBeenCalled();
|
||||
|
||||
queueableFns[1].fn();
|
||||
@@ -580,12 +618,12 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns[2].fn();
|
||||
expect(queueRunner.calls.count()).toBe(4);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(queueRunner.calls.count()).toBe(5);
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(leaf2.execute).toHaveBeenCalled();
|
||||
|
||||
queueableFns[3].fn();
|
||||
@@ -593,12 +631,12 @@ describe("TreeProcessor", function() {
|
||||
|
||||
queueableFns[4].fn();
|
||||
expect(queueRunner.calls.count()).toBe(6);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
|
||||
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(queueRunner.calls.count()).toBe(7);
|
||||
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
|
||||
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
|
||||
expect(leaf3.execute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -625,11 +663,11 @@ describe("TreeProcessor", function() {
|
||||
queueableFns[1].fn();
|
||||
|
||||
var childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
|
||||
expect(childFns.length).toBe(2);
|
||||
childFns[0].fn();
|
||||
expect(childFns.length).toBe(3);
|
||||
childFns[1].fn();
|
||||
expect(leaf2.execute).toHaveBeenCalled();
|
||||
|
||||
childFns[1].fn();
|
||||
childFns[2].fn();
|
||||
expect(leaf3.execute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -691,7 +729,7 @@ describe("TreeProcessor", function() {
|
||||
expect(leaf11.execute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("runs nodes in a custom order when orderChildren is overrided", function() {
|
||||
it("runs nodes in a custom order when orderChildren is overridden", function() {
|
||||
var leaf1 = new Leaf(),
|
||||
leaf2 = new Leaf(),
|
||||
leaf3 = new Leaf(),
|
||||
|
||||
54
spec/core/UserContextSpec.js
Normal file
54
spec/core/UserContextSpec.js
Normal file
@@ -0,0 +1,54 @@
|
||||
describe("UserContext", function() {
|
||||
it("Behaves just like an plain object", function() {
|
||||
var context = new jasmineUnderTest.UserContext(),
|
||||
properties = [];
|
||||
|
||||
for (var prop in context) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
properties.push(prop);
|
||||
}
|
||||
}
|
||||
|
||||
expect(properties).toEqual([]);
|
||||
});
|
||||
|
||||
describe('.fromExisting', function() {
|
||||
describe('when using an already built context as model', function() {
|
||||
beforeEach(function() {
|
||||
this.context = new jasmineUnderTest.UserContext();
|
||||
this.context.key = 'value';
|
||||
this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
|
||||
});
|
||||
|
||||
it('returns a cloned object', function() {
|
||||
expect(this.cloned).toEqual(this.context);
|
||||
});
|
||||
|
||||
it('does not return the same object', function() {
|
||||
expect(this.cloned).not.toBe(this.context);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when using a regular object as parameter', function() {
|
||||
beforeEach(function() {
|
||||
this.context = {};
|
||||
this.value = 'value'
|
||||
this.context.key = this.value;
|
||||
this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
|
||||
});
|
||||
|
||||
it('returns an object with the same attributes', function() {
|
||||
expect(this.cloned.key).toEqual(this.value);
|
||||
});
|
||||
|
||||
it('does not return the same object', function() {
|
||||
expect(this.cloned).not.toBe(this.context);
|
||||
});
|
||||
|
||||
it('returns an UserContext', function() {
|
||||
expect(this.cloned.constructor).toBe(jasmineUnderTest.UserContext);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,9 +43,6 @@ describe("jasmineUnderTest.util", function() {
|
||||
});
|
||||
|
||||
describe("getPropertyDescriptor", function() {
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
it("get property descriptor from object", function() {
|
||||
var obj = {prop: 1},
|
||||
actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
|
||||
@@ -94,6 +91,15 @@ describe("jasmineUnderTest.util", function() {
|
||||
|
||||
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
|
||||
// a trailing slash if present.
|
||||
expect(jasmineUnderTest.util.jasmineFile()).toMatch(/util.js\/?$/);
|
||||
expect(jasmine.util.jasmineFile()).toMatch(/jasmine.js\/?$/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,38 @@ describe("Any", function() {
|
||||
expect(any.asymmetricMatch(true)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Map", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Map);
|
||||
|
||||
expect(any.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Set", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Set);
|
||||
|
||||
expect(any.asymmetricMatch(new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a TypedArray", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Uint32Array);
|
||||
|
||||
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Symbol", function() {
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Symbol);
|
||||
|
||||
expect(any.asymmetricMatch(Symbol())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches another constructed object", function() {
|
||||
var Thing = function() {},
|
||||
any = new jasmineUnderTest.Any(Thing);
|
||||
@@ -36,10 +68,17 @@ describe("Any", function() {
|
||||
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
||||
});
|
||||
|
||||
it("does not treat null as an Object", function() {
|
||||
var any = new jasmineUnderTest.Any(Object);
|
||||
|
||||
expect(any.asymmetricMatch(null)).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToString's itself", function() {
|
||||
var 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() {
|
||||
|
||||
@@ -23,6 +23,38 @@ describe("Anything", function() {
|
||||
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Map", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Set", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a TypedArray", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Symbol", function() {
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
expect(anything.asymmetricMatch(Symbol())).toBe(true);
|
||||
});
|
||||
|
||||
it("doesn't match undefined", function() {
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
|
||||
47
spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js
Normal file
47
spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js
Normal file
@@ -0,0 +1,47 @@
|
||||
describe("ArrayWithExactContents", function() {
|
||||
it("matches an array with the same items in a different order", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||
|
||||
expect(matcher.asymmetricMatch([2, 'a', /a/])).toBe(true);
|
||||
});
|
||||
|
||||
it("does not work when not passed an array", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents("foo");
|
||||
|
||||
expect(function() {
|
||||
matcher.asymmetricMatch([]);
|
||||
}).toThrowError(/not 'foo'/);
|
||||
});
|
||||
|
||||
it("does not match when an item is missing", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
||||
|
||||
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
||||
expect(matcher.asymmetricMatch(['a', 2, undefined])).toBe(false);
|
||||
});
|
||||
|
||||
it("does not match when there is an extra item", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
||||
|
||||
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
||||
});
|
||||
|
||||
it("jasmineToStrings itself", function() {
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents([]);
|
||||
|
||||
expect(matcher.jasmineToString()).toMatch("<jasmine.arrayWithExactContents");
|
||||
});
|
||||
|
||||
it("uses custom equality testers", function() {
|
||||
var tester = function(a, b) {
|
||||
// All "foo*" strings match each other.
|
||||
if (typeof a == "string" && typeof b == "string" &&
|
||||
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var matcher = new jasmineUnderTest.ArrayWithExactContents(["fooVal"]);
|
||||
|
||||
expect(matcher.asymmetricMatch(["fooBar"], [tester])).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -57,9 +57,6 @@ describe("ObjectContaining", function() {
|
||||
});
|
||||
|
||||
it("matches defined properties", function(){
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
||||
|
||||
var definedPropertyObject = {};
|
||||
|
||||
@@ -4,6 +4,7 @@ describe("Custom Matchers (Integration)", function() {
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.randomizeTests(false);
|
||||
});
|
||||
|
||||
it("allows adding more matchers local to a spec", function(done) {
|
||||
@@ -67,8 +68,9 @@ describe("Custom Matchers (Integration)", function() {
|
||||
};
|
||||
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.expect({foo: 'fooValue'}).toEqual(jasmine.objectContaining({foo: 'fooBar'}));
|
||||
env.expect(['fooValue']).toEqual(jasmine.arrayContaining(['fooBar']));
|
||||
env.expect({foo: 'fooValue'}).toEqual(jasmineUnderTest.objectContaining({foo: 'fooBar'}));
|
||||
env.expect(['fooValue', 'things']).toEqual(jasmineUnderTest.arrayContaining(['fooBar']));
|
||||
env.expect(['fooValue']).toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
|
||||
});
|
||||
|
||||
var specExpectations = function(result) {
|
||||
|
||||
138
spec/core/integration/CustomSpyStrategiesSpec.js
Normal file
138
spec/core/integration/CustomSpyStrategiesSpec.js
Normal file
@@ -0,0 +1,138 @@
|
||||
describe('Custom Spy Strategies (Integration)', function() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.randomizeTests(false);
|
||||
});
|
||||
|
||||
it('allows adding more strategies local to a suite', function(done) {
|
||||
var plan = jasmine.createSpy('custom strategy plan')
|
||||
.and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue(plan);
|
||||
|
||||
env.describe('suite defining a custom spy strategy', function() {
|
||||
env.beforeEach(function() {
|
||||
env.addSpyStrategy('frobnicate', strategy);
|
||||
});
|
||||
|
||||
env.it('spec in the suite', function() {
|
||||
var spy = env.createSpy('something').and.frobnicate(17);
|
||||
expect(spy(1, 2, 3)).toEqual(42);
|
||||
expect(strategy).toHaveBeenCalledWith(17);
|
||||
expect(plan).toHaveBeenCalledWith(1, 2, 3);
|
||||
});
|
||||
});
|
||||
|
||||
env.it('spec without custom strategy defined', function() {
|
||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('allows adding more strategies local to a spec', function(done) {
|
||||
var plan = jasmine.createSpy('custom strategy plan')
|
||||
.and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue(plan);
|
||||
|
||||
env.it('spec defining a custom spy strategy', function() {
|
||||
env.addSpyStrategy('frobnicate', strategy);
|
||||
var spy = env.createSpy('something').and.frobnicate(17);
|
||||
expect(spy(1, 2, 3)).toEqual(42);
|
||||
expect(strategy).toHaveBeenCalledWith(17);
|
||||
expect(plan).toHaveBeenCalledWith(1, 2, 3);
|
||||
});
|
||||
|
||||
env.it('spec without custom strategy defined', function() {
|
||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('allows using custom strategies on a per-argument basis', function(done) {
|
||||
var plan = jasmine.createSpy('custom strategy plan')
|
||||
.and.returnValue(42);
|
||||
var strategy = jasmine.createSpy('custom strategy')
|
||||
.and.returnValue(plan);
|
||||
|
||||
env.it('spec defining a custom spy strategy', function() {
|
||||
env.addSpyStrategy('frobnicate', strategy);
|
||||
var spy = env.createSpy('something')
|
||||
.and.returnValue('no args return')
|
||||
.withArgs(1, 2, 3).and.frobnicate(17);
|
||||
|
||||
expect(spy()).toEqual('no args return');
|
||||
expect(plan).not.toHaveBeenCalled();
|
||||
expect(spy(1, 2, 3)).toEqual(42);
|
||||
expect(plan).toHaveBeenCalledWith(1, 2, 3);
|
||||
});
|
||||
|
||||
env.it('spec without custom strategy defined', function() {
|
||||
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone });
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('allows multiple custom strategies to be used', function(done) {
|
||||
var plan1 = jasmine.createSpy('plan 1').and.returnValue(42),
|
||||
strategy1 = jasmine.createSpy('strat 1').and.returnValue(plan1),
|
||||
plan2 = jasmine.createSpy('plan 2').and.returnValue(24),
|
||||
strategy2 = jasmine.createSpy('strat 2').and.returnValue(plan2),
|
||||
specDone = jasmine.createSpy('specDone');
|
||||
|
||||
env.beforeEach(function() {
|
||||
env.addSpyStrategy('frobnicate', strategy1);
|
||||
env.addSpyStrategy('jiggle', strategy2);
|
||||
});
|
||||
|
||||
env.it('frobnicates', function() {
|
||||
plan1.calls.reset();
|
||||
plan2.calls.reset();
|
||||
var spy = env.createSpy('spy').and.frobnicate();
|
||||
expect(spy()).toEqual(42);
|
||||
expect(plan1).toHaveBeenCalled();
|
||||
expect(plan2).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
env.it('jiggles', function() {
|
||||
plan1.calls.reset();
|
||||
plan2.calls.reset();
|
||||
var spy = env.createSpy('spy').and.jiggle();
|
||||
expect(spy()).toEqual(24);
|
||||
expect(plan1).not.toHaveBeenCalled();
|
||||
expect(plan2).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
function jasmineDone(result) {
|
||||
expect(result.overallStatus).toEqual('passed');
|
||||
expect(specDone.calls.count()).toBe(2);
|
||||
done();
|
||||
}
|
||||
|
||||
env.addReporter({ jasmineDone: jasmineDone, specDone: specDone });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,10 @@
|
||||
describe("jasmine spec running", function () {
|
||||
describe("spec running", function () {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.getEnv().registerIntegrationMatchers();
|
||||
env = new jasmineUnderTest.Env();
|
||||
env.randomizeTests(false);
|
||||
});
|
||||
|
||||
it('should assign spec ids sequentially', function() {
|
||||
@@ -600,18 +602,16 @@ describe("jasmine spec running", function () {
|
||||
|
||||
it("should recover gracefully when there are errors in describe functions", function(done) {
|
||||
var specs = [],
|
||||
reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);
|
||||
reporter = jasmine.createSpyObj(['specDone', 'suiteDone', 'jasmineDone']);
|
||||
|
||||
reporter.specDone.and.callFake(function(result) {
|
||||
specs.push(result.fullName);
|
||||
});
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(specs).toContain('outer1 inner1 should thingy');
|
||||
expect(specs).toContain('outer1 inner1 encountered a declaration exception');
|
||||
expect(specs).toContain('outer1 inner2 should other thingy');
|
||||
expect(specs).toContain('outer1 encountered a declaration exception');
|
||||
expect(specs).toContain('outer2 should xxx');
|
||||
expect(specs).toEqual(['outer1 inner1 should thingy', 'outer1 inner2 should other thingy', 'outer2 should xxx']);
|
||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1 inner1', [/inner error/]);
|
||||
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [/outer error/]);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -622,7 +622,7 @@ describe("jasmine spec running", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
throw new Error("fake error");
|
||||
throw new Error("inner error");
|
||||
});
|
||||
|
||||
env.describe("inner2", function() {
|
||||
@@ -631,7 +631,7 @@ describe("jasmine spec running", function () {
|
||||
});
|
||||
});
|
||||
|
||||
throw new Error("fake error");
|
||||
throw new Error("outer error");
|
||||
|
||||
});
|
||||
}).not.toThrow();
|
||||
@@ -740,8 +740,8 @@ describe("jasmine spec running", function () {
|
||||
|
||||
it("should run the tests in a consistent order when a seed is supplied", function(done) {
|
||||
var actions = [];
|
||||
env.randomizeTests(true);
|
||||
env.seed('123456');
|
||||
env.randomizeTests(true);
|
||||
|
||||
env.beforeEach(function () {
|
||||
actions.push('topSuite beforeEach');
|
||||
@@ -836,4 +836,141 @@ describe("jasmine spec running", function () {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
describe("When throwOnExpectationFailure is set", function() {
|
||||
it("skips to cleanup functions after an error", function(done) {
|
||||
var actions = [];
|
||||
|
||||
env.describe('Something', function() {
|
||||
env.beforeEach(function() {
|
||||
actions.push('outer beforeEach');
|
||||
throw new Error("error");
|
||||
});
|
||||
|
||||
env.afterEach(function() {
|
||||
actions.push('outer afterEach');
|
||||
});
|
||||
|
||||
env.describe('Inner', function() {
|
||||
env.beforeEach(function() {
|
||||
actions.push('inner beforeEach');
|
||||
});
|
||||
|
||||
env.afterEach(function() {
|
||||
actions.push('inner afterEach');
|
||||
});
|
||||
|
||||
env.it('does it' , function() {
|
||||
actions.push('inner it');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.throwOnExpectationFailure(true);
|
||||
|
||||
var assertions = function() {
|
||||
expect(actions).toEqual([
|
||||
'outer beforeEach',
|
||||
'inner afterEach',
|
||||
'outer afterEach'
|
||||
]);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("skips to cleanup functions after done.fail is called", function(done) {
|
||||
var actions = [];
|
||||
|
||||
env.describe('Something', function() {
|
||||
env.beforeEach(function(done) {
|
||||
actions.push('beforeEach');
|
||||
done.fail('error');
|
||||
actions.push('after done.fail');
|
||||
});
|
||||
|
||||
env.afterEach(function() {
|
||||
actions.push('afterEach');
|
||||
});
|
||||
|
||||
env.it('does it' , function() {
|
||||
actions.push('it');
|
||||
});
|
||||
});
|
||||
|
||||
env.throwOnExpectationFailure(true);
|
||||
|
||||
var assertions = function() {
|
||||
expect(actions).toEqual([
|
||||
'beforeEach',
|
||||
'afterEach'
|
||||
]);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("skips to cleanup functions when an async function times out", function(done) {
|
||||
var actions = [];
|
||||
|
||||
env.describe('Something', function() {
|
||||
env.beforeEach(function(innerDone) {
|
||||
actions.push('beforeEach');
|
||||
}, 1);
|
||||
|
||||
env.afterEach(function() {
|
||||
actions.push('afterEach');
|
||||
});
|
||||
|
||||
env.it('does it' , function() {
|
||||
actions.push('it');
|
||||
});
|
||||
});
|
||||
|
||||
env.throwOnExpectationFailure(true);
|
||||
|
||||
var assertions = function() {
|
||||
expect(actions).toEqual([
|
||||
'beforeEach',
|
||||
'afterEach'
|
||||
]);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when stopOnSpecFailure is on", function() {
|
||||
it("does not run further specs when one fails", function(done) {
|
||||
var actions = [];
|
||||
|
||||
env.it('fails', function() {
|
||||
actions.push('fails');
|
||||
env.expect(1).toBe(2);
|
||||
});
|
||||
|
||||
env.it('does not run', function() {
|
||||
actions.push('does not run');
|
||||
});
|
||||
|
||||
env.randomizeTests(false);
|
||||
env.stopOnSpecFailure(true);
|
||||
|
||||
var assertions = function() {
|
||||
expect(actions).toEqual(['fails']);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: assertions });
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,7 +71,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
|
||||
var one = [1,2,3],
|
||||
two = [1,2,3];
|
||||
two = [1,2,3];
|
||||
|
||||
one.foo = 'bar';
|
||||
two.foo = 'baz';
|
||||
@@ -81,7 +81,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes for Arrays with equivalent contents and properties", function() {
|
||||
var one = [1,2,3],
|
||||
two = [1,2,3];
|
||||
two = [1,2,3];
|
||||
|
||||
one.foo = 'bar';
|
||||
two.foo = 'bar';
|
||||
@@ -122,7 +122,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes for Objects that are equivalent (with cycles)", function() {
|
||||
var actual = { a: "foo" },
|
||||
expected = { a: "foo" };
|
||||
expected = { a: "foo" };
|
||||
|
||||
actual.b = actual;
|
||||
expected.b = actual;
|
||||
@@ -156,8 +156,6 @@ describe("matchersUtil", function() {
|
||||
});
|
||||
|
||||
it("passes for equivalent frozen objects (GitHub issue #266)", function() {
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var a = { foo: 1 },
|
||||
b = {foo: 1 };
|
||||
|
||||
@@ -166,6 +164,16 @@ describe("matchersUtil", function() {
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for equivalent Promises (GitHub issue #1314)", function() {
|
||||
if (typeof Promise === 'undefined') { return; }
|
||||
|
||||
var p1 = new Promise(function () {}),
|
||||
p2 = new Promise(function () {});
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(p1, p1)).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(p1, p2)).toBe(false);
|
||||
});
|
||||
|
||||
describe("when running in a browser", function() {
|
||||
function isNotRunningInBrowser() {
|
||||
@@ -191,10 +199,6 @@ describe("matchersUtil", function() {
|
||||
if (isNotRunningInBrowser()) {
|
||||
return;
|
||||
}
|
||||
// iframe.contentWindow.eval isn't supported in ie8
|
||||
if (jasmine.getEnv().ieVersion < 9) {
|
||||
return;
|
||||
}
|
||||
var iframe = document.createElement('iframe');
|
||||
document.body.appendChild(iframe);
|
||||
iframe.contentWindow.eval('window.testObject = {}');
|
||||
@@ -332,7 +336,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
|
||||
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
||||
symmetricTester = function(a, b) { return false; };
|
||||
symmetricTester = function(a, b) { return false; };
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
||||
@@ -350,16 +354,14 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes when an Any is compared to an Any that checks for the same type", function() {
|
||||
var any1 = new jasmineUnderTest.Any(Function),
|
||||
any2 = new jasmineUnderTest.Any(Function);
|
||||
any2 = new jasmineUnderTest.Any(Function);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for null prototype objects with same properties", function () {
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var objA = Object.create(null),
|
||||
objB = Object.create(null);
|
||||
objB = Object.create(null);
|
||||
|
||||
objA.name = 'test';
|
||||
objB.name = 'test';
|
||||
@@ -368,10 +370,8 @@ describe("matchersUtil", function() {
|
||||
});
|
||||
|
||||
it("fails for null prototype objects with different properties", function () {
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var objA = Object.create(null),
|
||||
objB = Object.create(null);
|
||||
objB = Object.create(null);
|
||||
|
||||
objA.name = 'test';
|
||||
objB.test = 'name';
|
||||
@@ -386,38 +386,145 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes when comparing identical sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([6, 5]);
|
||||
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(5);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and simple elements", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var setA = new Set();
|
||||
setA.add(3);
|
||||
setA.add(6);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(3);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and complex elements 1", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var setA1 = new Set();
|
||||
setA1.add(['a',3]);
|
||||
setA1.add([6,1]);
|
||||
var setA2 = new Set();
|
||||
setA1.add(['y',3]);
|
||||
setA1.add([6,1]);
|
||||
var setA = new Set();
|
||||
setA.add(setA1);
|
||||
setA.add(setA2);
|
||||
|
||||
|
||||
var setB1 = new Set();
|
||||
setB1.add([6,1]);
|
||||
setB1.add(['a',3]);
|
||||
var setB2 = new Set();
|
||||
setB1.add([6,1]);
|
||||
setB1.add(['y',3]);
|
||||
var setB = new Set();
|
||||
setB.add(setB1);
|
||||
setB.add(setB2);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and complex elements 2", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var setA = new Set();
|
||||
setA.add([[1,2], [3,4]]);
|
||||
setA.add([[5,6], [7,8]]);
|
||||
var setB = new Set();
|
||||
setB.add([[5,6], [7,8]]);
|
||||
setB.add([[1,2], [3,4]]);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for sets with different elements", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([6, 3, 5]);
|
||||
var setB = new Set([6, 4, 5]);
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(3);
|
||||
setA.add(5);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(4);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for sets of different size", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([6, 3]);
|
||||
var setB = new Set([6, 4, 5]);
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(3);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(4);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for sets with different insertion order", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([3, 6]);
|
||||
var setB = new Set([6, 3]);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
||||
it("passes when comparing two empty maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
expect(jasmineUnderTest.matchersUtil.equals(new Map(), new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 5);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 5);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical maps with different insertion order", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map();
|
||||
mapA.set("a", 3);
|
||||
mapA.set(6, 1);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 1);
|
||||
mapB.set("a", 3);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for maps with different elements", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 3);
|
||||
mapA.set(5, 1);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 4);
|
||||
mapB.set(5, 1);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for maps of different size", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 3);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 4);
|
||||
mapB.set(5, 1);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
});
|
||||
|
||||
describe("when running in an environment with array polyfills", function() {
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
if (jasmine.getEnv().ieVersion < 9) { return; }
|
||||
|
||||
var findIndexDescriptor = Object.getOwnPropertyDescriptor(Array.prototype, 'findIndex');
|
||||
if (!findIndexDescriptor) {
|
||||
return;
|
||||
@@ -427,28 +534,28 @@ describe("matchersUtil", function() {
|
||||
Object.defineProperty(Array.prototype, 'findIndex', {
|
||||
enumerable: true,
|
||||
value: function (predicate) {
|
||||
if (this === null) {
|
||||
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
||||
}
|
||||
if (this === null) {
|
||||
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
||||
}
|
||||
|
||||
if (typeof predicate !== 'function') {
|
||||
throw new TypeError('predicate must be a function');
|
||||
}
|
||||
if (typeof predicate !== 'function') {
|
||||
throw new TypeError('predicate must be a function');
|
||||
}
|
||||
|
||||
var list = Object(this);
|
||||
var length = list.length >>> 0;
|
||||
var thisArg = arguments[1];
|
||||
var value;
|
||||
var list = Object(this);
|
||||
var length = list.length >>> 0;
|
||||
var thisArg = arguments[1];
|
||||
var value;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
value = list[i];
|
||||
if (predicate.call(thisArg, value, i, list)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < length; i++) {
|
||||
value = list[i];
|
||||
if (predicate.call(thisArg, value, i, list)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
8
spec/core/matchers/nothingSpec.js
Normal file
8
spec/core/matchers/nothingSpec.js
Normal file
@@ -0,0 +1,8 @@
|
||||
describe('nothing', function() {
|
||||
it('should pass', function() {
|
||||
var matcher = jasmineUnderTest.matchers.nothing(),
|
||||
result = matcher.compare();
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,9 @@ describe("toBeCloseTo", function() {
|
||||
|
||||
result = matcher.compare(0, 0.001);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(0, 0.005);
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when not within two decimal places by default", function() {
|
||||
@@ -16,6 +19,9 @@ describe("toBeCloseTo", function() {
|
||||
|
||||
result = matcher.compare(0, 0.01);
|
||||
expect(result.pass).toBe(false);
|
||||
|
||||
result = matcher.compare(0, 0.05);
|
||||
expect(result.pass).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts an optional precision argument", function() {
|
||||
@@ -25,8 +31,36 @@ describe("toBeCloseTo", function() {
|
||||
result = matcher.compare(0, 0.1, 0);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(0, 0.5, 0);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(0, 0.0001, 3);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(0, 0.0005, 3);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(0, 0.00001, 4);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(0, 0.00005, 4);
|
||||
expect(result.pass).toBe(true);
|
||||
});
|
||||
|
||||
it("fails when one of the arguments is null", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeCloseTo();
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(null, null);
|
||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(null).');
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(0, null);
|
||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(0).toBeCloseTo(null).');
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(null, 0);
|
||||
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(0).');
|
||||
});
|
||||
|
||||
it("rounds expected values", function() {
|
||||
@@ -42,7 +76,15 @@ describe("toBeCloseTo", function() {
|
||||
result = matcher.compare(1.23, 1.225);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
result = matcher.compare(1.23, 1.235);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
// 1.2249999 will be rounded to 1.225
|
||||
result = matcher.compare(1.23, 1.2249999);
|
||||
expect(result.pass).toBe(true);
|
||||
|
||||
// 1.2249999 will be rounded to 1.224
|
||||
result = matcher.compare(1.23, 1.2244999);
|
||||
expect(result.pass).toBe(false);
|
||||
|
||||
result = matcher.compare(1.23, 1.234);
|
||||
|
||||
@@ -161,8 +161,8 @@ describe("toEqual", function() {
|
||||
it("uses the default failure message given arrays with different lengths", function() {
|
||||
var actual = [1, 2],
|
||||
expected = [1, 2, 3],
|
||||
message =
|
||||
"Expected [ 1, 2 ] to equal [ 1, 2, 3 ].";
|
||||
message = 'Expected $.length = 2 to equal 3.\n' +
|
||||
'Expected $[2] = undefined to equal 3.';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -211,6 +211,16 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches between arrays of different types", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
|
||||
var actual = new Uint32Array([1, 2, 3]),
|
||||
expected = new Uint16Array([1, 2, 3]),
|
||||
message = "Expected Uint32Array [ 1, 2, 3 ] to equal Uint16Array [ 1, 2, 3 ].";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches involving NaN", function() {
|
||||
var actual = {x: 0},
|
||||
expected = {x: 0/0},
|
||||
@@ -289,22 +299,7 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
function constructorIsNotEnumerable() {
|
||||
// in IE8, the constructor property is not enumerable, even if it is an
|
||||
// own property of the object.
|
||||
// Objects that differ only by an own `constructor` property are thus
|
||||
// considered equal in IE8.
|
||||
for (var key in {constructor: 1}) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
it("reports mismatches between objects with their own constructor property", function () {
|
||||
if (constructorIsNotEnumerable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
function Foo() {}
|
||||
function Bar() {}
|
||||
|
||||
@@ -316,10 +311,6 @@ describe("toEqual", function() {
|
||||
});
|
||||
|
||||
it("reports mismatches between an object with a real constructor and one with its own constructor property", function () {
|
||||
if (constructorIsNotEnumerable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
function Foo() {}
|
||||
function Bar() {}
|
||||
|
||||
@@ -359,13 +350,28 @@ describe("toEqual", function() {
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("does not report deep mismatches within Sets", function() {
|
||||
// TODO: implement deep comparison of set elements
|
||||
// == Sets ==
|
||||
|
||||
it("reports mismatches between Sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = new Set([1]),
|
||||
expected = new Set([2]),
|
||||
message = 'Expected Set( 1 ) to equal Set( 2 ).';
|
||||
var actual = new Set();
|
||||
actual.add(1);
|
||||
var expected = new Set();
|
||||
expected.add(2);
|
||||
var message = 'Expected Set( 1 ) to equal Set( 2 ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports deep mismatches within Sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = new Set();
|
||||
actual.add({x: 1});
|
||||
var expected = new Set();
|
||||
expected.add({x: 2});
|
||||
var message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -373,9 +379,14 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Sets nested in objects", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = {sets: [new Set([1])]},
|
||||
expected = {sets: [new Set([2])]},
|
||||
message = "Expected $.sets[0] = Set( 1 ) to equal Set( 2 ).";
|
||||
var actualSet = new Set();
|
||||
actualSet.add(1);
|
||||
var expectedSet = new Set();
|
||||
expectedSet.add(2);
|
||||
|
||||
var actual = { sets: [actualSet] };
|
||||
var expected = { sets: [expectedSet] };
|
||||
var message = "Expected $.sets[0] = Set( 1 ) to equal Set( 2 ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -383,13 +394,182 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Sets of different lengths", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = new Set([1, 2]),
|
||||
expected = new Set([2]),
|
||||
message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
|
||||
var actual = new Set();
|
||||
actual.add(1);
|
||||
actual.add(2);
|
||||
var expected = new Set();
|
||||
expected.add(2);
|
||||
var message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches between Sets where actual is missing a value from expected", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
// Use 'duplicate' object in actual so sizes match
|
||||
var actual = new Set();
|
||||
actual.add({x: 1});
|
||||
actual.add({x: 1});
|
||||
var expected = new Set();
|
||||
expected.add({x: 1});
|
||||
expected.add({x: 2});
|
||||
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches between Sets where actual has a value missing from expected", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
// Use 'duplicate' object in expected so sizes match
|
||||
var actual = new Set();
|
||||
actual.add({x: 1});
|
||||
actual.add({x: 2});
|
||||
var expected = new Set();
|
||||
expected.add({x: 1});
|
||||
expected.add({x: 1});
|
||||
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
// == Maps ==
|
||||
|
||||
it("does not report mismatches between deep equal Maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
// values are the same but with different object identity
|
||||
var actual = new Map();
|
||||
actual.set('a',{x:1});
|
||||
var expected = new Map();
|
||||
expected.set('a',{x:1});
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
it("reports deep mismatches within Maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map();
|
||||
actual.set('a',{x:1});
|
||||
var expected = new Map();
|
||||
expected.set('a',{x:2});
|
||||
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches between Maps nested in objects", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = {Maps:[new Map()]};
|
||||
actual.Maps[0].set('a',1);
|
||||
var expected = {Maps:[new Map()]};
|
||||
expected.Maps[0].set('a',2);
|
||||
|
||||
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches between Maps of different lengths", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map();
|
||||
actual.set('a',1);
|
||||
var expected = new Map();
|
||||
expected.set('a',2);
|
||||
expected.set('b',1);
|
||||
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports mismatches between Maps with equal values but differing keys", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map();
|
||||
actual.set('a',1);
|
||||
var expected = new Map();
|
||||
expected.set('b',1);
|
||||
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("does not report mismatches between Maps with keys with same object identity", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var key = {x: 1};
|
||||
var actual = new Map();
|
||||
actual.set(key,2);
|
||||
var expected = new Map();
|
||||
expected.set(key,2);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
it("reports mismatches between Maps with identical keys with different object identity", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map();
|
||||
actual.set({x:1},2);
|
||||
var expected = new Map();
|
||||
expected.set({x:1},2);
|
||||
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map();
|
||||
actual.set('a',1);
|
||||
var expected = new Map();
|
||||
expected.set(jasmineUnderTest.anything(),1);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
it("does not report mismatches when comparing Maps with the same symbol keys", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var key = Symbol();
|
||||
var actual = new Map();
|
||||
actual.set(key,1);
|
||||
var expected = new Map();
|
||||
expected.set(key,1);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
it("reports mismatches between Maps with different symbol keys", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var actual = new Map();
|
||||
actual.set(Symbol(),1);
|
||||
var expected = new Map();
|
||||
expected.set(Symbol(),1);
|
||||
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toBe(message);
|
||||
});
|
||||
|
||||
it("does not report mismatches when comparing Map symbol key to jasmine.anything()", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var actual = new Map();
|
||||
actual.set(Symbol(),1);
|
||||
var expected = new Map();
|
||||
expected.set(jasmineUnderTest.anything(),1);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
function isNotRunningInBrowser() {
|
||||
return typeof document === 'undefined'
|
||||
}
|
||||
@@ -401,7 +581,7 @@ describe("toEqual", function() {
|
||||
|
||||
var actual = {a: document.createElement('div')},
|
||||
expected = {a: document.createElement('p')},
|
||||
message = 'Expected $.a = HTMLNode to equal HTMLNode.';
|
||||
message = 'Expected $.a = <div> to equal <p>.';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -419,7 +599,7 @@ describe("toEqual", function() {
|
||||
|
||||
var actual = {a: nodeA},
|
||||
expected = {a: nodeB},
|
||||
message = 'Expected $.a = HTMLNode to equal HTMLNode.';
|
||||
message = 'Expected $.a = <div>...</div> to equal <div>...</div>.';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
})
|
||||
@@ -431,7 +611,7 @@ describe("toEqual", function() {
|
||||
|
||||
var actual = {a: document.createElement('div')},
|
||||
expected = {a: {}},
|
||||
message = 'Expected $.a = HTMLNode to equal Object({ }).';
|
||||
message = 'Expected $.a = <div> to equal Object({ }).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -456,9 +636,9 @@ describe("toEqual", function() {
|
||||
|
||||
it("does not report a mismatch when asymmetric matchers are satisfied", function() {
|
||||
var actual = {a: 'a'},
|
||||
expected = {a: jasmineUnderTest.any(String)},
|
||||
message = 'Expected $.a = 1 to equal <jasmine.any(String)>.';
|
||||
expected = {a: jasmineUnderTest.any(String)};
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual('');
|
||||
expect(compareEquals(actual, expected).pass).toBe(true)
|
||||
});
|
||||
|
||||
@@ -499,7 +679,8 @@ describe("toEqual", function() {
|
||||
|
||||
var message =
|
||||
'Expected $.foo[0].bar = 1 to equal 2.\n' +
|
||||
"Expected $.foo[0].things = [ 'a', 'b' ] to equal [ 'a', 'b', 'c' ].\n" +
|
||||
'Expected $.foo[0].things.length = 2 to equal 3.\n' +
|
||||
"Expected $.foo[0].things[2] = undefined to equal 'c'.\n" +
|
||||
"Expected $.foo[1].things[1] = 'b' to equal 'd'.\n" +
|
||||
'Expected $.baz[0].a to have properties\n' +
|
||||
' c: 1\n' +
|
||||
@@ -513,4 +694,92 @@ describe("toEqual", function() {
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
})
|
||||
|
||||
describe("different length arrays", function() {
|
||||
it("actual array is longer", function() {
|
||||
var actual = [1, 1, 2, 3, 5],
|
||||
expected = [1, 1, 2, 3],
|
||||
message = 'Expected $.length = 5 to equal 4.\n' +
|
||||
'Expected $[4] = 5 to equal undefined.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("expected array is longer", function() {
|
||||
var actual = [1, 1, 2, 3],
|
||||
expected = [1, 1, 2, 3, 5],
|
||||
message = 'Expected $.length = 4 to equal 5.\n' +
|
||||
'Expected $[4] = undefined to equal 5.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("expected array is longer by 4 elements", function() {
|
||||
var actual = [1, 1, 2],
|
||||
expected = [1, 1, 2, 3, 5, 8, 13],
|
||||
message = 'Expected $.length = 3 to equal 7.\n' +
|
||||
'Expected $[3] = undefined to equal 3.\n' +
|
||||
'Expected $[4] = undefined to equal 5.\n' +
|
||||
'Expected $[5] = undefined to equal 8.\n' +
|
||||
'Expected $[6] = undefined to equal 13.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("different length and different elements", function() {
|
||||
var actual = [1],
|
||||
expected = [2, 3],
|
||||
message = 'Expected $.length = 1 to equal 2.\n' +
|
||||
'Expected $[0] = 1 to equal 2.\n' +
|
||||
'Expected $[1] = undefined to equal 3.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("object with nested array", function() {
|
||||
var actual = { values: [1, 1, 2, 3] },
|
||||
expected = { values: [1, 1, 2] },
|
||||
message = 'Expected $.values.length = 4 to equal 3.\n' +
|
||||
'Expected $.values[3] = 3 to equal undefined.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("array with nested object", function() {
|
||||
var actual = [1, 1, 2, { value: 3 }],
|
||||
expected = [1, 1, 2],
|
||||
message = 'Expected $.length = 4 to equal 3.\n' +
|
||||
'Expected $[3] = Object({ value: 3 }) to equal undefined.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("array with nested different length array", function() {
|
||||
var actual = [[1], [1, 2]],
|
||||
expected = [[1, 1], [2]],
|
||||
message = 'Expected $[0].length = 1 to equal 2.\n' +
|
||||
'Expected $[0][1] = undefined to equal 1.\n' +
|
||||
'Expected $[1].length = 2 to equal 1.\n' +
|
||||
'Expected $[1][0] = 1 to equal 2.\n' +
|
||||
'Expected $[1][1] = 2 to equal undefined.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("last element of longer array is undefined", function() {
|
||||
var actual = [1, 2],
|
||||
expected = [1, 2, void 0],
|
||||
message = 'Expected $.length = 2 to equal 3.';
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(false)
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
@@ -2,14 +2,14 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
it("throws an exception when the actual is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
fn = function() {},
|
||||
secondSpy = jasmineUnderTest.createSpy('second spy');
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
||||
|
||||
expect(function() { matcher.compare(fn, secondSpy) }).toThrowError(Error, /Expected a spy, but got Function./);
|
||||
});
|
||||
|
||||
it("throws an exception when the expected is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
fn = function() {};
|
||||
|
||||
expect(function() { matcher.compare(firstSpy, fn) }).toThrowError(Error, /Expected a spy, but got Function./);
|
||||
@@ -17,8 +17,8 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
|
||||
it("fails when the actual was not called", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
||||
secondSpy = jasmineUnderTest.createSpy('second spy');
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
||||
|
||||
secondSpy();
|
||||
|
||||
@@ -29,8 +29,8 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
|
||||
it("fails when the expected was not called", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
||||
secondSpy = jasmineUnderTest.createSpy('second spy');
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
||||
|
||||
firstSpy();
|
||||
|
||||
@@ -41,8 +41,8 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
|
||||
it("fails when the actual is called after the expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||
result;
|
||||
|
||||
secondSpy();
|
||||
@@ -55,8 +55,8 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
|
||||
it("fails when the actual is called before and after the expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||
result;
|
||||
|
||||
firstSpy();
|
||||
@@ -70,8 +70,8 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
|
||||
it("fails when the expected is called before and after the actual", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||
result;
|
||||
|
||||
secondSpy();
|
||||
@@ -85,8 +85,8 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
|
||||
it("passes when the actual is called before the expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||
result;
|
||||
|
||||
firstSpy();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
describe("toHaveBeenCalled", function() {
|
||||
it("passes when the actual was called, with a custom .not fail message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||
result;
|
||||
|
||||
calledSpy();
|
||||
@@ -13,7 +13,7 @@ describe("toHaveBeenCalled", function() {
|
||||
|
||||
it("fails when the actual was not called", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
||||
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||
result;
|
||||
|
||||
result = matcher.compare(uncalledSpy);
|
||||
@@ -29,14 +29,14 @@ describe("toHaveBeenCalled", function() {
|
||||
|
||||
it("throws an exception when invoked with any arguments", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||
spy = jasmineUnderTest.createSpy('sample spy');
|
||||
spy = new jasmineUnderTest.Env().createSpy('sample spy');
|
||||
|
||||
expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/);
|
||||
});
|
||||
|
||||
it("has a custom message on failure", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
||||
spy = new jasmineUnderTest.Env().createSpy('sample-spy'),
|
||||
result;
|
||||
|
||||
result = matcher.compare(spy);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
describe("toHaveBeenCalledTimes", function() {
|
||||
it("passes when the actual 0 matches the expected 0 ", function () {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||
result;
|
||||
result = matcher.compare(calledSpy, 0);
|
||||
expect(result.pass).toBeTruthy();
|
||||
});
|
||||
it("passes when the actual matches the expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||
result;
|
||||
calledSpy();
|
||||
|
||||
@@ -18,7 +18,7 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
|
||||
it("fails when expected numbers is not supplied", function(){
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
spy = jasmineUnderTest.createSpy('spy'),
|
||||
spy = new jasmineUnderTest.Env().createSpy('spy'),
|
||||
result;
|
||||
|
||||
spy();
|
||||
@@ -29,7 +29,7 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
|
||||
it("fails when the actual was called less than the expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
||||
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||
result;
|
||||
|
||||
result = matcher.compare(uncalledSpy, 2);
|
||||
@@ -38,7 +38,7 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
|
||||
it("fails when the actual was called more than expected", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
||||
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||
result;
|
||||
|
||||
uncalledSpy();
|
||||
@@ -59,7 +59,7 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
|
||||
it("has a custom message on failure that tells it was called only once", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
||||
spy = new jasmineUnderTest.Env().createSpy('sample-spy'),
|
||||
result;
|
||||
spy();
|
||||
spy();
|
||||
@@ -72,7 +72,7 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
|
||||
it("has a custom message on failure that tells how many times it was called", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
||||
spy = new jasmineUnderTest.Env().createSpy('sample-spy'),
|
||||
result;
|
||||
spy();
|
||||
spy();
|
||||
|
||||
@@ -5,7 +5,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||
result;
|
||||
|
||||
calledSpy('a', 'b');
|
||||
@@ -21,7 +21,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
},
|
||||
customEqualityTesters = [function() { return true; }],
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
|
||||
calledSpy = jasmineUnderTest.createSpy('called-spy');
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy');
|
||||
|
||||
calledSpy('a', 'b');
|
||||
matcher.compare(calledSpy, 'a', 'b');
|
||||
@@ -34,7 +34,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
||||
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||
result;
|
||||
|
||||
result = matcher.compare(uncalledSpy);
|
||||
@@ -47,7 +47,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
calledSpy = jasmineUnderTest.createSpy('called spy'),
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called spy'),
|
||||
result;
|
||||
|
||||
calledSpy('a');
|
||||
|
||||
@@ -79,7 +79,7 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("passes if thrown is an instanceof Error regardless of global that contains its constructor", function() {
|
||||
if (isNotRunningInBrowser() || jasmine.getEnv().phantomVersion < 2 || jasmine.getEnv().ieVersion < 10) {
|
||||
if (isNotRunningInBrowser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ describe("toThrowError", function() {
|
||||
iframeDocument.body.appendChild(iframeDocument.createElement("script"))
|
||||
.textContent = "function method() { throw new Error('foo'); }";
|
||||
} else {
|
||||
// older IE
|
||||
// IE 10 and older
|
||||
iframeDocument.write("<html><head><script>function method() { throw new Error('foo'); }</script></head></html>");
|
||||
}
|
||||
|
||||
|
||||
73
spec/core/matchers/toThrowMatchingSpec.js
Normal file
73
spec/core/matchers/toThrowMatchingSpec.js
Normal file
@@ -0,0 +1,73 @@
|
||||
describe("toThrowMatching", function() {
|
||||
it("throws an error when the actual is not a function", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching();
|
||||
|
||||
expect(function() {
|
||||
matcher.compare({}, function() { return true; });
|
||||
}).toThrowError(/Actual is not a Function/);
|
||||
});
|
||||
|
||||
it("throws an error when the expected is not a function", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
};
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(fn, 1);
|
||||
}).toThrowError(/Predicate is not a Function/);
|
||||
});
|
||||
|
||||
it("fails if actual does not throw at all", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||
fn = function() {
|
||||
return true;
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, function() { return true; });
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toEqual("Expected function to throw an exception.");
|
||||
});
|
||||
|
||||
it("fails with the correct message if thrown is a falsy value", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||
fn = function() {
|
||||
throw undefined;
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, function() { return false; });
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message()).toEqual("Expected function to throw an exception matching a predicate, but it threw undefined.");
|
||||
});
|
||||
|
||||
it("passes if the argument is a function that returns true when called with the error", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||
predicate = function(e) { return e.message === "nope" },
|
||||
fn = function() {
|
||||
throw new TypeError("nope");
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, predicate);
|
||||
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message).toEqual("Expected function not to throw an exception matching a predicate.");
|
||||
});
|
||||
|
||||
it("fails if the argument is a function that returns false when called with the error", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||
predicate = function(e) { return e.message === "oh no" },
|
||||
fn = function() {
|
||||
throw new TypeError("nope");
|
||||
},
|
||||
result;
|
||||
|
||||
result = matcher.compare(fn, predicate);
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message()).toEqual("Expected function to throw an exception matching a predicate, but it threw TypeError with message 'nope'.");
|
||||
});
|
||||
});
|
||||
@@ -8,20 +8,8 @@
|
||||
return match ? parseFloat(match[1]) : void 0;
|
||||
}
|
||||
|
||||
env.ieVersion = browserVersion(function(userAgent) {
|
||||
return /MSIE ([0-9]{1,}[\.0-9]{0,})/.exec(userAgent);
|
||||
});
|
||||
|
||||
env.safariVersion = browserVersion(function(userAgent) {
|
||||
return /Safari/.exec(userAgent) && /Version\/([0-9]{0,})/.exec(userAgent);
|
||||
});
|
||||
|
||||
env.firefoxVersion = browserVersion(function(userAgent) {
|
||||
return /Firefox\/([0-9]{0,})/.exec(userAgent);
|
||||
});
|
||||
|
||||
env.phantomVersion = browserVersion(function(userAgent) {
|
||||
return /PhantomJS\/([0-9]{0,})/.exec(userAgent);
|
||||
});
|
||||
|
||||
})(jasmine.getEnv());
|
||||
|
||||
27
spec/helpers/asyncAwait.js
Normal file
27
spec/helpers/asyncAwait.js
Normal file
@@ -0,0 +1,27 @@
|
||||
(function(env) {
|
||||
function getAsyncCtor() {
|
||||
try {
|
||||
eval("var func = async function(){};");
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Object.getPrototypeOf(func).constructor;
|
||||
}
|
||||
|
||||
function hasAsyncAwaitSupport() {
|
||||
return getAsyncCtor() !== null;
|
||||
}
|
||||
|
||||
env.makeAsyncAwaitFunction = function() {
|
||||
var AsyncFunction = getAsyncCtor();
|
||||
return new AsyncFunction("");
|
||||
};
|
||||
|
||||
env.requireAsyncAwait = function() {
|
||||
if (!hasAsyncAwaitSupport()) {
|
||||
env.pending("Environment does not support async/await functions");
|
||||
}
|
||||
};
|
||||
})(jasmine.getEnv());
|
||||
|
||||
37
spec/helpers/checkForMap.js
Normal file
37
spec/helpers/checkForMap.js
Normal file
@@ -0,0 +1,37 @@
|
||||
(function(env) {
|
||||
function hasFunctioningMaps() {
|
||||
if (typeof Map === 'undefined') { return false; }
|
||||
|
||||
try {
|
||||
var s = new Map();
|
||||
s.set('a',1);
|
||||
s.set('b',2);
|
||||
|
||||
if (s.size !== 2) { return false; }
|
||||
if (s.has('a') !== true) { return false; }
|
||||
|
||||
var iterations = 0;
|
||||
var ifForEachWorking = true;
|
||||
s.forEach(function(value, key, map) {
|
||||
ifForEachWorking = ifForEachWorking && map === s;
|
||||
if (key==='a') {
|
||||
ifForEachWorking = ifForEachWorking && value===1;
|
||||
}
|
||||
iterations++;
|
||||
});
|
||||
if (iterations !== 2) { return false; }
|
||||
if (ifForEachWorking !== true) { return false; }
|
||||
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
env.requireFunctioningMaps = function() {
|
||||
if (!hasFunctioningMaps()) {
|
||||
env.pending("Browser has incomplete or missing support for Maps");
|
||||
}
|
||||
};
|
||||
|
||||
})(jasmine.getEnv());
|
||||
@@ -3,9 +3,29 @@
|
||||
if (typeof Set === 'undefined') { return false; }
|
||||
|
||||
try {
|
||||
var s = new Set([4]);
|
||||
if (s.size !== 1) { return false; }
|
||||
if (s.values().next().value !== 4) { return false; }
|
||||
var s = new Set();
|
||||
s.add(1);
|
||||
s.add(2);
|
||||
|
||||
if (s.size !== 2) { return false; }
|
||||
if (s.has(1) !== true) { return false; }
|
||||
|
||||
var iterations = 0;
|
||||
var isForEachWorking = true;
|
||||
s.forEach(function(value, key, set) {
|
||||
isForEachWorking = isForEachWorking && set === s;
|
||||
|
||||
if (iterations===0) {
|
||||
isForEachWorking = isForEachWorking && (key===value) && value===1;
|
||||
} else if (iterations===1) {
|
||||
isForEachWorking = isForEachWorking && (key===value) && value===2;
|
||||
}
|
||||
|
||||
iterations++;
|
||||
});
|
||||
if (iterations !== 2) { return false; }
|
||||
if (isForEachWorking !== true) { return false; }
|
||||
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
|
||||
28
spec/helpers/checkForSymbol.js
Normal file
28
spec/helpers/checkForSymbol.js
Normal file
@@ -0,0 +1,28 @@
|
||||
(function(env) {
|
||||
function hasFunctioningSymbols() {
|
||||
if (typeof Symbol === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
var s1 = Symbol();
|
||||
var s2 = Symbol();
|
||||
if (typeof s1 !== 'symbol') {
|
||||
return false;
|
||||
}
|
||||
if (s1 === s2) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
env.requireFunctioningSymbols = function() {
|
||||
if (!hasFunctioningSymbols()) {
|
||||
env.pending("Browser has incomplete or missing support for Symbols");
|
||||
}
|
||||
};
|
||||
|
||||
})(jasmine.getEnv());
|
||||
20
spec/helpers/checkForTypedArrays.js
Normal file
20
spec/helpers/checkForTypedArrays.js
Normal file
@@ -0,0 +1,20 @@
|
||||
(function(env) {
|
||||
function hasFunctioningTypedArrays() {
|
||||
if (typeof Uint32Array === 'undefined') { return false; }
|
||||
|
||||
try {
|
||||
var a = new Uint32Array([1, 2, 3]);
|
||||
if (a.length !== 3) { return false; }
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
env.requireFunctioningTypedArrays = function() {
|
||||
if (!hasFunctioningTypedArrays()) {
|
||||
env.pending("Browser has incomplete or missing support for typed arrays");
|
||||
}
|
||||
};
|
||||
|
||||
})(jasmine.getEnv());
|
||||
@@ -3,5 +3,4 @@
|
||||
// to the Jasmine source files (and not jasmine.js). So re-require
|
||||
window.jasmineUnderTest = jasmineRequire.core(jasmineRequire);
|
||||
jasmineRequire.html(jasmineUnderTest);
|
||||
jasmineRequire.console(jasmineRequire, jasmineUnderTest);
|
||||
})();
|
||||
|
||||
43
spec/helpers/integrationMatchers.js
Normal file
43
spec/helpers/integrationMatchers.js
Normal file
@@ -0,0 +1,43 @@
|
||||
(function(env) {
|
||||
env.registerIntegrationMatchers = function() {
|
||||
jasmine.addMatchers({
|
||||
toHaveFailedExpectationsForRunnable: function (util, customeEqualityTesters) {
|
||||
return {
|
||||
compare: function (actual, fullName, expectedFailures) {
|
||||
var foundRunnable = false, expectations = true, foundFailures = [];
|
||||
for (var i = 0; i < actual.calls.count(); i++) {
|
||||
var args = actual.calls.argsFor(i)[0];
|
||||
|
||||
if (args.fullName === fullName) {
|
||||
foundRunnable = true;
|
||||
|
||||
for (var j = 0; j < args.failedExpectations.length; j++) {
|
||||
foundFailures.push(args.failedExpectations[j].message);
|
||||
}
|
||||
|
||||
for (var j = 0; j < expectedFailures.length; j++) {
|
||||
var failure = foundFailures[j];
|
||||
var expectedFailure = expectedFailures[j];
|
||||
|
||||
if (Object.prototype.toString.call(expectedFailure) === '[object RegExp]') {
|
||||
expectations = expectations && expectedFailure.test(failure);
|
||||
} else {
|
||||
expectations = expectations && failure === expectedFailure;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
pass: foundRunnable && expectations,
|
||||
message: !foundRunnable ? 'The runnable "' + fullName + '" never finished' :
|
||||
'Expected runnable "' + fullName + '" to have failures ' + jasmine.pp(expectedFailures) + ' but it had ' + jasmine.pp(foundFailures)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
})(jasmine.getEnv());
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
}
|
||||
|
||||
function getSourceFiles() {
|
||||
var src_files = ['core/**/*.js', 'console/**/*.js', 'version.js'];
|
||||
var src_files = ['core/**/*.js', 'version.js'];
|
||||
src_files.forEach(function(file) {
|
||||
var filePath = path.join(__dirname, "../../", 'src/', file);
|
||||
glob.sync(filePath).forEach(function(resolvedFile) {
|
||||
@@ -25,9 +25,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
extend(jasmineUnderTestRequire, require(path.join(__dirname,"../../src/console/requireConsole.js")));
|
||||
getSourceFiles();
|
||||
global.jasmineUnderTest = jasmineUnderTestRequire.core(jasmineUnderTestRequire);
|
||||
|
||||
jasmineUnderTestRequire.console(jasmineUnderTestRequire, jasmineUnderTest);
|
||||
})();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
describe("New HtmlReporter", function() {
|
||||
describe("HtmlReporter", function() {
|
||||
it("builds the initial DOM elements, including the title banner", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
@@ -26,9 +26,8 @@ describe("New HtmlReporter", function() {
|
||||
expect(title.getAttribute('href')).toEqual('http://jasmine.github.io/');
|
||||
expect(title.getAttribute('target')).toEqual('_blank');
|
||||
|
||||
var version = banner.querySelector(".jasmine-version"),
|
||||
versionText = 'textContent' in version ? version.textContent : version.innerText;
|
||||
expect(versionText).toEqual(jasmineUnderTest.version);
|
||||
var version = banner.querySelector(".jasmine-version");
|
||||
expect(version.textContent).toEqual(jasmineUnderTest.version);
|
||||
});
|
||||
|
||||
it("builds a single reporter even if initialized multiple times", function() {
|
||||
@@ -93,7 +92,7 @@ describe("New HtmlReporter", function() {
|
||||
expect(specEl.getAttribute("class")).toEqual("jasmine-empty");
|
||||
});
|
||||
|
||||
it("reports the status symbol of a disabled spec", function() {
|
||||
it("reports the status symbol of a excluded spec", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
@@ -105,10 +104,10 @@ describe("New HtmlReporter", function() {
|
||||
});
|
||||
reporter.initialize();
|
||||
|
||||
reporter.specDone({id: 789, status: "disabled", fullName: "symbols should have titles", passedExpectations: [], failedExpectations: []});
|
||||
reporter.specDone({id: 789, status: "excluded", fullName: "symbols should have titles", passedExpectations: [], failedExpectations: []});
|
||||
|
||||
var specEl = container.querySelector('.jasmine-symbol-summary li');
|
||||
expect(specEl.getAttribute("class")).toEqual("jasmine-disabled");
|
||||
expect(specEl.getAttribute("class")).toEqual("jasmine-excluded");
|
||||
expect(specEl.getAttribute("id")).toEqual("spec_789");
|
||||
expect(specEl.getAttribute("title")).toEqual("symbols should have titles");
|
||||
});
|
||||
@@ -178,10 +177,10 @@ describe("New HtmlReporter", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there are suite failures", function () {
|
||||
it("displays the exceptions in their own alert bars", function(){
|
||||
describe('when there are deprecation warnings', function() {
|
||||
it('displays the messages in their own alert bars', function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
container = document.createElement('div'),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
@@ -193,23 +192,34 @@ describe("New HtmlReporter", function() {
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My After All Exception' }] });
|
||||
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My Other Exception' }] });
|
||||
reporter.jasmineDone({ failedExpectations: [{ message: 'Global After All Failure' }, { message: 'Other Global' }] });
|
||||
reporter.specDone({
|
||||
status: 'passed',
|
||||
deprecationWarnings: [{ message: 'spec deprecation' }],
|
||||
failedExpectations: [],
|
||||
passedExpectations: []
|
||||
});
|
||||
reporter.suiteDone({
|
||||
status: 'passed',
|
||||
deprecationWarnings: [{ message: 'suite deprecation' }],
|
||||
failedExpectations: []
|
||||
});
|
||||
reporter.jasmineDone({
|
||||
deprecationWarnings: [{ message: 'global deprecation' }],
|
||||
failedExpectations: []
|
||||
});
|
||||
|
||||
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
|
||||
|
||||
expect(alertBars.length).toEqual(5);
|
||||
expect(alertBars[1].innerHTML).toMatch(/My After All Exception/);
|
||||
expect(alertBars[1].getAttribute("class")).toEqual('jasmine-bar jasmine-errored');
|
||||
expect(alertBars[2].innerHTML).toMatch(/My Other Exception/);
|
||||
expect(alertBars[3].innerHTML).toMatch(/Global After All Failure/);
|
||||
expect(alertBars[4].innerHTML).toMatch(/Other Global/);
|
||||
expect(alertBars.length).toEqual(4);
|
||||
expect(alertBars[1].innerHTML).toMatch(/spec deprecation/);
|
||||
expect(alertBars[1].getAttribute("class")).toEqual('jasmine-bar jasmine-warning');
|
||||
expect(alertBars[2].innerHTML).toMatch(/suite deprecation/);
|
||||
expect(alertBars[3].innerHTML).toMatch(/global deprecation/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when Jasmine is done", function() {
|
||||
it("adds EMPTY to the link title of specs that have no expectations", function() {
|
||||
it("adds a warning to the link title of specs that have no expectations", function() {
|
||||
if (!window.console) {
|
||||
window.console = { error: function(){} };
|
||||
}
|
||||
@@ -228,7 +238,7 @@ describe("New HtmlReporter", function() {
|
||||
reporter.initialize();
|
||||
reporter.jasmineStarted({});
|
||||
reporter.suiteStarted({id: 1});
|
||||
reporter.specStarted({id: 1, status: 'passed', passedExpectations: [], failedExpectations: []});
|
||||
reporter.specStarted({id: 1, passedExpectations: [], failedExpectations: []});
|
||||
reporter.specDone({
|
||||
id: 1,
|
||||
status: 'passed',
|
||||
@@ -265,7 +275,7 @@ describe("New HtmlReporter", function() {
|
||||
reporter.jasmineStarted({});
|
||||
|
||||
timer.elapsed.and.returnValue(100);
|
||||
reporter.jasmineDone();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var duration = container.querySelector(".jasmine-alert .jasmine-duration");
|
||||
expect(duration.innerHTML).toMatch(/finished in 0.1s/);
|
||||
@@ -319,7 +329,12 @@ describe("New HtmlReporter", function() {
|
||||
reporter.specStarted(specResult);
|
||||
reporter.specDone(specResult);
|
||||
|
||||
reporter.suiteDone({id: 2});
|
||||
reporter.suiteDone({
|
||||
id: 2,
|
||||
status: 'things',
|
||||
description: "inner suite",
|
||||
fullName: "A Suite inner suite"
|
||||
});
|
||||
|
||||
specResult = {
|
||||
id: 209,
|
||||
@@ -332,7 +347,12 @@ describe("New HtmlReporter", function() {
|
||||
reporter.specStarted(specResult);
|
||||
reporter.specDone(specResult);
|
||||
|
||||
reporter.suiteDone({id: 1});
|
||||
reporter.suiteDone({
|
||||
id: 1,
|
||||
status: 'things',
|
||||
description: "A Suite",
|
||||
fullName: "A Suite"
|
||||
});
|
||||
|
||||
reporter.jasmineDone({});
|
||||
var summary = container.querySelector(".jasmine-summary");
|
||||
@@ -347,7 +367,7 @@ describe("New HtmlReporter", function() {
|
||||
var node = outerSuite.childNodes[i];
|
||||
classes.push(node.getAttribute("class"));
|
||||
}
|
||||
expect(classes).toEqual(["jasmine-suite-detail", "jasmine-specs", "jasmine-suite", "jasmine-specs"]);
|
||||
expect(classes).toEqual(["jasmine-suite-detail jasmine-things", "jasmine-specs", "jasmine-suite", "jasmine-specs"]);
|
||||
|
||||
var suiteDetail = outerSuite.childNodes[0];
|
||||
var suiteLink = suiteDetail.childNodes[0];
|
||||
@@ -362,7 +382,6 @@ describe("New HtmlReporter", function() {
|
||||
var specLink = spec.childNodes[0];
|
||||
expect(specLink.innerHTML).toEqual("with a spec");
|
||||
expect(specLink.getAttribute("href")).toEqual("?foo=bar&spec=A Suite with a spec");
|
||||
// expect(specLink.getAttribute("title")).toEqual("A Suite with a spec");
|
||||
});
|
||||
|
||||
it("has an options menu", function() {
|
||||
@@ -388,43 +407,78 @@ describe("New HtmlReporter", function() {
|
||||
var trigger = container.querySelector('.jasmine-run-options .jasmine-trigger'),
|
||||
payload = container.querySelector('.jasmine-run-options .jasmine-payload');
|
||||
|
||||
expect(payload.className).not.toContain('jasmine-open');
|
||||
expect(payload).not.toHaveClass('jasmine-open');
|
||||
|
||||
trigger.onclick();
|
||||
|
||||
expect(payload.className).toContain('jasmine-open');
|
||||
expect(payload).toHaveClass('jasmine-open');
|
||||
|
||||
trigger.onclick();
|
||||
|
||||
expect(payload.className).not.toContain('jasmine-open');
|
||||
expect(payload).not.toHaveClass('jasmine-open');
|
||||
});
|
||||
|
||||
describe("UI for raising/catching exceptions", function() {
|
||||
it("should be unchecked if the env is catching", function() {
|
||||
describe("when there are global errors", function() {
|
||||
it("displays the exceptions in their own alert bars", function(){
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var raisingExceptionsUI = container.querySelector(".jasmine-raise");
|
||||
expect(raisingExceptionsUI.checked).toBe(false);
|
||||
reporter.jasmineStarted({});
|
||||
reporter.jasmineDone({ failedExpectations: [
|
||||
{ message: 'Global After All Failure', globalErrorType: 'afterAll' },
|
||||
{ message: 'Your JS is borken', globalErrorType: 'load' }
|
||||
] });
|
||||
|
||||
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
|
||||
|
||||
expect(alertBars.length).toEqual(3);
|
||||
expect(alertBars[1].getAttribute("class")).toEqual('jasmine-bar jasmine-errored');
|
||||
expect(alertBars[1].innerHTML).toMatch(/AfterAll Global After All Failure/);
|
||||
expect(alertBars[2].innerHTML).toMatch(/Error during loading: Your JS is borken/);
|
||||
expect(alertBars[2].innerHTML).not.toMatch(/line/);
|
||||
});
|
||||
|
||||
it("should be checked if the env is not catching", function() {
|
||||
it("displays file and line information if available", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
reporter.jasmineDone({ failedExpectations: [
|
||||
{
|
||||
message: 'Your JS is borken',
|
||||
globalErrorType: 'load',
|
||||
filename: 'some/file.js',
|
||||
lineno: 42
|
||||
}
|
||||
] });
|
||||
|
||||
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
|
||||
|
||||
expect(alertBars.length).toEqual(2);
|
||||
expect(alertBars[1].innerHTML).toMatch(/Error during loading: Your JS is borken in some\/file.js line 42/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("UI for stop on spec failure", function() {
|
||||
it("should be unchecked for full execution", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() {
|
||||
@@ -442,24 +496,49 @@ describe("New HtmlReporter", function() {
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
env.catchExceptions(false);
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var raisingExceptionsUI = container.querySelector(".jasmine-raise");
|
||||
expect(raisingExceptionsUI.checked).toBe(true);
|
||||
var stopOnFailureUI = container.querySelector(".jasmine-fail-fast");
|
||||
expect(stopOnFailureUI.checked).toBe(false);
|
||||
});
|
||||
|
||||
it("should affect the query param for catching exceptions", function() {
|
||||
it("should be checked if stopping short", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
exceptionsClickHandler = jasmine.createSpy("raise exceptions checked"),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
onRaiseExceptionsClick: exceptionsClickHandler,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
env.stopOnSpecFailure(true);
|
||||
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var stopOnFailureUI = container.querySelector(".jasmine-fail-fast");
|
||||
expect(stopOnFailureUI.checked).toBe(true);
|
||||
});
|
||||
|
||||
it("should navigate and turn the setting on", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
navigationHandler = jasmine.createSpy('navigate'),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: navigationHandler,
|
||||
getContainer: getContainer,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
@@ -471,9 +550,40 @@ describe("New HtmlReporter", function() {
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var input = container.querySelector(".jasmine-raise");
|
||||
input.click();
|
||||
expect(exceptionsClickHandler).toHaveBeenCalled();
|
||||
var stopOnFailureUI = container.querySelector(".jasmine-fail-fast");
|
||||
stopOnFailureUI.click();
|
||||
|
||||
expect(navigationHandler).toHaveBeenCalledWith('failFast', true);
|
||||
});
|
||||
|
||||
it("should navigate and turn the setting off", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
navigationHandler = jasmine.createSpy('navigate'),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
navigateWithNewParam: navigationHandler,
|
||||
getContainer: getContainer,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
env.stopOnSpecFailure(true);
|
||||
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var stopOnFailureUI = container.querySelector(".jasmine-fail-fast");
|
||||
stopOnFailureUI.click();
|
||||
|
||||
expect(navigationHandler).toHaveBeenCalledWith('failFast', false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -528,17 +638,17 @@ describe("New HtmlReporter", function() {
|
||||
expect(throwingExpectationsUI.checked).toBe(true);
|
||||
});
|
||||
|
||||
it("should affect the query param for throw expectation failures", function() {
|
||||
it("should navigate and change the setting to on", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
throwingExceptionHandler = jasmine.createSpy('throwingExceptions'),
|
||||
navigateHandler = jasmine.createSpy('navigate'),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
onThrowExpectationsClick: throwingExceptionHandler,
|
||||
navigateWithNewParam: navigateHandler,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
@@ -553,7 +663,37 @@ describe("New HtmlReporter", function() {
|
||||
var throwingExpectationsUI = container.querySelector(".jasmine-throw");
|
||||
throwingExpectationsUI.click();
|
||||
|
||||
expect(throwingExceptionHandler).toHaveBeenCalled();
|
||||
expect(navigateHandler).toHaveBeenCalledWith('throwFailures', true);
|
||||
});
|
||||
|
||||
it("should navigate and change the setting to off", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
navigateHandler = jasmine.createSpy('navigate'),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
navigateWithNewParam: navigateHandler,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
env.throwOnExpectationFailure(true);
|
||||
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var throwingExpectationsUI = container.querySelector(".jasmine-throw");
|
||||
throwingExpectationsUI.click();
|
||||
|
||||
expect(navigateHandler).toHaveBeenCalledWith('throwFailures', false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -575,6 +715,7 @@ describe("New HtmlReporter", function() {
|
||||
}
|
||||
});
|
||||
|
||||
env.randomizeTests(false);
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
@@ -607,17 +748,17 @@ describe("New HtmlReporter", function() {
|
||||
expect(randomUI.checked).toBe(true);
|
||||
});
|
||||
|
||||
it("should affect the query param for random tests", function() {
|
||||
it("should navigate and change the setting to on", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
randomHandler = jasmine.createSpy('randomHandler'),
|
||||
navigateHandler = jasmine.createSpy('navigate'),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
onRandomClick: randomHandler,
|
||||
navigateWithNewParam: navigateHandler,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
@@ -626,13 +767,43 @@ describe("New HtmlReporter", function() {
|
||||
}
|
||||
});
|
||||
|
||||
env.randomizeTests(false);
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var randomUI = container.querySelector(".jasmine-random");
|
||||
randomUI.click();
|
||||
|
||||
expect(randomHandler).toHaveBeenCalled();
|
||||
expect(navigateHandler).toHaveBeenCalledWith('random', true);
|
||||
});
|
||||
|
||||
it("should navigate and change the setting to off", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
navigateHandler = jasmine.createSpy('navigate'),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
navigateWithNewParam: navigateHandler,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
env.randomizeTests(true);
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var randomUI = container.querySelector(".jasmine-random");
|
||||
randomUI.click();
|
||||
|
||||
expect(navigateHandler).toHaveBeenCalledWith('random', false);
|
||||
});
|
||||
|
||||
it("should show the seed bar if randomizing", function() {
|
||||
@@ -661,8 +832,7 @@ describe("New HtmlReporter", function() {
|
||||
});
|
||||
|
||||
var seedBar = container.querySelector(".jasmine-seed-bar");
|
||||
var seedBarText = 'textContent' in seedBar ? seedBar.textContent : seedBar.innerText;
|
||||
expect(seedBarText).toBe(', randomized with seed 424242');
|
||||
expect(seedBar.textContent).toBe(', randomized with seed 424242');
|
||||
var seedLink = container.querySelector(".jasmine-seed-bar a");
|
||||
expect(seedLink.getAttribute('href')).toBe('?seed=424242');
|
||||
});
|
||||
@@ -685,20 +855,21 @@ describe("New HtmlReporter", function() {
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var seedBar = container.querySelector(".jasmine-seed-bar");
|
||||
expect(seedBar).toBeNull();
|
||||
});
|
||||
|
||||
it("should include the random query param in the jasmine-skipped link when randomizing", function(){
|
||||
it("should include non-spec query params in the jasmine-skipped link when present", function(){
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: function() { return container; },
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||
addToExistingQueryString: function(key, value) { return "?foo=bar&" + key + "=" + value; }
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
@@ -706,47 +877,8 @@ describe("New HtmlReporter", function() {
|
||||
reporter.jasmineDone({ order: { random: true } });
|
||||
|
||||
var skippedLink = container.querySelector(".jasmine-skipped a");
|
||||
expect(skippedLink.getAttribute('href')).toEqual('?random=true');
|
||||
expect(skippedLink.getAttribute('href')).toEqual('?foo=bar&spec=');
|
||||
});
|
||||
|
||||
it("should not include the random query param in the jasmine-skipped link when not randomizing", function(){
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: function() { return container; },
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||
reporter.jasmineDone();
|
||||
|
||||
var skippedLink = container.querySelector(".jasmine-skipped a");
|
||||
expect(skippedLink.getAttribute('href')).toEqual('?');
|
||||
});
|
||||
});
|
||||
|
||||
it("shows a message if no specs are run", function(){
|
||||
var env, container, reporter;
|
||||
env = new jasmineUnderTest.Env();
|
||||
container = document.createElement("div");
|
||||
var getContainer = function() { return container; },
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
reporter.jasmineDone({});
|
||||
|
||||
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
|
||||
expect(alertBars[0].getAttribute('class')).toMatch(/jasmine-skipped/);
|
||||
expect(alertBars[0].innerHTML).toMatch(/No specs found/);
|
||||
});
|
||||
|
||||
describe("and all specs pass", function() {
|
||||
@@ -787,7 +919,6 @@ describe("New HtmlReporter", function() {
|
||||
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
|
||||
|
||||
expect(alertBars.length).toEqual(1);
|
||||
expect(alertBars[0].getAttribute('class')).toMatch(/jasmine-passed/);
|
||||
expect(alertBars[0].innerHTML).toMatch(/2 specs, 0 failures/);
|
||||
});
|
||||
|
||||
@@ -804,7 +935,7 @@ describe("New HtmlReporter", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("and there are disabled specs", function() {
|
||||
describe("and there are excluded specs", function() {
|
||||
var env, container, reporter, reporterConfig, specStatus;
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
@@ -817,9 +948,9 @@ describe("New HtmlReporter", function() {
|
||||
};
|
||||
specStatus = {
|
||||
id: 123,
|
||||
description: "with a disabled spec",
|
||||
fullName: "A Suite with a disabled spec",
|
||||
status: "disabled",
|
||||
description: "with a excluded spec",
|
||||
fullName: "A Suite with a excluded spec",
|
||||
status: "excluded",
|
||||
passedExpectations: [],
|
||||
failedExpectations: []
|
||||
};
|
||||
@@ -836,10 +967,10 @@ describe("New HtmlReporter", function() {
|
||||
reporter.jasmineDone({});
|
||||
});
|
||||
|
||||
it("shows the disabled spec in the spec list", function() {
|
||||
it("shows the excluded spec in the spec list", function() {
|
||||
var specList = container.querySelector(".jasmine-summary");
|
||||
|
||||
expect(specList.innerHTML).toContain('with a disabled spec');
|
||||
expect(specList.innerHTML).toContain('with a excluded spec');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -854,7 +985,7 @@ describe("New HtmlReporter", function() {
|
||||
reporter.jasmineDone({});
|
||||
});
|
||||
|
||||
it("doesn't show the disabled spec in the spec list", function() {
|
||||
it("doesn't show the excluded spec in the spec list", function() {
|
||||
var specList = container.querySelector(".jasmine-summary");
|
||||
|
||||
expect(specList.innerHTML).toEqual('');
|
||||
@@ -927,16 +1058,24 @@ describe("New HtmlReporter", function() {
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||
reporter.suiteStarted({
|
||||
id: 1,
|
||||
description: "A suite"
|
||||
});
|
||||
reporter.suiteStarted({
|
||||
id: 2,
|
||||
description: "inner suite"
|
||||
});
|
||||
|
||||
var passingResult = {id: 123, status: "passed", passedExpectations: [{passed: true}], failedExpectations: []};
|
||||
reporter.specStarted(passingResult);
|
||||
reporter.specDone(passingResult);
|
||||
var passingSpecResult = {id: 123, status: "passed", passedExpectations: [{passed: true}], failedExpectations: []};
|
||||
reporter.specStarted(passingSpecResult);
|
||||
reporter.specDone(passingSpecResult);
|
||||
|
||||
var failingResult = {
|
||||
var failingSpecResult = {
|
||||
id: 124,
|
||||
status: "failed",
|
||||
description: "a failing spec",
|
||||
fullName: "a suite with a failing spec",
|
||||
fullName: "a suite inner suite a failing spec",
|
||||
passedExpectations: [],
|
||||
failedExpectations: [
|
||||
{
|
||||
@@ -945,39 +1084,83 @@ describe("New HtmlReporter", function() {
|
||||
}
|
||||
]
|
||||
};
|
||||
reporter.specStarted(failingResult);
|
||||
reporter.specDone(failingResult);
|
||||
|
||||
var passingSuiteResult = {
|
||||
id: 1,
|
||||
description: "A suite"
|
||||
};
|
||||
var failingSuiteResult = {
|
||||
id: 2,
|
||||
description: 'a suite',
|
||||
fullName: 'a suite',
|
||||
status: 'failed',
|
||||
failedExpectations: [{ message: 'My After All Exception' }]
|
||||
};
|
||||
reporter.specStarted(failingSpecResult);
|
||||
reporter.specDone(failingSpecResult);
|
||||
reporter.suiteDone(passingSuiteResult);
|
||||
reporter.suiteDone(failingSuiteResult);
|
||||
reporter.suiteDone(passingSuiteResult);
|
||||
reporter.jasmineDone({});
|
||||
});
|
||||
|
||||
it("reports the specs counts", function() {
|
||||
var alertBar = container.querySelector(".jasmine-alert .jasmine-bar");
|
||||
|
||||
expect(alertBar.getAttribute('class')).toMatch(/jasmine-failed/);
|
||||
expect(alertBar.innerHTML).toMatch(/2 specs, 1 failure/);
|
||||
expect(alertBar.innerHTML).toMatch(/2 specs, 2 failure/);
|
||||
});
|
||||
|
||||
it("reports failure messages and stack traces", function() {
|
||||
var specFailures = container.querySelector(".jasmine-failures");
|
||||
|
||||
var failure = specFailures.childNodes[0];
|
||||
expect(failure.getAttribute("class")).toMatch(/jasmine-failed/);
|
||||
expect(failure.getAttribute("class")).toMatch(/jasmine-spec-detail/);
|
||||
expect(specFailures.childNodes.length).toEqual(2);
|
||||
|
||||
var specDiv = failure.childNodes[0];
|
||||
var specFailure = specFailures.childNodes[0];
|
||||
expect(specFailure.getAttribute("class")).toMatch(/jasmine-failed/);
|
||||
expect(specFailure.getAttribute("class")).toMatch(/jasmine-spec-detail/);
|
||||
|
||||
var specDiv = specFailure.childNodes[0];
|
||||
expect(specDiv.getAttribute("class")).toEqual("jasmine-description");
|
||||
|
||||
var specLink = specDiv.childNodes[0];
|
||||
expect(specLink.getAttribute("title")).toEqual("a suite with a failing spec");
|
||||
expect(specLink.getAttribute("href")).toEqual("?foo=bar&spec=a suite with a failing spec");
|
||||
|
||||
var message = failure.childNodes[1].childNodes[0];
|
||||
var message = specFailure.childNodes[1].childNodes[0];
|
||||
expect(message.getAttribute("class")).toEqual("jasmine-result-message");
|
||||
expect(message.innerHTML).toEqual("a failure message");
|
||||
|
||||
var stackTrace = failure.childNodes[1].childNodes[1];
|
||||
var stackTrace = specFailure.childNodes[1].childNodes[1];
|
||||
expect(stackTrace.getAttribute("class")).toEqual("jasmine-stack-trace");
|
||||
expect(stackTrace.innerHTML).toEqual("a stack trace");
|
||||
|
||||
var suiteFailure = specFailures.childNodes[0];
|
||||
expect(suiteFailure.getAttribute("class")).toMatch(/jasmine-failed/);
|
||||
expect(suiteFailure.getAttribute("class")).toMatch(/jasmine-spec-detail/);
|
||||
|
||||
var suiteDiv = suiteFailure.childNodes[0];
|
||||
expect(suiteDiv.getAttribute("class")).toEqual("jasmine-description");
|
||||
|
||||
var suiteMessage = suiteFailure.childNodes[1].childNodes[0];
|
||||
expect(suiteMessage.getAttribute("class")).toEqual("jasmine-result-message");
|
||||
expect(suiteMessage.innerHTML).toEqual("a failure message");
|
||||
|
||||
var suiteStackTrace = suiteFailure.childNodes[1].childNodes[1];
|
||||
expect(suiteStackTrace.getAttribute("class")).toEqual("jasmine-stack-trace");
|
||||
expect(suiteStackTrace.innerHTML).toEqual("a stack trace");
|
||||
});
|
||||
|
||||
it('provides links to focus on a failure and each containing suite', function() {
|
||||
var description = container.querySelector('.jasmine-failures .jasmine-description');
|
||||
var links = description.querySelectorAll('a');
|
||||
|
||||
expect(description.textContent).toEqual('A suite > inner suite > a failing spec');
|
||||
|
||||
expect(links.length).toEqual(3);
|
||||
expect(links[0].textContent).toEqual('A suite');
|
||||
|
||||
expect(links[0].getAttribute('href')).toMatch(/\?foo=bar&spec=A suite/);
|
||||
|
||||
expect(links[1].textContent).toEqual('inner suite');
|
||||
expect(links[1].getAttribute('href')).toMatch(/\?foo=bar&spec=A suite inner suite/);
|
||||
|
||||
expect(links[2].textContent).toEqual('a failing spec');
|
||||
expect(links[2].getAttribute('href')).toMatch(/\?foo=bar&spec=a suite inner suite a failing spec/);
|
||||
});
|
||||
|
||||
it("allows switching between failure details and the spec summary", function() {
|
||||
@@ -996,4 +1179,83 @@ describe("New HtmlReporter", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("The overall result bar", function() {
|
||||
describe("When the jasmineDone event's overallStatus is 'passed'", function() {
|
||||
it("has class jasmine-passed", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
reporter.jasmineDone({
|
||||
overallStatus: 'passed',
|
||||
failedExpectations: []
|
||||
});
|
||||
|
||||
var alertBar = container.querySelector(".jasmine-overall-result");
|
||||
expect(alertBar).toHaveClass("jasmine-passed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("When the jasmineDone event's overallStatus is 'failed'", function() {
|
||||
it("has class jasmine-failed", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
reporter.jasmineDone({
|
||||
overallStatus: 'failed',
|
||||
failedExpectations: []
|
||||
});
|
||||
|
||||
var alertBar = container.querySelector(".jasmine-overall-result");
|
||||
expect(alertBar).toHaveClass("jasmine-failed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("When the jasmineDone event's overallStatus is 'incomplete'", function() {
|
||||
it("has class jasmine-incomplete", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmineUnderTest.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
reporter.jasmineDone({
|
||||
overallStatus: 'incomplete',
|
||||
incompleteReason: 'because nope',
|
||||
failedExpectations: []
|
||||
});
|
||||
|
||||
var alertBar = container.querySelector(".jasmine-overall-result");
|
||||
expect(alertBar).toHaveClass("jasmine-incomplete");
|
||||
expect(alertBar.textContent).toContain("Incomplete: because nope");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
describe("jasmineUnderTest.pp (HTML Dependent)", function () {
|
||||
it("should stringify HTML nodes properly", function() {
|
||||
var sampleNode = document.createElement('div');
|
||||
sampleNode.innerHTML = 'foo<b>bar</b>';
|
||||
it("should stringify non-element HTML nodes properly", function() {
|
||||
var sampleNode = document.createTextNode("");
|
||||
expect(jasmineUnderTest.pp(sampleNode)).toEqual("HTMLNode");
|
||||
expect(jasmineUnderTest.pp({foo: sampleNode})).toEqual("Object({ foo: HTMLNode })");
|
||||
});
|
||||
|
||||
it("should stringify empty HTML elements as their opening tags", function () {
|
||||
var simple = document.createElement('div');
|
||||
simple.className = 'foo';
|
||||
expect(jasmineUnderTest.pp(simple)).toEqual('<div class="foo">');
|
||||
});
|
||||
|
||||
it("should stringify non-empty HTML elements as tags with placeholders", function() {
|
||||
var nonEmpty = document.createElement('div');
|
||||
nonEmpty.className = 'foo';
|
||||
nonEmpty.innerHTML = '<p>Irrelevant</p>';
|
||||
expect(jasmineUnderTest.pp(nonEmpty)).toEqual('<div class="foo">...</div>');
|
||||
});
|
||||
|
||||
it("should print Firefox's wrapped native objects correctly", function() {
|
||||
if(jasmine.getEnv().firefoxVersion) {
|
||||
try { new CustomEvent(); } catch(e) { var err = e; };
|
||||
|
||||
39
spec/html/SpyRegistryHtmlSpec.js
Normal file
39
spec/html/SpyRegistryHtmlSpec.js
Normal file
@@ -0,0 +1,39 @@
|
||||
describe('Spy Registry browser-specific behavior', function() {
|
||||
function createSpy(name, originalFn) {
|
||||
return jasmineUnderTest.Spy(name, originalFn);
|
||||
}
|
||||
|
||||
it('can spy on and unspy window.onerror', function() {
|
||||
requireWriteableOnerror();
|
||||
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
createSpy: createSpy,
|
||||
global: window
|
||||
}),
|
||||
originalHandler = window.onerror;
|
||||
|
||||
try {
|
||||
spyRegistry.spyOn(window, 'onerror');
|
||||
spyRegistry.clearSpies();
|
||||
expect(window.onerror).toBe(originalHandler);
|
||||
} finally {
|
||||
window.onerror = originalHandler;
|
||||
}
|
||||
});
|
||||
|
||||
function requireWriteableOnerror() {
|
||||
var descriptor;
|
||||
|
||||
try {
|
||||
descriptor = Object.getOwnPropertyDescriptor(window, 'onerror');
|
||||
} catch(e) {
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
}
|
||||
|
||||
if (descriptor && !(descriptor.writable || descriptor.set)) {
|
||||
pending('Browser declares window.onerror to be readonly');
|
||||
}
|
||||
}
|
||||
});
|
||||
48
spec/html/matchers/toHaveClassSpec.js
Normal file
48
spec/html/matchers/toHaveClassSpec.js
Normal file
@@ -0,0 +1,48 @@
|
||||
describe('toHaveClass', function() {
|
||||
it('fails for a DOM element that lacks the expected class', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveClass(),
|
||||
result = matcher.compare(document.createElement('div'), 'foo');
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
});
|
||||
|
||||
it('passes for a DOM element that has the expected class', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveClass(),
|
||||
el = document.createElement('div');
|
||||
|
||||
el.className = 'foo bar baz';
|
||||
|
||||
expect(matcher.compare(el, 'foo').pass).toBe(true);
|
||||
expect(matcher.compare(el, 'bar').pass).toBe(true);
|
||||
expect(matcher.compare(el, 'bar').pass).toBe(true);
|
||||
});
|
||||
|
||||
it('fails for a DOM element that only has other classes', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveClass(),
|
||||
el = document.createElement('div');
|
||||
|
||||
el.className = 'foo bar';
|
||||
|
||||
expect(matcher.compare(el, 'fo').pass).toBe(false);
|
||||
});
|
||||
|
||||
it('throws an exception when actual is not a DOM element', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveClass();
|
||||
|
||||
expect(function() {
|
||||
matcher.compare('x', 'foo');
|
||||
}).toThrowError("'x' is not a DOM element");
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(undefined, 'foo');
|
||||
}).toThrowError('undefined is not a DOM element');
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(document.createTextNode(''), 'foo')
|
||||
}).toThrowError('HTMLNode is not a DOM element');
|
||||
|
||||
expect(function() {
|
||||
matcher.compare({classList: ''}, 'foo');
|
||||
}).toThrowError("Object({ classList: '' }) is not a DOM element");
|
||||
});
|
||||
});
|
||||
@@ -2,11 +2,15 @@
|
||||
"spec_dir": "spec",
|
||||
"spec_files": [
|
||||
"core/**/*.js",
|
||||
"console/**/*.js",
|
||||
"npmPackage/**/*.js"
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/asyncAwait.js",
|
||||
"helpers/checkForMap.js",
|
||||
"helpers/checkForSet.js",
|
||||
"helpers/checkForSymbol.js",
|
||||
"helpers/checkForTypedArrays.js",
|
||||
"helpers/integrationMatchers.js",
|
||||
"helpers/nodeDefineJasmineUnderTest.js"
|
||||
],
|
||||
"random": true
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
src_dir:
|
||||
- 'src'
|
||||
src_files:
|
||||
- 'core/requireCore.js'
|
||||
- 'core/base.js'
|
||||
- 'core/util.js'
|
||||
#end of known dependencies
|
||||
@@ -12,12 +13,17 @@ src_files:
|
||||
- 'core/PrettyPrinter.js'
|
||||
- 'core/Suite.js'
|
||||
- 'core/**/*.js'
|
||||
- 'html/**.js'
|
||||
- 'html/**/*.js'
|
||||
- '**/*.js'
|
||||
stylesheets:
|
||||
helpers:
|
||||
- 'helpers/asyncAwait.js'
|
||||
- 'helpers/BrowserFlags.js'
|
||||
- 'helpers/checkForMap.js'
|
||||
- 'helpers/checkForSet.js'
|
||||
- 'helpers/checkForSymbol.js'
|
||||
- 'helpers/checkForTypedArrays.js'
|
||||
- 'helpers/integrationMatchers.js'
|
||||
- 'helpers/defineJasmineUnderTest.js'
|
||||
spec_files:
|
||||
- '**/*[Ss]pec.js'
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
getJasmineRequireObj().ConsoleReporter = function() {
|
||||
|
||||
var noopTimer = {
|
||||
start: function(){},
|
||||
elapsed: function(){ return 0; }
|
||||
};
|
||||
|
||||
function ConsoleReporter(options) {
|
||||
var print = options.print,
|
||||
showColors = options.showColors || false,
|
||||
onComplete = options.onComplete || function() {},
|
||||
timer = options.timer || noopTimer,
|
||||
specCount,
|
||||
failureCount,
|
||||
failedSpecs = [],
|
||||
pendingCount,
|
||||
ansi = {
|
||||
green: '\x1B[32m',
|
||||
red: '\x1B[31m',
|
||||
yellow: '\x1B[33m',
|
||||
none: '\x1B[0m'
|
||||
},
|
||||
failedSuites = [];
|
||||
|
||||
print('ConsoleReporter is deprecated and will be removed in a future version.');
|
||||
|
||||
this.jasmineStarted = function() {
|
||||
specCount = 0;
|
||||
failureCount = 0;
|
||||
pendingCount = 0;
|
||||
print('Started');
|
||||
printNewline();
|
||||
timer.start();
|
||||
};
|
||||
|
||||
this.jasmineDone = function() {
|
||||
printNewline();
|
||||
for (var i = 0; i < failedSpecs.length; i++) {
|
||||
specFailureDetails(failedSpecs[i]);
|
||||
}
|
||||
|
||||
if(specCount > 0) {
|
||||
printNewline();
|
||||
|
||||
var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' +
|
||||
failureCount + ' ' + plural('failure', failureCount);
|
||||
|
||||
if (pendingCount) {
|
||||
specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount);
|
||||
}
|
||||
|
||||
print(specCounts);
|
||||
} else {
|
||||
print('No specs found');
|
||||
}
|
||||
|
||||
printNewline();
|
||||
var seconds = timer.elapsed() / 1000;
|
||||
print('Finished in ' + seconds + ' ' + plural('second', seconds));
|
||||
printNewline();
|
||||
|
||||
for(i = 0; i < failedSuites.length; i++) {
|
||||
suiteFailureDetails(failedSuites[i]);
|
||||
}
|
||||
|
||||
onComplete(failureCount === 0);
|
||||
};
|
||||
|
||||
this.specDone = function(result) {
|
||||
specCount++;
|
||||
|
||||
if (result.status == 'pending') {
|
||||
pendingCount++;
|
||||
print(colored('yellow', '*'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.status == 'passed') {
|
||||
print(colored('green', '.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.status == 'failed') {
|
||||
failureCount++;
|
||||
failedSpecs.push(result);
|
||||
print(colored('red', 'F'));
|
||||
}
|
||||
};
|
||||
|
||||
this.suiteDone = function(result) {
|
||||
if (result.failedExpectations && result.failedExpectations.length > 0) {
|
||||
failureCount++;
|
||||
failedSuites.push(result);
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
function printNewline() {
|
||||
print('\n');
|
||||
}
|
||||
|
||||
function colored(color, str) {
|
||||
return showColors ? (ansi[color] + str + ansi.none) : str;
|
||||
}
|
||||
|
||||
function plural(str, count) {
|
||||
return count == 1 ? str : str + 's';
|
||||
}
|
||||
|
||||
function repeat(thing, times) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < times; i++) {
|
||||
arr.push(thing);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
function indent(str, spaces) {
|
||||
var lines = (str || '').split('\n');
|
||||
var newArr = [];
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
newArr.push(repeat(' ', spaces).join('') + lines[i]);
|
||||
}
|
||||
return newArr.join('\n');
|
||||
}
|
||||
|
||||
function specFailureDetails(result) {
|
||||
printNewline();
|
||||
print(result.fullName);
|
||||
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
var failedExpectation = result.failedExpectations[i];
|
||||
printNewline();
|
||||
print(indent(failedExpectation.message, 2));
|
||||
print(indent(failedExpectation.stack, 2));
|
||||
}
|
||||
|
||||
printNewline();
|
||||
}
|
||||
|
||||
function suiteFailureDetails(result) {
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
printNewline();
|
||||
print(colored('red', 'An error was thrown in an afterAll'));
|
||||
printNewline();
|
||||
print(colored('red', 'AfterAll ' + result.failedExpectations[i].message));
|
||||
|
||||
}
|
||||
printNewline();
|
||||
}
|
||||
}
|
||||
|
||||
return ConsoleReporter;
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
function getJasmineRequireObj() {
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
return exports;
|
||||
} else {
|
||||
window.jasmineRequire = window.jasmineRequire || {};
|
||||
return window.jasmineRequire;
|
||||
}
|
||||
}
|
||||
|
||||
getJasmineRequireObj().console = function(jRequire, j$) {
|
||||
j$.ConsoleReporter = jRequire.ConsoleReporter();
|
||||
};
|
||||
@@ -7,22 +7,9 @@ getJasmineRequireObj().CallTracker = function(j$) {
|
||||
var calls = [];
|
||||
var opts = {};
|
||||
|
||||
function argCloner(context) {
|
||||
var clonedArgs = [];
|
||||
var argsAsArray = j$.util.argsToArray(context.args);
|
||||
for(var i = 0; i < argsAsArray.length; i++) {
|
||||
if(Object.prototype.toString.apply(argsAsArray[i]).match(/^\[object/)) {
|
||||
clonedArgs.push(j$.util.clone(argsAsArray[i]));
|
||||
} else {
|
||||
clonedArgs.push(argsAsArray[i]);
|
||||
}
|
||||
}
|
||||
context.args = clonedArgs;
|
||||
}
|
||||
|
||||
this.track = function(context) {
|
||||
if(opts.cloneArgs) {
|
||||
argCloner(context);
|
||||
context.args = j$.util.cloneArgs(context.args);
|
||||
}
|
||||
calls.push(context);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
getJasmineRequireObj().clearStack = function(j$) {
|
||||
function messageChannelImpl(global) {
|
||||
var maxInlineCallCount = 10;
|
||||
|
||||
function messageChannelImpl(global, setTimeout) {
|
||||
var channel = new global.MessageChannel(),
|
||||
head = {},
|
||||
tail = head;
|
||||
@@ -22,25 +24,44 @@ getJasmineRequireObj().clearStack = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
var currentCallCount = 0;
|
||||
return function clearStack(fn) {
|
||||
tail = tail.next = { task: fn };
|
||||
channel.port2.postMessage(0);
|
||||
currentCallCount++;
|
||||
|
||||
if (currentCallCount < maxInlineCallCount) {
|
||||
tail = tail.next = { task: fn };
|
||||
channel.port2.postMessage(0);
|
||||
} else {
|
||||
currentCallCount = 0;
|
||||
setTimeout(fn);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getClearStack(global) {
|
||||
var currentCallCount = 0;
|
||||
var realSetTimeout = global.setTimeout;
|
||||
var setTimeoutImpl = function clearStack(fn) {
|
||||
Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]);
|
||||
};
|
||||
|
||||
if (j$.isFunction_(global.setImmediate)) {
|
||||
var realSetImmediate = global.setImmediate;
|
||||
return function(fn) {
|
||||
realSetImmediate(fn);
|
||||
currentCallCount++;
|
||||
|
||||
if (currentCallCount < maxInlineCallCount) {
|
||||
realSetImmediate(fn);
|
||||
} else {
|
||||
currentCallCount = 0;
|
||||
|
||||
setTimeoutImpl(fn);
|
||||
}
|
||||
};
|
||||
} else if (!j$.util.isUndefined(global.MessageChannel)) {
|
||||
return messageChannelImpl(global);
|
||||
return messageChannelImpl(global, setTimeoutImpl);
|
||||
} else {
|
||||
var realSetTimeout = global.setTimeout;
|
||||
return function clearStack(fn) {
|
||||
Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]);
|
||||
};
|
||||
return setTimeoutImpl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
getJasmineRequireObj().Clock = function() {
|
||||
|
||||
var NODE_JS = typeof process !== 'undefined' && process.versions && typeof process.versions.node === 'string';
|
||||
|
||||
/**
|
||||
* _Note:_ Do not construct this directly, Jasmine will make one during booting. You can get the current clock with {@link jasmine.clock}.
|
||||
* @class Clock
|
||||
@@ -22,6 +25,7 @@ getJasmineRequireObj().Clock = function() {
|
||||
delayedFunctionScheduler,
|
||||
timer;
|
||||
|
||||
self.FakeTimeout = FakeTimeout;
|
||||
|
||||
/**
|
||||
* Install the mock clock over the built-in methods.
|
||||
@@ -83,22 +87,10 @@ getJasmineRequireObj().Clock = function() {
|
||||
};
|
||||
|
||||
self.setTimeout = function(fn, delay, params) {
|
||||
if (legacyIE()) {
|
||||
if (arguments.length > 2) {
|
||||
throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill');
|
||||
}
|
||||
return timer.setTimeout(fn, delay);
|
||||
}
|
||||
return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]);
|
||||
};
|
||||
|
||||
self.setInterval = function(fn, delay, params) {
|
||||
if (legacyIE()) {
|
||||
if (arguments.length > 2) {
|
||||
throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill');
|
||||
}
|
||||
return timer.setInterval(fn, delay);
|
||||
}
|
||||
return Function.prototype.apply.apply(timer.setInterval, [global, arguments]);
|
||||
};
|
||||
|
||||
@@ -133,11 +125,6 @@ getJasmineRequireObj().Clock = function() {
|
||||
global.clearInterval === realTimingFunctions.clearInterval;
|
||||
}
|
||||
|
||||
function legacyIE() {
|
||||
//if these methods are polyfilled, apply will be present
|
||||
return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply;
|
||||
}
|
||||
|
||||
function replace(dest, source) {
|
||||
for (var prop in source) {
|
||||
dest[prop] = source[prop];
|
||||
@@ -145,7 +132,15 @@ getJasmineRequireObj().Clock = function() {
|
||||
}
|
||||
|
||||
function setTimeout(fn, delay) {
|
||||
return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2));
|
||||
if (!NODE_JS) {
|
||||
return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2));
|
||||
}
|
||||
|
||||
var timeout = new FakeTimeout();
|
||||
|
||||
delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2), false, timeout);
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
function clearTimeout(id) {
|
||||
@@ -153,7 +148,15 @@ getJasmineRequireObj().Clock = function() {
|
||||
}
|
||||
|
||||
function setInterval(fn, interval) {
|
||||
return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true);
|
||||
if (!NODE_JS) {
|
||||
return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true);
|
||||
}
|
||||
|
||||
var timeout = new FakeTimeout();
|
||||
|
||||
delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true, timeout);
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
function clearInterval(id) {
|
||||
@@ -165,5 +168,18 @@ getJasmineRequireObj().Clock = function() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks Node.js Timeout class
|
||||
*/
|
||||
function FakeTimeout() {}
|
||||
|
||||
FakeTimeout.prototype.ref = function () {
|
||||
return this;
|
||||
};
|
||||
|
||||
FakeTimeout.prototype.unref = function () {
|
||||
return this;
|
||||
};
|
||||
|
||||
return Clock;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
getJasmineRequireObj().DelayedFunctionScheduler = function() {
|
||||
getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
||||
function DelayedFunctionScheduler() {
|
||||
var self = this;
|
||||
var scheduledLookup = [];
|
||||
var scheduledFunctions = {};
|
||||
var currentTime = 0;
|
||||
var delayedFnCount = 0;
|
||||
var deletedKeys = [];
|
||||
|
||||
self.tick = function(millis, tickDate) {
|
||||
millis = millis || 0;
|
||||
@@ -51,6 +52,8 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
|
||||
};
|
||||
|
||||
self.removeFunctionWithId = function(timeoutKey) {
|
||||
deletedKeys.push(timeoutKey);
|
||||
|
||||
for (var runAtMillis in scheduledFunctions) {
|
||||
var funcs = scheduledFunctions[runAtMillis];
|
||||
var i = indexOfFirstToPass(funcs, function (func) {
|
||||
@@ -121,12 +124,14 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
|
||||
}
|
||||
|
||||
do {
|
||||
deletedKeys = [];
|
||||
var newCurrentTime = scheduledLookup.shift();
|
||||
tickDate(newCurrentTime - currentTime);
|
||||
|
||||
currentTime = newCurrentTime;
|
||||
|
||||
var funcsToRun = scheduledFunctions[currentTime];
|
||||
|
||||
delete scheduledFunctions[currentTime];
|
||||
|
||||
forEachFunction(funcsToRun, function(funcToRun) {
|
||||
@@ -136,8 +141,13 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
|
||||
});
|
||||
|
||||
forEachFunction(funcsToRun, function(funcToRun) {
|
||||
if (j$.util.arrayContains(deletedKeys, funcToRun.timeoutKey)) {
|
||||
// skip a timeoutKey deleted whilst we were running
|
||||
return;
|
||||
}
|
||||
funcToRun.funcToCall.apply(null, funcToRun.params || []);
|
||||
});
|
||||
deletedKeys = [];
|
||||
} while (scheduledLookup.length > 0 &&
|
||||
// checking first if we're out of time prevents setTimeout(0)
|
||||
// scheduled in a funcToRun from forcing an extra iteration
|
||||
|
||||
313
src/core/Env.js
313
src/core/Env.js
@@ -13,8 +13,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var totalSpecsDefined = 0;
|
||||
|
||||
var catchExceptions = true;
|
||||
|
||||
var realSetTimeout = j$.getGlobal().setTimeout;
|
||||
var realClearTimeout = j$.getGlobal().clearTimeout;
|
||||
var clearStack = j$.getClearStack(j$.getGlobal());
|
||||
@@ -26,8 +24,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var currentlyExecutingSuites = [];
|
||||
var currentDeclarationSuite = null;
|
||||
var throwOnExpectationFailure = false;
|
||||
var random = false;
|
||||
var stopOnSpecFailure = false;
|
||||
var random = true;
|
||||
var seed = null;
|
||||
var handlingLoadErrors = true;
|
||||
var hasFailures = false;
|
||||
|
||||
var currentSuite = function() {
|
||||
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
||||
@@ -37,21 +38,29 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return currentSpec || currentSuite();
|
||||
};
|
||||
|
||||
var reporter = new j$.ReportDispatcher([
|
||||
'jasmineStarted',
|
||||
'jasmineDone',
|
||||
'suiteStarted',
|
||||
'suiteDone',
|
||||
'specStarted',
|
||||
'specDone'
|
||||
]);
|
||||
|
||||
var globalErrors = new j$.GlobalErrors();
|
||||
globalErrors.install();
|
||||
globalErrors.pushListener(function(message, filename, lineno) {
|
||||
topSuite.result.failedExpectations.push({
|
||||
passed: false,
|
||||
globalErrorType: 'load',
|
||||
message: message,
|
||||
filename: filename,
|
||||
lineno: lineno
|
||||
});
|
||||
});
|
||||
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
this.addSpyStrategy = function(name, fn) {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Custom spy strategies must be added in a before function or a spec');
|
||||
}
|
||||
runnableResources[currentRunnable().id].customSpyStrategies[name] = fn;
|
||||
};
|
||||
|
||||
this.addCustomEqualityTester = function(tester) {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Custom Equalities must be added in a before function or a spec');
|
||||
@@ -96,7 +105,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
var defaultResourcesForRunnable = function(id, parentRunnableId) {
|
||||
var resources = {spies: [], customEqualityTesters: [], customMatchers: {}};
|
||||
var resources = {spies: [], customEqualityTesters: [], customMatchers: {}, customSpyStrategies: {}};
|
||||
|
||||
if(runnableResources[parentRunnableId]){
|
||||
resources.customEqualityTesters = j$.util.clone(runnableResources[parentRunnableId].customEqualityTesters);
|
||||
@@ -150,23 +159,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return buildExpectationResult(attrs);
|
||||
};
|
||||
|
||||
// TODO: fix this naming, and here's where the value comes in
|
||||
this.catchExceptions = function(value) {
|
||||
catchExceptions = !!value;
|
||||
return catchExceptions;
|
||||
};
|
||||
|
||||
this.catchingExceptions = function() {
|
||||
return catchExceptions;
|
||||
};
|
||||
|
||||
var maximumSpecCallbackDepth = 20;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
|
||||
var catchException = function(e) {
|
||||
return j$.Spec.isPendingSpecException(e) || catchExceptions;
|
||||
};
|
||||
|
||||
this.throwOnExpectationFailure = function(value) {
|
||||
throwOnExpectationFailure = !!value;
|
||||
};
|
||||
@@ -175,6 +170,14 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return throwOnExpectationFailure;
|
||||
};
|
||||
|
||||
this.stopOnSpecFailure = function(value) {
|
||||
stopOnSpecFailure = !!value;
|
||||
};
|
||||
|
||||
this.stoppingOnSpecFailure = function() {
|
||||
return stopOnSpecFailure;
|
||||
};
|
||||
|
||||
this.randomizeTests = function(value) {
|
||||
random = !!value;
|
||||
};
|
||||
@@ -190,14 +193,39 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return seed;
|
||||
};
|
||||
|
||||
var queueRunnerFactory = function(options) {
|
||||
options.catchException = catchException;
|
||||
this.suppressLoadErrors = function() {
|
||||
if (handlingLoadErrors) {
|
||||
globalErrors.popListener();
|
||||
}
|
||||
handlingLoadErrors = false;
|
||||
};
|
||||
|
||||
this.deprecated = function(msg) {
|
||||
var runnable = currentRunnable() || topSuite;
|
||||
runnable.addDeprecationWarning(msg);
|
||||
if(typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
|
||||
console.error('DEPRECATION: ' + msg);
|
||||
}
|
||||
};
|
||||
|
||||
var queueRunnerFactory = function(options, args) {
|
||||
var failFast = false;
|
||||
if (options.isLeaf) {
|
||||
failFast = throwOnExpectationFailure;
|
||||
} else if (!options.isReporter) {
|
||||
failFast = stopOnSpecFailure;
|
||||
}
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||
options.fail = self.fail;
|
||||
options.globalErrors = globalErrors;
|
||||
options.completeOnFirstError = failFast;
|
||||
options.onException = options.onException || function(e) {
|
||||
(currentRunnable() || topSuite).onException(e);
|
||||
};
|
||||
options.deprecated = self.deprecated;
|
||||
|
||||
new j$.QueueRunner(options).execute();
|
||||
new j$.QueueRunner(options).execute(args);
|
||||
};
|
||||
|
||||
var topSuite = new j$.Suite({
|
||||
@@ -214,7 +242,63 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return topSuite;
|
||||
};
|
||||
|
||||
/**
|
||||
* This represents the available reporter callback for an object passed to {@link Env#addReporter}.
|
||||
* @interface Reporter
|
||||
*/
|
||||
var reporter = new j$.ReportDispatcher([
|
||||
/**
|
||||
* `jasmineStarted` is called after all of the specs have been loaded, but just before execution starts.
|
||||
* @function
|
||||
* @name Reporter#jasmineStarted
|
||||
* @param {JasmineStartedInfo} suiteInfo Information about the full Jasmine suite that is being run
|
||||
*/
|
||||
'jasmineStarted',
|
||||
/**
|
||||
* When the entire suite has finished execution `jasmineDone` is called
|
||||
* @function
|
||||
* @name Reporter#jasmineDone
|
||||
* @param {JasmineDoneInfo} suiteInfo Information about the full Jasmine suite that just finished running.
|
||||
*/
|
||||
'jasmineDone',
|
||||
/**
|
||||
* `suiteStarted` is invoked when a `describe` starts to run
|
||||
* @function
|
||||
* @name Reporter#suiteStarted
|
||||
* @param {SuiteResult} result Information about the individual {@link describe} being run
|
||||
*/
|
||||
'suiteStarted',
|
||||
/**
|
||||
* `suiteDone` is invoked when all of the child specs and suites for a given suite have been run
|
||||
*
|
||||
* While jasmine doesn't require any specific functions, not defining a `suiteDone` will make it impossible for a reporter to know when a suite has failures in an `afterAll`.
|
||||
* @function
|
||||
* @name Reporter#suiteDone
|
||||
* @param {SuiteResult} result
|
||||
*/
|
||||
'suiteDone',
|
||||
/**
|
||||
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
|
||||
* @function
|
||||
* @name Reporter#specStarted
|
||||
* @param {SpecResult} result Information about the individual {@link it} being run
|
||||
*/
|
||||
'specStarted',
|
||||
/**
|
||||
* `specDone` is invoked when an `it` and its associated `beforeEach` and `afterEach` functions have been run.
|
||||
*
|
||||
* While jasmine doesn't require any specific functions, not defining a `specDone` will make it impossible for a reporter to know when a spec has failed.
|
||||
* @function
|
||||
* @name Reporter#specDone
|
||||
* @param {SpecResult} result
|
||||
*/
|
||||
'specDone'
|
||||
], queueRunnerFactory);
|
||||
|
||||
this.execute = function(runnablesToRun) {
|
||||
var self = this;
|
||||
this.suppressLoadErrors();
|
||||
|
||||
if(!runnablesToRun) {
|
||||
if (focusedRunnables.length) {
|
||||
runnablesToRun = focusedRunnables;
|
||||
@@ -232,24 +316,30 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
tree: topSuite,
|
||||
runnableIds: runnablesToRun,
|
||||
queueRunnerFactory: queueRunnerFactory,
|
||||
nodeStart: function(suite) {
|
||||
nodeStart: function(suite, next) {
|
||||
currentlyExecutingSuites.push(suite);
|
||||
defaultResourcesForRunnable(suite.id, suite.parentSuite.id);
|
||||
reporter.suiteStarted(suite.result);
|
||||
reporter.suiteStarted(suite.result, next);
|
||||
},
|
||||
nodeComplete: function(suite, result) {
|
||||
nodeComplete: function(suite, result, next) {
|
||||
if (suite !== currentSuite()) {
|
||||
throw new Error('Tried to complete the wrong suite');
|
||||
}
|
||||
|
||||
if (!suite.markedPending) {
|
||||
clearResourcesForRunnable(suite.id);
|
||||
}
|
||||
clearResourcesForRunnable(suite.id);
|
||||
currentlyExecutingSuites.pop();
|
||||
reporter.suiteDone(result);
|
||||
|
||||
if (result.status === 'failed') {
|
||||
hasFailures = true;
|
||||
}
|
||||
|
||||
reporter.suiteDone(result, next);
|
||||
},
|
||||
orderChildren: function(node) {
|
||||
return order.sort(node.children);
|
||||
},
|
||||
excludeNode: function(spec) {
|
||||
return !self.specFilter(spec);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -257,21 +347,51 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
throw new Error('Invalid order: would cause a beforeAll or afterAll to be run multiple times');
|
||||
}
|
||||
|
||||
/**
|
||||
* Information passed to the {@link Reporter#jasmineStarted} event.
|
||||
* @typedef JasmineStartedInfo
|
||||
* @property {Int} totalSpecsDefined - The total number of specs defined in this suite.
|
||||
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
|
||||
*/
|
||||
reporter.jasmineStarted({
|
||||
totalSpecsDefined: totalSpecsDefined
|
||||
});
|
||||
totalSpecsDefined: totalSpecsDefined,
|
||||
order: order
|
||||
}, function() {
|
||||
currentlyExecutingSuites.push(topSuite);
|
||||
|
||||
currentlyExecutingSuites.push(topSuite);
|
||||
processor.execute(function () {
|
||||
clearResourcesForRunnable(topSuite.id);
|
||||
currentlyExecutingSuites.pop();
|
||||
var overallStatus, incompleteReason;
|
||||
|
||||
globalErrors.install();
|
||||
processor.execute(function() {
|
||||
clearResourcesForRunnable(topSuite.id);
|
||||
currentlyExecutingSuites.pop();
|
||||
globalErrors.uninstall();
|
||||
if (hasFailures || topSuite.result.failedExpectations.length > 0) {
|
||||
overallStatus = 'failed';
|
||||
} else if (focusedRunnables.length > 0) {
|
||||
overallStatus = 'incomplete';
|
||||
incompleteReason = 'fit() or fdescribe() was found';
|
||||
} else if (totalSpecsDefined === 0) {
|
||||
overallStatus = 'incomplete';
|
||||
incompleteReason = 'No specs found';
|
||||
} else {
|
||||
overallStatus = 'passed';
|
||||
}
|
||||
|
||||
reporter.jasmineDone({
|
||||
order: order,
|
||||
failedExpectations: topSuite.result.failedExpectations
|
||||
/**
|
||||
* Information passed to the {@link Reporter#jasmineDone} event.
|
||||
* @typedef JasmineDoneInfo
|
||||
* @property {OverallStatus} - The overall result of the sute: 'passed', 'failed', or 'incomplete'.
|
||||
* @property {IncompleteReason} - Explanation of why the suite was incimplete.
|
||||
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
|
||||
* @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
|
||||
* @property {Expectation[]} deprecationWarnings - List of deprecation warnings that occurred at the global level.
|
||||
*/
|
||||
reporter.jasmineDone({
|
||||
overallStatus: overallStatus,
|
||||
incompleteReason: incompleteReason,
|
||||
order: order,
|
||||
failedExpectations: topSuite.result.failedExpectations,
|
||||
deprecationWarnings: topSuite.result.deprecationWarnings
|
||||
}, function() {});
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -280,6 +400,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
* Add a custom reporter to the Jasmine environment.
|
||||
* @name Env#addReporter
|
||||
* @function
|
||||
* @param {Reporter} reporterToAdd The reporter to be added.
|
||||
* @see custom_reporter
|
||||
*/
|
||||
this.addReporter = function(reporterToAdd) {
|
||||
@@ -294,12 +415,27 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
reporter.clearReporters();
|
||||
};
|
||||
|
||||
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Spies must be created in a before function or a spec');
|
||||
var spyFactory = new j$.SpyFactory(function() {
|
||||
var runnable = currentRunnable();
|
||||
|
||||
if (runnable) {
|
||||
return runnableResources[runnable.id].customSpyStrategies;
|
||||
}
|
||||
return runnableResources[currentRunnable().id].spies;
|
||||
}});
|
||||
|
||||
return {};
|
||||
});
|
||||
|
||||
var spyRegistry = new j$.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
if(!currentRunnable()) {
|
||||
throw new Error('Spies must be created in a before function or a spec');
|
||||
}
|
||||
return runnableResources[currentRunnable().id].spies;
|
||||
},
|
||||
createSpy: function(name, originalFn) {
|
||||
return self.createSpy(name, originalFn);
|
||||
}
|
||||
});
|
||||
|
||||
this.allowRespy = function(allow){
|
||||
spyRegistry.allowRespy(allow);
|
||||
@@ -313,12 +449,33 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return spyRegistry.spyOnProperty.apply(spyRegistry, arguments);
|
||||
};
|
||||
|
||||
this.createSpy = function(name, originalFn) {
|
||||
return spyFactory.createSpy(name, originalFn);
|
||||
};
|
||||
|
||||
this.createSpyObj = function(baseName, methodNames) {
|
||||
return spyFactory.createSpyObj(baseName, methodNames);
|
||||
};
|
||||
|
||||
var ensureIsFunction = function(fn, caller) {
|
||||
if (!j$.isFunction_(fn)) {
|
||||
throw new Error(caller + ' expects a function argument; received ' + j$.getType_(fn));
|
||||
}
|
||||
};
|
||||
|
||||
var ensureIsFunctionOrAsync = function(fn, caller) {
|
||||
if (!j$.isFunction_(fn) && !j$.isAsyncFunction_(fn)) {
|
||||
throw new Error(caller + ' expects a function argument; received ' + j$.getType_(fn));
|
||||
}
|
||||
};
|
||||
|
||||
function ensureIsNotNested(method) {
|
||||
var runnable = currentRunnable();
|
||||
if (runnable !== null && runnable !== undefined) {
|
||||
throw new Error('\'' + method + '\' should only be used in \'describe\' function');
|
||||
}
|
||||
}
|
||||
|
||||
var suiteFactory = function(description) {
|
||||
var suite = new j$.Suite({
|
||||
env: self,
|
||||
@@ -334,6 +491,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.describe = function(description, specDefinitions) {
|
||||
ensureIsNotNested('describe');
|
||||
ensureIsFunction(specDefinitions, 'describe');
|
||||
var suite = suiteFactory(description);
|
||||
if (specDefinitions.length > 0) {
|
||||
@@ -347,6 +505,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.xdescribe = function(description, specDefinitions) {
|
||||
ensureIsNotNested('xdescribe');
|
||||
ensureIsFunction(specDefinitions, 'xdescribe');
|
||||
var suite = suiteFactory(description);
|
||||
suite.pend();
|
||||
@@ -357,6 +516,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var focusedRunnables = [];
|
||||
|
||||
this.fdescribe = function(description, specDefinitions) {
|
||||
ensureIsNotNested('fdescribe');
|
||||
ensureIsFunction(specDefinitions, 'fdescribe');
|
||||
var suite = suiteFactory(description);
|
||||
suite.isFocused = true;
|
||||
@@ -381,9 +541,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
|
||||
if (declarationError) {
|
||||
self.it('encountered a declaration exception', function() {
|
||||
throw declarationError;
|
||||
});
|
||||
suite.onException(declarationError);
|
||||
}
|
||||
|
||||
currentDeclarationSuite = parentSuite;
|
||||
@@ -434,30 +592,32 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
throwOnExpectationFailure: throwOnExpectationFailure
|
||||
});
|
||||
|
||||
if (!self.specFilter(spec)) {
|
||||
spec.disable();
|
||||
}
|
||||
|
||||
return spec;
|
||||
|
||||
function specResultCallback(result) {
|
||||
function specResultCallback(result, next) {
|
||||
clearResourcesForRunnable(spec.id);
|
||||
currentSpec = null;
|
||||
reporter.specDone(result);
|
||||
|
||||
if (result.status === 'failed') {
|
||||
hasFailures = true;
|
||||
}
|
||||
|
||||
reporter.specDone(result, next);
|
||||
}
|
||||
|
||||
function specStarted(spec) {
|
||||
function specStarted(spec, next) {
|
||||
currentSpec = spec;
|
||||
defaultResourcesForRunnable(spec.id, suite.id);
|
||||
reporter.specStarted(spec.result);
|
||||
reporter.specStarted(spec.result, next);
|
||||
}
|
||||
};
|
||||
|
||||
this.it = function(description, fn, timeout) {
|
||||
ensureIsNotNested('it');
|
||||
// it() sometimes doesn't have a fn argument, so only check the type if
|
||||
// it's given.
|
||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||
ensureIsFunction(fn, 'it');
|
||||
ensureIsFunctionOrAsync(fn, 'it');
|
||||
}
|
||||
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||
if (currentDeclarationSuite.markedPending) {
|
||||
@@ -468,10 +628,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.xit = function(description, fn, timeout) {
|
||||
ensureIsNotNested('xit');
|
||||
// xit(), like it(), doesn't always have a fn argument, so only check the
|
||||
// type when needed.
|
||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||
ensureIsFunction(fn, 'xit');
|
||||
ensureIsFunctionOrAsync(fn, 'xit');
|
||||
}
|
||||
var spec = this.it.apply(this, arguments);
|
||||
spec.pend('Temporarily disabled with xit');
|
||||
@@ -479,7 +640,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.fit = function(description, fn, timeout){
|
||||
ensureIsFunction(fn, 'fit');
|
||||
ensureIsNotNested('fit');
|
||||
ensureIsFunctionOrAsync(fn, 'fit');
|
||||
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
|
||||
currentDeclarationSuite.addChild(spec);
|
||||
focusedRunnables.push(spec.id);
|
||||
@@ -496,7 +658,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||
ensureIsFunction(beforeEachFunction, 'beforeEach');
|
||||
ensureIsNotNested('beforeEach');
|
||||
ensureIsFunctionOrAsync(beforeEachFunction, 'beforeEach');
|
||||
currentDeclarationSuite.beforeEach({
|
||||
fn: beforeEachFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
@@ -504,7 +667,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.beforeAll = function(beforeAllFunction, timeout) {
|
||||
ensureIsFunction(beforeAllFunction, 'beforeAll');
|
||||
ensureIsNotNested('beforeAll');
|
||||
ensureIsFunctionOrAsync(beforeAllFunction, 'beforeAll');
|
||||
currentDeclarationSuite.beforeAll({
|
||||
fn: beforeAllFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
@@ -512,7 +676,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.afterEach = function(afterEachFunction, timeout) {
|
||||
ensureIsFunction(afterEachFunction, 'afterEach');
|
||||
ensureIsNotNested('afterEach');
|
||||
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach');
|
||||
afterEachFunction.isCleanup = true;
|
||||
currentDeclarationSuite.afterEach({
|
||||
fn: afterEachFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
@@ -520,7 +686,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.afterAll = function(afterAllFunction, timeout) {
|
||||
ensureIsFunction(afterAllFunction, 'afterAll');
|
||||
ensureIsNotNested('afterAll');
|
||||
ensureIsFunctionOrAsync(afterAllFunction, 'afterAll');
|
||||
currentDeclarationSuite.afterAll({
|
||||
fn: afterAllFunction,
|
||||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
|
||||
@@ -561,6 +728,10 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
message: message,
|
||||
error: error && error.message ? error : null
|
||||
});
|
||||
|
||||
if (self.throwingExpectationFailures()) {
|
||||
throw new Error(message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
getJasmineRequireObj().ExceptionFormatter = function() {
|
||||
function ExceptionFormatter() {
|
||||
getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
||||
|
||||
function ExceptionFormatter(options) {
|
||||
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile();
|
||||
this.message = function(error) {
|
||||
var message = '';
|
||||
|
||||
@@ -21,8 +23,34 @@ getJasmineRequireObj().ExceptionFormatter = function() {
|
||||
};
|
||||
|
||||
this.stack = function(error) {
|
||||
return error ? error.stack : null;
|
||||
if (!error || !error.stack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var stackTrace = new j$.StackTrace(error.stack);
|
||||
var lines = filterJasmine(stackTrace);
|
||||
|
||||
if (stackTrace.message) {
|
||||
lines.unshift(stackTrace.message);
|
||||
}
|
||||
|
||||
return lines.join('\n');
|
||||
};
|
||||
|
||||
function filterJasmine(stackTrace) {
|
||||
var result = [],
|
||||
jasmineMarker = stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
|
||||
|
||||
stackTrace.frames.forEach(function(frame) {
|
||||
if (frame.file && frame.file !== jasmineFile) {
|
||||
result.push(frame.raw);
|
||||
} else if (result[result.length - 1] !== jasmineMarker) {
|
||||
result.push(jasmineMarker);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ExceptionFormatter;
|
||||
|
||||
@@ -4,6 +4,15 @@ getJasmineRequireObj().buildExpectationResult = function() {
|
||||
var messageFormatter = options.messageFormatter || function() {},
|
||||
stackFormatter = options.stackFormatter || function() {};
|
||||
|
||||
/**
|
||||
* @typedef Expectation
|
||||
* @property {String} matcherName - The name of the matcher that was executed for this expectation.
|
||||
* @property {String} message - The failure message for the expectation.
|
||||
* @property {String} stack - The stack trace for the failure if available.
|
||||
* @property {Boolean} passed - Whether the expectation passed or failed.
|
||||
* @property {Object} expected - If the expectation failed, what was the expected value.
|
||||
* @property {Object} actual - If the expectation failed, what actual value was produced.
|
||||
*/
|
||||
var result = {
|
||||
matcherName: options.matcherName,
|
||||
message: message(),
|
||||
|
||||
@@ -13,8 +13,6 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
this.uninstall = function noop() {};
|
||||
|
||||
this.install = function install() {
|
||||
if (global.process && global.process.listeners && j$.isFunction_(global.process.on)) {
|
||||
var originalHandlers = global.process.listeners('uncaughtException');
|
||||
|
||||
@@ -6,11 +6,10 @@ getJasmineRequireObj().JsApiReporter = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* _Note:_ Do not construct this directly, use the global `jsApiReporter` to retrieve the instantiated object.
|
||||
*
|
||||
* @name jsApiReporter
|
||||
* @classdesc Reporter added by default in `boot.js` to record results for retrieval in javascript code.
|
||||
* @classdesc {@link Reporter} added by default in `boot.js` to record results for retrieval in javascript code. An instance is made available as `jsApiReporter` on the global object.
|
||||
* @class
|
||||
* @hideconstructor
|
||||
*/
|
||||
function JsApiReporter(options) {
|
||||
var timer = options.timer || noopTimer,
|
||||
@@ -64,7 +63,7 @@ getJasmineRequireObj().JsApiReporter = function() {
|
||||
* @function
|
||||
* @param {Number} index - The position in the suites list to start from.
|
||||
* @param {Number} length - Maximum number of suite results to return.
|
||||
* @return {Object[]}
|
||||
* @return {SuiteResult[]}
|
||||
*/
|
||||
this.suiteResults = function(index, length) {
|
||||
return suites.slice(index, index + length);
|
||||
@@ -79,7 +78,7 @@ getJasmineRequireObj().JsApiReporter = function() {
|
||||
* Get all of the suites in a single object, with their `id` as the key.
|
||||
* @name jsApiReporter#suites
|
||||
* @function
|
||||
* @return {Object}
|
||||
* @return {Object} - Map of suite id to {@link SuiteResult}
|
||||
*/
|
||||
this.suites = function() {
|
||||
return suites_hash;
|
||||
@@ -99,7 +98,7 @@ getJasmineRequireObj().JsApiReporter = function() {
|
||||
* @function
|
||||
* @param {Number} index - The position in the specs list to start from.
|
||||
* @param {Number} length - Maximum number of specs results to return.
|
||||
* @return {Object[]}
|
||||
* @return {SpecResult[]}
|
||||
*/
|
||||
this.specResults = function(index, length) {
|
||||
return specs.slice(index, index + length);
|
||||
@@ -109,7 +108,7 @@ getJasmineRequireObj().JsApiReporter = function() {
|
||||
* Get all spec results.
|
||||
* @name jsApiReporter#specs
|
||||
* @function
|
||||
* @return {Object[]}
|
||||
* @return {SpecResult[]}
|
||||
*/
|
||||
this.specs = function() {
|
||||
return specs;
|
||||
|
||||
@@ -3,12 +3,14 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
function PrettyPrinter() {
|
||||
this.ppNestLevel_ = 0;
|
||||
this.seen = [];
|
||||
this.length = 0;
|
||||
this.stringParts = [];
|
||||
}
|
||||
|
||||
function hasCustomToString(value) {
|
||||
// value.toString !== Object.prototype.toString if value has no custom toString but is from another context (e.g.
|
||||
// iframe, web worker)
|
||||
return value.toString !== Object.prototype.toString && (value.toString() !== Object.prototype.toString.call(value));
|
||||
return j$.isFunction_(value.toString) && value.toString !== Object.prototype.toString && (value.toString() !== Object.prototype.toString.call(value));
|
||||
}
|
||||
|
||||
PrettyPrinter.prototype.format = function(value) {
|
||||
@@ -27,17 +29,23 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
} else if (typeof value === 'string') {
|
||||
this.emitString(value);
|
||||
} else if (j$.isSpy(value)) {
|
||||
this.emitScalar('spy on ' + value.and.identity());
|
||||
this.emitScalar('spy on ' + value.and.identity);
|
||||
} else if (value instanceof RegExp) {
|
||||
this.emitScalar(value.toString());
|
||||
} else if (typeof value === 'function') {
|
||||
this.emitScalar('Function');
|
||||
} else if (value.nodeType === 1) {
|
||||
this.emitDomElement(value);
|
||||
} else if (typeof value.nodeType === 'number') {
|
||||
this.emitScalar('HTMLNode');
|
||||
} else if (value instanceof Date) {
|
||||
this.emitScalar('Date(' + value + ')');
|
||||
} else if (value.toString && value.toString() == '[object Set]') {
|
||||
} else if (j$.isSet(value)) {
|
||||
this.emitSet(value);
|
||||
} else if (j$.isMap(value)) {
|
||||
this.emitMap(value);
|
||||
} else if (j$.isTypedArray_(value)) {
|
||||
this.emitTypedArray(value);
|
||||
} else if (value.toString && typeof value === 'object' && !j$.isArray_(value) && hasCustomToString(value)) {
|
||||
this.emitScalar(value.toString());
|
||||
} else if (j$.util.arrayContains(this.seen, value)) {
|
||||
@@ -53,42 +61,44 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
} else {
|
||||
this.emitScalar(value.toString());
|
||||
}
|
||||
} catch (e) {
|
||||
if (this.ppNestLevel_ > 1 || !(e instanceof MaxCharsReachedError)) {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
this.ppNestLevel_--;
|
||||
}
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
||||
for (var property in obj) {
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; }
|
||||
fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) &&
|
||||
obj.__lookupGetter__(property) !== null) : false);
|
||||
var objKeys = keys(obj, j$.isArray_(obj));
|
||||
var isGetter = function isGetter(prop) {};
|
||||
|
||||
if (obj.__lookupGetter__) {
|
||||
isGetter = function isGetter(prop) {
|
||||
var getter = obj.__lookupGetter__(prop);
|
||||
return !j$.util.isUndefined(getter) && getter !== null;
|
||||
};
|
||||
|
||||
}
|
||||
var length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
for (var i = 0; i < length; i++) {
|
||||
var property = objKeys[i];
|
||||
fn(property, isGetter(property));
|
||||
}
|
||||
|
||||
return objKeys.length > length;
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_;
|
||||
PrettyPrinter.prototype.emitSet = j$.unimplementedMethod_;
|
||||
PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_;
|
||||
PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_;
|
||||
PrettyPrinter.prototype.emitString = j$.unimplementedMethod_;
|
||||
|
||||
function StringPrettyPrinter() {
|
||||
PrettyPrinter.call(this);
|
||||
|
||||
this.string = '';
|
||||
}
|
||||
|
||||
j$.util.inherit(StringPrettyPrinter, PrettyPrinter);
|
||||
|
||||
StringPrettyPrinter.prototype.emitScalar = function(value) {
|
||||
PrettyPrinter.prototype.emitScalar = function(value) {
|
||||
this.append(value);
|
||||
};
|
||||
|
||||
StringPrettyPrinter.prototype.emitString = function(value) {
|
||||
PrettyPrinter.prototype.emitString = function(value) {
|
||||
this.append('\'' + value + '\'');
|
||||
};
|
||||
|
||||
StringPrettyPrinter.prototype.emitArray = function(array) {
|
||||
PrettyPrinter.prototype.emitArray = function(array) {
|
||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||
this.append('Array');
|
||||
return;
|
||||
@@ -107,11 +117,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
|
||||
var self = this;
|
||||
var first = array.length === 0;
|
||||
this.iterateObject(array, function(property, isGetter) {
|
||||
if (property.match(/^\d+$/)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var truncated = this.iterateObject(array, function(property, isGetter) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
@@ -121,30 +127,62 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
self.formatProperty(array, property, isGetter);
|
||||
});
|
||||
|
||||
if (truncated) { this.append(', ...'); }
|
||||
|
||||
this.append(' ]');
|
||||
};
|
||||
|
||||
StringPrettyPrinter.prototype.emitSet = function(set) {
|
||||
PrettyPrinter.prototype.emitSet = function(set) {
|
||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||
this.append('Set');
|
||||
return;
|
||||
}
|
||||
this.append('Set( ');
|
||||
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
var iter = set.values();
|
||||
for (var i = 0; i < size; i++) {
|
||||
var i = 0;
|
||||
set.forEach( function( value, key ) {
|
||||
if (i >= size) {
|
||||
return;
|
||||
}
|
||||
if (i > 0) {
|
||||
this.append(', ');
|
||||
}
|
||||
this.format(iter.next().value);
|
||||
}
|
||||
this.format(value);
|
||||
|
||||
i++;
|
||||
}, this );
|
||||
if (set.size > size){
|
||||
this.append(', ...');
|
||||
}
|
||||
this.append(' )');
|
||||
};
|
||||
|
||||
StringPrettyPrinter.prototype.emitObject = function(obj) {
|
||||
PrettyPrinter.prototype.emitMap = function(map) {
|
||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||
this.append('Map');
|
||||
return;
|
||||
}
|
||||
this.append('Map( ');
|
||||
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
var i = 0;
|
||||
map.forEach( function( value, key ) {
|
||||
if (i >= size) {
|
||||
return;
|
||||
}
|
||||
if (i > 0) {
|
||||
this.append(', ');
|
||||
}
|
||||
this.format([key,value]);
|
||||
|
||||
i++;
|
||||
}, this );
|
||||
if (map.size > size){
|
||||
this.append(', ...');
|
||||
}
|
||||
this.append(' )');
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitObject = function(obj) {
|
||||
var ctor = obj.constructor,
|
||||
constructorName;
|
||||
|
||||
@@ -162,7 +200,7 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.append('({ ');
|
||||
var first = true;
|
||||
|
||||
this.iterateObject(obj, function(property, isGetter) {
|
||||
var truncated = this.iterateObject(obj, function(property, isGetter) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
@@ -172,10 +210,36 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
self.formatProperty(obj, property, isGetter);
|
||||
});
|
||||
|
||||
if (truncated) { this.append(', ...'); }
|
||||
|
||||
this.append(' })');
|
||||
};
|
||||
|
||||
StringPrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
||||
PrettyPrinter.prototype.emitTypedArray = function(arr) {
|
||||
var constructorName = j$.fnNameFor(arr.constructor),
|
||||
limitedArray = Array.prototype.slice.call(arr, 0, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH),
|
||||
itemsString = Array.prototype.join.call(limitedArray, ', ');
|
||||
|
||||
if (limitedArray.length !== arr.length) {
|
||||
itemsString += ', ...';
|
||||
}
|
||||
|
||||
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.emitDomElement = function(el) {
|
||||
var closingTag = '</' + el.tagName.toLowerCase() + '>';
|
||||
|
||||
if (el.innerHTML === '') {
|
||||
this.append(el.outerHTML.replace(closingTag, ''));
|
||||
} else {
|
||||
var tagEnd = el.outerHTML.indexOf(el.innerHTML);
|
||||
this.append(el.outerHTML.substring(0, tagEnd));
|
||||
this.append('...' + closingTag);
|
||||
}
|
||||
};
|
||||
|
||||
PrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
||||
this.append(property);
|
||||
this.append(': ');
|
||||
if (isGetter) {
|
||||
@@ -185,13 +249,65 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
StringPrettyPrinter.prototype.append = function(value) {
|
||||
this.string += value;
|
||||
PrettyPrinter.prototype.append = function(value) {
|
||||
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||
this.length += result.value.length;
|
||||
this.stringParts.push(result.value);
|
||||
|
||||
if (result.truncated) {
|
||||
throw new MaxCharsReachedError();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function truncate(s, maxlen) {
|
||||
if (s.length <= maxlen) {
|
||||
return { value: s, truncated: false };
|
||||
}
|
||||
|
||||
s = s.substring(0, maxlen - 4) + ' ...';
|
||||
return { value: s, truncated: true };
|
||||
}
|
||||
|
||||
function MaxCharsReachedError() {
|
||||
this.message = 'Exceeded ' + j$.MAX_PRETTY_PRINT_CHARS +
|
||||
' characters while pretty-printing a value';
|
||||
}
|
||||
|
||||
MaxCharsReachedError.prototype = new Error();
|
||||
|
||||
function keys(obj, isArray) {
|
||||
var allKeys = Object.keys ? Object.keys(obj) :
|
||||
(function(o) {
|
||||
var keys = [];
|
||||
for (var key in o) {
|
||||
if (j$.util.has(o, key)) {
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
})(obj);
|
||||
|
||||
if (!isArray) {
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
if (allKeys.length === 0) {
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
var extraKeys = [];
|
||||
for (var i = 0; i < allKeys.length; i++) {
|
||||
if (!/^[0-9]+$/.test(allKeys[i])) {
|
||||
extraKeys.push(allKeys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return extraKeys;
|
||||
}
|
||||
return function(value) {
|
||||
var stringPrettyPrinter = new StringPrettyPrinter();
|
||||
stringPrettyPrinter.format(value);
|
||||
return stringPrettyPrinter.string;
|
||||
var prettyPrinter = new PrettyPrinter();
|
||||
prettyPrinter.format(value);
|
||||
return prettyPrinter.stringParts.join('');
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,26 +1,37 @@
|
||||
getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
function StopExecutionError() {}
|
||||
StopExecutionError.prototype = new Error();
|
||||
j$.StopExecutionError = StopExecutionError;
|
||||
|
||||
function once(fn) {
|
||||
var called = false;
|
||||
return function() {
|
||||
if (!called) {
|
||||
called = true;
|
||||
fn();
|
||||
fn.apply(null, arguments);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
function QueueRunner(attrs) {
|
||||
this.queueableFns = attrs.queueableFns || [];
|
||||
var queueableFns = attrs.queueableFns || [];
|
||||
this.queueableFns = queueableFns.concat(attrs.cleanupFns || []);
|
||||
this.firstCleanupIx = queueableFns.length;
|
||||
this.onComplete = attrs.onComplete || function() {};
|
||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||
this.onException = attrs.onException || function() {};
|
||||
this.catchException = attrs.catchException || function() { return true; };
|
||||
this.userContext = attrs.userContext || {};
|
||||
this.userContext = attrs.userContext || new j$.UserContext();
|
||||
this.timeout = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
||||
this.fail = attrs.fail || function() {};
|
||||
this.globalErrors = attrs.globalErrors || { pushListener: function() {}, popListener: function() {} };
|
||||
this.completeOnFirstError = !!attrs.completeOnFirstError;
|
||||
this.errored = false;
|
||||
|
||||
if (typeof(this.onComplete) !== 'function') {
|
||||
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
|
||||
}
|
||||
this.deprecated = attrs.deprecated;
|
||||
}
|
||||
|
||||
QueueRunner.prototype.execute = function() {
|
||||
@@ -29,88 +40,138 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
self.onException(error);
|
||||
};
|
||||
this.globalErrors.pushListener(this.handleFinalError);
|
||||
this.run(this.queueableFns, 0);
|
||||
this.run(0);
|
||||
};
|
||||
|
||||
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
|
||||
var length = queueableFns.length,
|
||||
QueueRunner.prototype.skipToCleanup = function(lastRanIndex) {
|
||||
if (lastRanIndex < this.firstCleanupIx) {
|
||||
this.run(this.firstCleanupIx);
|
||||
} else {
|
||||
this.run(lastRanIndex + 1);
|
||||
}
|
||||
};
|
||||
|
||||
QueueRunner.prototype.clearTimeout = function(timeoutId) {
|
||||
Function.prototype.apply.apply(this.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
||||
};
|
||||
|
||||
QueueRunner.prototype.setTimeout = function(fn, timeout) {
|
||||
return Function.prototype.apply.apply(this.timeout.setTimeout, [j$.getGlobal(), [fn, timeout]]);
|
||||
};
|
||||
|
||||
QueueRunner.prototype.attempt = function attempt(iterativeIndex) {
|
||||
var self = this, completedSynchronously = true,
|
||||
handleError = function handleError(error) {
|
||||
onException(error);
|
||||
next(error);
|
||||
},
|
||||
cleanup = once(function cleanup() {
|
||||
self.clearTimeout(timeoutId);
|
||||
self.globalErrors.popListener(handleError);
|
||||
}),
|
||||
next = once(function next(err) {
|
||||
cleanup();
|
||||
|
||||
if (j$.isError_(err)) {
|
||||
if (!(err instanceof StopExecutionError)) {
|
||||
self.fail(err);
|
||||
}
|
||||
self.errored = errored = true;
|
||||
}
|
||||
|
||||
function runNext() {
|
||||
if (self.completeOnFirstError && errored) {
|
||||
self.skipToCleanup(iterativeIndex);
|
||||
} else {
|
||||
self.run(iterativeIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (completedSynchronously) {
|
||||
self.setTimeout(runNext);
|
||||
} else {
|
||||
runNext();
|
||||
}
|
||||
}),
|
||||
errored = false,
|
||||
queueableFn = self.queueableFns[iterativeIndex],
|
||||
timeoutId;
|
||||
|
||||
next.fail = function nextFail() {
|
||||
self.fail.apply(null, arguments);
|
||||
self.errored = errored = true;
|
||||
next();
|
||||
};
|
||||
|
||||
self.globalErrors.pushListener(handleError);
|
||||
|
||||
if (queueableFn.timeout) {
|
||||
timeoutId = self.setTimeout(function() {
|
||||
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
||||
onException(error);
|
||||
next();
|
||||
}, queueableFn.timeout());
|
||||
}
|
||||
|
||||
try {
|
||||
if (queueableFn.fn.length === 0) {
|
||||
var maybeThenable = queueableFn.fn.call(self.userContext);
|
||||
|
||||
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
||||
maybeThenable.then(next, onPromiseRejection);
|
||||
completedSynchronously = false;
|
||||
return { completedSynchronously: false };
|
||||
}
|
||||
} else {
|
||||
queueableFn.fn.call(self.userContext, next);
|
||||
completedSynchronously = false;
|
||||
return { completedSynchronously: false };
|
||||
}
|
||||
} catch (e) {
|
||||
onException(e);
|
||||
self.errored = errored = true;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
return { completedSynchronously: true, errored: errored };
|
||||
|
||||
function onException(e) {
|
||||
self.onException(e);
|
||||
self.errored = errored = true;
|
||||
}
|
||||
|
||||
function onPromiseRejection(e) {
|
||||
onException(e);
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
QueueRunner.prototype.run = function(recursiveIndex) {
|
||||
var length = this.queueableFns.length,
|
||||
self = this,
|
||||
iterativeIndex;
|
||||
|
||||
|
||||
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
|
||||
var queueableFn = queueableFns[iterativeIndex];
|
||||
if (queueableFn.fn.length > 0) {
|
||||
attemptAsync(queueableFn);
|
||||
var result = this.attempt(iterativeIndex);
|
||||
|
||||
if (!result.completedSynchronously) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.errored = result.errored;
|
||||
|
||||
if (this.completeOnFirstError && result.errored) {
|
||||
this.skipToCleanup(iterativeIndex);
|
||||
return;
|
||||
} else {
|
||||
attemptSync(queueableFn);
|
||||
}
|
||||
}
|
||||
|
||||
this.clearStack(function() {
|
||||
self.globalErrors.popListener(self.handleFinalError);
|
||||
self.onComplete();
|
||||
self.onComplete(self.errored && new StopExecutionError());
|
||||
});
|
||||
|
||||
function attemptSync(queueableFn) {
|
||||
try {
|
||||
queueableFn.fn.call(self.userContext);
|
||||
} catch (e) {
|
||||
handleException(e, queueableFn);
|
||||
}
|
||||
}
|
||||
|
||||
function attemptAsync(queueableFn) {
|
||||
var clearTimeout = function () {
|
||||
Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
||||
},
|
||||
handleError = function(error) {
|
||||
onException(error);
|
||||
next();
|
||||
},
|
||||
next = once(function () {
|
||||
clearTimeout(timeoutId);
|
||||
self.globalErrors.popListener(handleError);
|
||||
self.run(queueableFns, iterativeIndex + 1);
|
||||
}),
|
||||
timeoutId;
|
||||
|
||||
next.fail = function() {
|
||||
self.fail.apply(null, arguments);
|
||||
next();
|
||||
};
|
||||
|
||||
self.globalErrors.pushListener(handleError);
|
||||
|
||||
if (queueableFn.timeout) {
|
||||
timeoutId = Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [function() {
|
||||
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
||||
onException(error);
|
||||
next();
|
||||
}, queueableFn.timeout()]]);
|
||||
}
|
||||
|
||||
try {
|
||||
queueableFn.fn.call(self.userContext, next);
|
||||
} catch (e) {
|
||||
handleException(e, queueableFn);
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
function onException(e) {
|
||||
self.onException(e);
|
||||
}
|
||||
|
||||
function handleException(e, queueableFn) {
|
||||
onException(e);
|
||||
if (!self.catchException(e)) {
|
||||
//TODO: set a var when we catch an exception and
|
||||
//use a finally block to close the loop in a nice way..
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return QueueRunner;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
getJasmineRequireObj().ReportDispatcher = function() {
|
||||
function ReportDispatcher(methods) {
|
||||
getJasmineRequireObj().ReportDispatcher = function(j$) {
|
||||
function ReportDispatcher(methods, queueRunnerFactory) {
|
||||
|
||||
var dispatchedMethods = methods || [];
|
||||
|
||||
@@ -33,11 +33,40 @@ getJasmineRequireObj().ReportDispatcher = function() {
|
||||
if (reporters.length === 0 && fallbackReporter !== null) {
|
||||
reporters.push(fallbackReporter);
|
||||
}
|
||||
var onComplete = args[args.length - 1];
|
||||
args = j$.util.argsToArray(args).splice(0, args.length - 1);
|
||||
var fns = [];
|
||||
for (var i = 0; i < reporters.length; i++) {
|
||||
var reporter = reporters[i];
|
||||
if (reporter[method]) {
|
||||
reporter[method].apply(reporter, args);
|
||||
}
|
||||
addFn(fns, reporter, method, args);
|
||||
}
|
||||
|
||||
queueRunnerFactory({
|
||||
queueableFns: fns,
|
||||
onComplete: onComplete,
|
||||
isReporter: true
|
||||
});
|
||||
}
|
||||
|
||||
function addFn(fns, reporter, method, args) {
|
||||
var fn = reporter[method];
|
||||
if (!fn) {
|
||||
return;
|
||||
}
|
||||
|
||||
var thisArgs = j$.util.cloneArgs(args);
|
||||
if (fn.length <= 1) {
|
||||
fns.push({
|
||||
fn: function () {
|
||||
return fn.apply(reporter, thisArgs);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
fns.push({
|
||||
fn: function (done) {
|
||||
return fn.apply(reporter, thisArgs.concat([done]));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user