From fd911ae0192a06c98c6688411f0ff1c5eef29743 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 26 Feb 2018 22:57:31 +0000 Subject: [PATCH] Add community packages documentation --- docs/CommunityPackages.md | 119 ++++++++++++++++++++++++++++++++++++++ website/i18n/en.json | 1 + website/sidebars.json | 1 + 3 files changed, 121 insertions(+) create mode 100644 docs/CommunityPackages.md diff --git a/docs/CommunityPackages.md b/docs/CommunityPackages.md new file mode 100644 index 000000000000..ffddc13ffe31 --- /dev/null +++ b/docs/CommunityPackages.md @@ -0,0 +1,119 @@ +--- +id: community-packages +title: Community Packages +--- + +Jest has a large community of packages out there in the wild, here's a list of +some of the popular packages to enhance your Jest experience: + +## jest-extended + +Additional Jest matchers including multiple APIs for different types including: + +* Array +* Boolean +* Date +* Function +* Mock +* Number +* Object +* Promise +* String + +### Example + +`.toContainEntries([[key, value]])` + +Use .toContainEntries when checking if an object contains all of the provided +entries. + +```javascript +test('passes when object contains all of the given entries', () => { + const o = {a: 'foo', b: 'bar', c: 'baz'}; + expect(o).toContainEntries([['a', 'foo']]); + expect(o).toContainEntries([['c', 'baz'], ['a', 'foo']]); + expect(o).not.toContainEntries([['b', 'qux'], ['a', 'foo']]); +}); +``` + +You can find all of the available matchers `jest-extended` has to offer in the +[readme file](https://github.com/jest-community/jest-extended/blob/master/README.md). + +## vscode-jest + +The optimal flow for Jest based testing in VS Code + +A comprehensive experience when using Facebook's Jest within a project. + +* Useful IDE based Feedback +* Session based test watching + +Find out how to install and setup `vscode-jest` in the +[readme file](https://github.com/jest-community/vscode-jest/blob/master/README.md). + +## eslint-plugin-jest + +ESLint plugin for Jest + +Popular rules include: + +* `jest/no-disabled-tests` +* `jest/no-focused-tests` +* `jest/no-identical-title` +* `jest/valid-expect` + +You can find all of the available rules `eslint-plugin-jest` has to offer in the +[readme file](https://github.com/jest-community/eslint-plugin-jest/blob/master/README.md). + +## jest-each + +Data Driven Jest Testing + +jest-each allows you to provide multiple arguments to your test/describe which +results in the test/suite being run once per row of data. _Supports skipping and +focussing tests_. + +### Example data driven test + +```javascript +import each from 'jest-each'; + +each([[1, 1, 2], [1, 2, 3], [2, 1, 3]]).test( + 'returns the result of adding %s to %s', + (a, b, expected) => { + expect(a + b).toBe(expected); + }, +); +``` + +Read the full documentation of `jest-each` in the +[readme file](https://github.com/mattphillips/jest-each/blob/master/README.md). + +## babel-jest-assertions + +Automatically add `expect.assertions(n)` and `expect.hasAssertions` to all tests +using babel + +### Usage + +Simply write your tests as you would normally and this plugin will add the +verification of assertions in the background. + +```javascript +it('resolves to one', () => { + Promise.reject(1).then(value => expect(value).toBe(1)); +}); +``` + +`↓ ↓ ↓ ↓ ↓ ↓` + +```javascript +it('resolves to one', () => { + expect.hasAssertions(); + expect.assertions(1); + Promise.reject(1).then(value => expect(value).toBe(1)); +}); +``` + +Find out how to install and setup `babel-jest-assertions` in the +[readme file](https://github.com/mattphillips/babel-jest-assertions/blob/master/README.md). diff --git a/website/i18n/en.json b/website/i18n/en.json index b11d7d41c4ea..05902b6ac03d 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -5,6 +5,7 @@ "previous": "Previous", "tagline": "🃏 Delightful JavaScript Testing", "cli": "Jest CLI Options", + "community-packages": "Community Packages", "configuration": "Configuring Jest", "es6-class-mocks": "ES6 Class Mocks", "expect": "Expect", diff --git a/website/sidebars.json b/website/sidebars.json index 2f5f48529200..e162c89dbf98 100644 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -7,6 +7,7 @@ "setup-teardown", "mock-functions", "jest-platform", + "community-packages", "more-resources" ], "Guides": [