Skip to content

Commit 6a8312d

Browse files
dadamssgKent C. Dodds
authored andcommitted
docs: added Using Without Jest section (#79)
* docs: added Using Without Jest section * use jsdom-global I discovered a package that can simplify this process greatly :)
1 parent 2c0ab4a commit 6a8312d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ when a real user uses it.
6262

6363
1. A test runner or framework
6464
2. Specific to a testing framework (though we recommend Jest as our
65-
preference, the library works with any framework)
65+
preference, the library works with any framework. See [Using Without Jest](#using-without-jest))
6666

6767
## Table of Contents
6868

@@ -92,6 +92,7 @@ when a real user uses it.
9292
- [Debugging](#debugging)
9393
- [`prettyDOM`](#prettydom)
9494
- [Implementations](#implementations)
95+
- [Using Without Jest](#using-without-jest)
9596
- [FAQ](#faq)
9697
- [Other Solutions](#other-solutions)
9798
- [Guiding Principles](#guiding-principles)
@@ -730,6 +731,37 @@ Implementations include:
730731
- [`react-testing-library`](https://github.com/kentcdodds/react-testing-library)
731732
- [`pptr-testing-library`](https://github.com/patrickhulce/pptr-testing-library)
732733

734+
## Using Without Jest
735+
736+
If you're running your tests in the browser bundled with webpack (or similar)
737+
then `dom-testing-library` should work out of the box for you. However, most
738+
people using `dom-testing-library` are using it with
739+
[the Jest testing framework](https://jestjs.io/) with the `testEnvironment`
740+
set to [`jest-environment-jsdom`](https://www.npmjs.com/package/jest-environment-jsdom)
741+
(which is the default configuration with Jest).
742+
743+
[jsdom](https://github.com/jsdom/jsdom) is a pure JavaScript implementation
744+
of the DOM and browser APIs that runs in node. If you're not using Jest and
745+
you would like to run your tests in Node, then you must install jsdom yourself.
746+
There's also a package called
747+
[jsdom-global](https://github.com/rstacruz/jsdom-global) which can be used
748+
to setup the global environment to simulate the browser APIs.
749+
750+
First, install jsdom and jsdom-global.
751+
752+
```
753+
npm install --save-dev jsdom jsdom-global
754+
```
755+
756+
With mocha, the test command would look something like this:
757+
758+
```
759+
mocha --require jsdom-global/register
760+
```
761+
762+
> Note, depending on the version of Node you're running, you may also need to install
763+
> `@babel/polyfill` (if you're using babel 7) or `babel-polyfill` (for babel 6).
764+
733765
## FAQ
734766

735767
<details>

0 commit comments

Comments
 (0)