├── .gitignore
├── .travis.yml
├── HISTORY.md
├── LICENSE.md
├── README.md
├── browser.js
├── examples
├── basic
│ ├── README.md
│ ├── index.html
│ ├── setup.js
│ └── test.js
└── failures
│ ├── README.md
│ ├── one.js
│ └── two.js
├── index.js
├── package.json
├── test
├── fixtures
│ └── rerequirable.js
├── globalize.js
├── jquery.js
├── mocha.opts
├── rerequire_test.js
├── robust.js
├── setup.js
├── simple.js
├── skip_window_check.js
├── standard_test.js
└── use_each.js
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage.html
3 | /coverage
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | sudo: false
3 | script: npm run coverage
4 | node_js:
5 | - '6'
6 | - '7'
7 | cache:
8 | directories:
9 | - node_modules
10 |
--------------------------------------------------------------------------------
/HISTORY.md:
--------------------------------------------------------------------------------
1 | ## [v2.0.0]
2 | > Jun 5, 2018
3 |
4 | See [Upgrading to v2.0.0](https://github.com/rstacruz/mocha-jsdom#upgrading-to-v200) for notes on how to update from an older version.
5 |
6 | * [#32] - `jsdom` is now a direct dependency of `mocha-jsdom` :tada:
7 |
8 | [#32]: https://github.com/rstacruz/mocha-jsdom/issues/32
9 | [v2.0.0]: https://github.com/rstacruz/mocha-jsdom/compare/v1.2.0...v2.0.0
10 |
11 | ## [v1.2.0]
12 | > Jun 5, 2018
13 |
14 | * [#29] - Update Jsdom compatibility ([@RobLoach])
15 | * [#31] - Update all npm dependencies
16 |
17 | [#29]: https://github.com/rstacruz/mocha-jsdom/issues/29
18 | [#31]: https://github.com/rstacruz/mocha-jsdom/issues/31
19 | [@RobLoach]: https://github.com/robloach
20 | [v1.2.0]: https://github.com/rstacruz/mocha-jsdom/compare/v1.1.0...v1.2.0
21 |
22 | ## [v1.1.0]
23 | > Feb 22, 2016
24 |
25 | * [#18] - Initialize global.window when it is undefined; fixes compatibility with [airbnb/enzyme][]. ([@moonboots])
26 |
27 | [v1.1.0]: https://github.com/rstacruz/mocha-jsdom/compare/v1.0.0...v1.1.0
28 |
29 | ## [v1.0.0] - Jul 4, 2015
30 |
31 | * Add testling/browserify support.
32 | * Add more examples.
33 |
34 | [v1.0.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.5.0...v1.0.0
35 |
36 | ## [v0.5.0] - Jun 26, 2015
37 |
38 | * Add `rerequire()` to help with using mocha-jsdom with `mocha --watch`.
39 | * Internal: change coding standard to feross/standard.
40 |
41 | ## [v0.4.0] - May 25, 2015
42 |
43 | * [#5] - Add `useEach` option. ([@jasco], [#6])
44 | * [#7] - Add a `skipWindowCheck` option.
45 |
46 | ## [v0.3.0] - Apr 3, 2015
47 |
48 | * [#3] - Bump `jsdom` dependency version. This fixes the "needs a context" error ([@nacyot], [#3])
49 |
50 | [#3]: https://github.com/rstacruz/mocha-jsdom/issues/3
51 | [#4]: https://github.com/rstacruz/mocha-jsdom/issues/4
52 | [@nacyot]: https://github.com/nacyot
53 |
54 | ## [v0.2.1] - Feb 19, 2014
55 |
56 | * Add `LICENSE` file
57 | * Update documentation
58 | * No functionality changes
59 |
60 | ## [v0.2.0] - November 5, 2014
61 |
62 | * Skip warnings. Add `JSDOM_VERBOSE=1` to your env to reenable them.
63 |
64 | ## [v0.1.2] - September 27, 2014
65 |
66 | * Throw a useful error when invoked twice.
67 |
68 | ## [v0.1.1] - September 27, 2014
69 |
70 | * Re-release with updated Readme.
71 |
72 | [airbnb/enzyme]: https://github.com/airbnb/enzyme
73 |
74 | ## v0.1.0 - September 25, 2014
75 |
76 | * Initial version.
77 |
78 | [#5]: https://github.com/rstacruz/mocha-jsdom/issues/5
79 | [#6]: https://github.com/rstacruz/mocha-jsdom/issues/6
80 | [#7]: https://github.com/rstacruz/mocha-jsdom/issues/7
81 | [@jasco]: https://github.com/jasco
82 | [v0.5.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.4.0...v0.5.0
83 | [v0.4.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.3.0...v0.4.0
84 | [v0.3.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.2.1...v0.3.0
85 | [v0.2.1]: https://github.com/rstacruz/mocha-jsdom/compare/v0.2.0...v0.2.1
86 | [v0.2.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.1.2...v0.2.0
87 | [v0.1.2]: https://github.com/rstacruz/mocha-jsdom/compare/v0.1.1...v0.1.2
88 | [v0.1.1]: https://github.com/rstacruz/mocha-jsdom/compare/v0.1.0...v0.1.1
89 | [#18]: https://github.com/rstacruz/mocha-jsdom/issues/18
90 | [@moonboots]: https://github.com/moonboots
91 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright © 2015 Rico Sta. Cruz
2 |
3 | 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:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | 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.
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > _Deprecation notice:_
2 | > Consider [jsdom-global](https://github.com/rstacruz/jsdom-global) instead, a simpler alternative that also works outside of Mocha. `mocha-jsdom` still works, but `jsdom-global` is better supported.
3 |
4 | ---
5 |
6 | # mocha-jsdom
7 |
8 | > Test frontend libraries in the console using Node.js, [mocha] and [jsdom].
9 |
10 | [](https://travis-ci.org/rstacruz/mocha-jsdom "See test builds")
11 |
12 |
13 |
14 | ## Usage
15 |
16 | ```sh
17 | $ npm i --save-dev mocha-jsdom
18 | ```
19 |
20 | [](https://npmjs.org/package/mocha-jsdom "View this project on npm")
21 |
22 | Use `jsdom()` inside your `describe(...)` block (or the global context). It will
23 | turn your Node.js environment into a mock browser environment supporting the
24 | full DOM and browser API. The variables `window`, `document`, `history` (and so
25 | on) will then be available for use.
26 |
27 | ```js
28 | var jsdom = require('mocha-jsdom')
29 | var expect = require('chai').expect
30 |
31 | describe('mocha tests', function () {
32 |
33 | jsdom()
34 |
35 | it('has document', function () {
36 | var div = document.createElement('div')
37 | expect(div.nodeName).eql('DIV')
38 | })
39 |
40 | })
41 | ```
42 |
43 | See [examples/basic](examples/basic) for an example of a basic setup.
44 |
45 |
46 |
47 | ## Upgrading to v2.0.0
48 |
49 | If you are coming from mocha-jsdom v1.x, remove `jsdom` if you're not using it before upgrading. `jsdom` is now a direct dependency of `mocha-jsdom`.
50 |
51 | ```bash
52 | # using Yarn
53 | yarn remove jsdom
54 | yarn upgrade mocha-jsdom
55 | ```
56 |
57 | ```bash
58 | # using npm
59 | npm uninstall -S -D jsdom
60 | npm upgrade mocha-jsdom
61 | ```
62 |
63 |
64 |
65 | ## Node and io.js information
66 |
67 | As of jsdom 4.0.0, [jsdom now requires io.js](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#400) and will not work with Node.js 0.12 or below.
68 |
69 |
70 |
71 | ## How it works
72 |
73 | mocha-jsdom is a simple glue to integrate [jsdom] to mocha.
74 |
75 | Invoking `jsdom()` will inject `before` and `after` handlers to the current
76 | mocha suite which will setup and teardown jsdom. Here's what it does:
77 |
78 | * __Window__: `global.window` will be available as the jsdom.
79 |
80 | * __Globals__: global variables like `document` and `history` are propagated,
81 | and they're cleaned up after tests run.
82 |
83 | * __Error handling__: jsdom errors are sanitized so that their stack traces are
84 | shortened.
85 |
86 | __NB:__ Before you try this library, learn about jsdom first. In fact, you may be
87 | able to integrate jsdom into your tests *without* this library; this is mostly
88 | syntactic sugar and reasonable defaults.
89 |
90 |
91 |
92 | ## Using with a library
93 |
94 | Perfect for testing small DOM-consuming utilities in the console. See
95 | [test/jquery.js](test/jquery.js) for an example.
96 |
97 | ```js
98 | describe('mocha tests', function () {
99 |
100 | var $
101 | jsdom()
102 |
103 | before(function () {
104 | $ = require('jquery')
105 | })
106 |
107 | it('works', function () {
108 | document.body.innerHTML = '