You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,7 +121,7 @@ Ran all test suites.
121
121
122
122
##### Using jest-circus
123
123
124
-
There may be cases where you want to run jest using `jest-circus` instead of `jest-jasmine2` (which is the default runner) for integration testing. In situations like this just set the environment variable `JEST_CIRCUS` to 1. That will configure jest to use `jest-circus`. So something like this.
124
+
There may be cases where you want to run jest using `jest-circus` instead of `jest-jasmine2` (which is the default runner) for integration testing. In situations like this, set the environment variable `JEST_CIRCUS` to 1. That will configure jest to use `jest-circus`. So something like this.
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -190,7 +190,7 @@ module.exports = {
190
190
};
191
191
```
192
192
193
-
Note, there are some [caveats](https://babeljs.io/docs/en/next/babel-plugin-transform-typescript.html#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is just transpilation, Jest will not type-check your tests as they are ran. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
193
+
Note, there are some [caveats](https://babeljs.io/docs/en/next/babel-plugin-transform-typescript.html#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is transpilation, Jest will not type-check your tests as they are ran. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
## In depth: Understanding mock constructor functions
192
192
193
-
Building your constructor function mock using `jest.fn().mockImplementation()` makes mocks appear more complicated than they really are. This section shows how you can create your own simple mocks to illustrate how mocking works.
193
+
Building your constructor function mock using `jest.fn().mockImplementation()` makes mocks appear more complicated than they really are. This section shows how you can create your own smaller mocks to illustrate how mocking works.
194
194
195
195
### Manual mock that is another ES6 class
196
196
@@ -211,7 +211,7 @@ export default class SoundPlayer {
211
211
}
212
212
```
213
213
214
-
### Simple mock using module factory parameter
214
+
### Mock using module factory parameter
215
215
216
216
The module factory function passed to `jest.mock(path, moduleFactory)` can be a HOF that returns a function\*. This will allow calling `new` on the mock. Again, this allows you to inject different behavior for testing, but does not provide a way to spy on calls.
@@ -838,7 +838,7 @@ The optional `numDigits` argument limits the number of digits to check **after**
838
838
Intuitive equality comparisons often fail, because arithmetic on decimal (base 10) values often have rounding errors in limited precision binary (base 2) representation. For example, this test fails:
839
839
840
840
```js
841
-
test('adding works sanely with simple decimals', () => {
841
+
test('adding works sanely with decimals', () => {
842
842
expect(0.2+0.1).toBe(0.3); // Fails!
843
843
});
844
844
```
@@ -848,7 +848,7 @@ It fails because in JavaScript, `0.2 + 0.1` is actually `0.30000000000000004`.
848
848
For example, this test passes with a precision of 5 digits:
849
849
850
850
```js
851
-
test('adding works sanely with simple decimals', () => {
851
+
test('adding works sanely with decimals', () => {
852
852
expect(0.2+0.1).toBeCloseTo(0.3, 5);
853
853
});
854
854
```
@@ -857,7 +857,7 @@ Because floating point errors are the problem that `toBeCloseTo` solves, it does
857
857
858
858
### `.toBeDefined()`
859
859
860
-
Use `.toBeDefined` to check that a variable is not undefined. For example, if you just want to check that a function `fetchNewFlavorIdea()` returns _something_, you can write:
860
+
Use `.toBeDefined` to check that a variable is not undefined. For example, if you want to check that a function `fetchNewFlavorIdea()` returns _something_, you can write:
861
861
862
862
```js
863
863
test('there is a new flavor idea', () => {
@@ -869,7 +869,7 @@ You could write `expect(fetchNewFlavorIdea()).not.toBe(undefined)`, but it's bet
869
869
870
870
### `.toBeFalsy()`
871
871
872
-
Use `.toBeFalsy` when you don't care what a value is, you just want to ensure a value is false in a boolean context. For example, let's say you have some application code that looks like:
872
+
Use `.toBeFalsy` when you don't care what a value is and you want to ensure a value is false in a boolean context. For example, let's say you have some application code that looks like:
Use `.toBeTruthy` when you don't care what a value is, you just want to ensure a value is true in a boolean context. For example, let's say you have some application code that looks like:
960
+
Use `.toBeTruthy` when you don't care what a value is and you want to ensure a value is true in a boolean context. For example, let's say you have some application code that looks like:
961
961
962
962
```js
963
963
drinkSomeLaCroix();
@@ -966,7 +966,7 @@ if (thirstInfo()) {
966
966
}
967
967
```
968
968
969
-
You may not care what `thirstInfo` returns, specifically - it might return `true` or a complex object, and your code would still work. So if you just want to test that `thirstInfo` will be truthy after drinking some La Croix, you could write:
969
+
You may not care what `thirstInfo` returns, specifically - it might return `true` or a complex object, and your code would still work. So if you want to test that `thirstInfo` will be truthy after drinking some La Croix, you could write:
970
970
971
971
```js
972
972
test('drinking La Croix leads to having thirst info', () => {
Copy file name to clipboardExpand all lines: docs/GettingStarted.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,4 +175,4 @@ module.exports = {
175
175
};
176
176
```
177
177
178
-
However, there are some [caveats](https://babeljs.io/docs/en/next/babel-plugin-transform-typescript.html#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is just transpilation, Jest will not type-check your tests as they are ran. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
178
+
However, there are some [caveats](https://babeljs.io/docs/en/next/babel-plugin-transform-typescript.html#caveats) to using TypeScript with Babel. Because TypeScript support in Babel is transpilation, Jest will not type-check your tests as they are ran. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
Here the `beforeAll` ensures that the database is set up before tests run. If setup was synchronous, you could just do this without `beforeAll`. The key is that Jest will wait for a promise to resolve, so you can have asynchronous setup as well.
126
+
Here the `beforeAll` ensures that the database is set up before tests run. If setup was synchronous, you could do this without `beforeAll`. The key is that Jest will wait for a promise to resolve, so you can have asynchronous setup as well.
127
127
128
128
If `beforeAll` is inside a `describe` block, it runs at the beginning of the describe block.
This isn't required - you can just write the `test` blocks directly at the top level. But this can be handy if you prefer your tests to be organized into groups.
193
+
This isn't required - you can write the `test` blocks directly at the top level. But this can be handy if you prefer your tests to be organized into groups.
194
194
195
195
You can also nest `describe` blocks if you have a hierarchy of tests:
196
196
@@ -388,7 +388,7 @@ describe.skip('my other beverage', () => {
388
388
});
389
389
```
390
390
391
-
Using `describe.skip` is often just an easier alternative to temporarily commenting out a chunk of tests.
391
+
Using `describe.skip` is often a cleaner alternative to temporarily commenting out a chunk of tests.
392
392
393
393
### `describe.skip.each(table)(name, fn)`
394
394
@@ -544,7 +544,7 @@ test('it is not snowing', () => {
544
544
545
545
Only the "it is raining" test will run in that test file, since it is run with `test.only`.
546
546
547
-
Usually you wouldn't check code using `test.only` into source control - you would use it just for debugging, and remove it once you have fixed the broken tests.
547
+
Usually you wouldn't check code using `test.only` into source control - you would use it for debugging, and remove it once you have fixed the broken tests.
548
548
549
549
### `test.only.each(table)(name, fn)`
550
550
@@ -590,7 +590,7 @@ test('will not be ran', () => {
590
590
591
591
Also under the aliases: `it.skip(name, fn)` or `xit(name, fn)` or `xtest(name, fn)`
592
592
593
-
When you are maintaining a large codebase, you may sometimes find a test that is temporarily broken for some reason. If you want to skip running this test, but you don't want to just delete this code, you can use `test.skip` to specify some tests to skip.
593
+
When you are maintaining a large codebase, you may sometimes find a test that is temporarily broken for some reason. If you want to skip running this test, but you don't want to delete this code, you can use `test.skip` to specify some tests to skip.
594
594
595
595
For example, let's say you had these tests:
596
596
@@ -606,7 +606,7 @@ test.skip('it is not snowing', () => {
606
606
607
607
Only the "it is raining" test will run, since the other test is run with `test.skip`.
608
608
609
-
You could simply comment the test out, but it's often a bit nicer to use `test.skip` because it will maintain indentation and syntax highlighting.
609
+
You could comment the test out, but it's often a bit nicer to use `test.skip` because it will maintain indentation and syntax highlighting.
The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can simply export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs.
127
+
The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs.
128
128
129
129
To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using [`jest.requireActual(moduleName)`](JestObjectAPI.md#jestrequireactualmodulename) in your manual mock and amending it with mock functions before exporting it.
Copy file name to clipboardExpand all lines: docs/MigrationGuide.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: Migrating to Jest
5
5
6
6
If you'd like to try out Jest with an existing codebase, there are a number of ways to convert to Jest:
7
7
8
-
- If you are using Jasmine, or a Jasmine like API (for example [Mocha](https://mochajs.org)), Jest should be mostly compatible and easy to migrate to.
8
+
- If you are using Jasmine, or a Jasmine like API (for example [Mocha](https://mochajs.org)), Jest should be mostly compatible, which makes it less complicated to migrate to.
9
9
- If you are using AVA, Expect.js (by Automattic), Jasmine, Mocha, proxyquire, Should.js or Tape you can automatically migrate with Jest Codemods (see below).
10
10
- If you like [chai](http://chaijs.com/), you can upgrade to Jest and continue using chai. However, we recommend trying out Jest's assertions and their failure messages. Jest Codemods can migrate from chai (see below).
Copy file name to clipboardExpand all lines: docs/MockFunctionAPI.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ id: mock-function-api
3
3
title: Mock Functions
4
4
---
5
5
6
-
Mock functions are also known as "spies", because they let you spy on the behavior of a function that is called indirectly by some other code, rather than just testing the output. You can create a mock function with `jest.fn()`. If no implementation is given, the mock function will return `undefined` when invoked.
6
+
Mock functions are also known as "spies", because they let you spy on the behavior of a function that is called indirectly by some other code, rather than only testing the output. You can create a mock function with `jest.fn()`. If no implementation is given, the mock function will return `undefined` when invoked.
0 commit comments