Skip to content

Commit 756ba05

Browse files
paulmolluzzoacatl
authored andcommitted
docs(Contributing): Add Testing Style to Contributing docs (ViacomInc#217)
1 parent 0b6384b commit 756ba05

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

CONTRIBUTING.md

+16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ We want DataPoint to be accessible to users from Node 6.x and above, because of
4949

5050
That said, for asynchronous code please rely on using BlueBird's promise api.
5151

52+
**Testing Style**
53+
54+
We want `DataPoint` to maintain 100% test coverage for a few reasons. It ensures the library is working as expected, and it documents the library with clear examples. If we run `jest --verbose`, we get a nice, readable list of what the library does:
55+
56+
![](https://user-images.githubusercontent.com/737065/36062198-0cf4e4ba-0e35-11e8-96da-4b27426f338f.png)
57+
58+
Here are a few tips for organizing your tests:
59+
60+
* Use the `describe` blocks to split up logically related tests, and write clear descriptions of what the tests relate to. (See tests in the [`base-entity`](https://github.com/ViacomInc/data-point/blob/b60824509467af599ef12d730a1b6cf8778d0b9d/packages/data-point/lib/entity-types/base-entity/resolve.test.js#L216) for an example.)
61+
* Break up individual tests to have as few `expect`s in each test as possible. This way if a single `expect` fails for some reason, it immediately gets narrowed down to the one test that failed. Also when `jest` throws the error it'll write the description string in the console, so we'll be able to read the English description of what failed and not read any code to understand the problem. (See [these tests in `reducer-herlpers/utils`](https://github.com/ViacomInc/data-point/blob/b60824509467af599ef12d730a1b6cf8778d0b9d/packages/data-point/lib/reducer-types/reducer-helpers/utils/index.test.js#L5-L45) for an example.)
62+
* Write simple result expectations directly in the test. Use `toMatchSnapshot()` if there is a large, complex expected result.
63+
* Write tests for both the passing and the _failing_ scenarios of a function. If a function should throw an error in some circumstance, write a test for that condition. Since the thrown error is likely to be a large object, using `toThrowErrorMatchingSnapshot()` is a good way to test that there was a thrown error and that the error object/message matches the expectation. For an example, see [these tests in `entity-hash/factory`](https://github.com/ViacomInc/data-point/blob/a366091b277e94a8a98da005a4dc578b127ea3db/packages/data-point/lib/entity-types/entity-hash/factory.test.js#L61-L96).
64+
65+
For more ideas when writing tests, check out this article: http://marclittlemore.com/how-to-write-high-quality-unit-tests/
66+
67+
5268
## Supported Node Versions
5369

5470
We will only be supporting node 6 and above, please make sure the code you use is supported by this version.

0 commit comments

Comments
 (0)