From bf817724ea8e7dfbd81663e64767fcf9d799d9e9 Mon Sep 17 00:00:00 2001 From: tushardhole Date: Tue, 9 Jan 2018 16:47:51 +0530 Subject: [PATCH 1/3] docs: updating docs for prefer-expect-assertions rule --- README.md | 21 +++++----- docs/rules/prefer-expect-assertions.md | 57 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 docs/rules/prefer-expect-assertions.md diff --git a/README.md b/README.md index 738476b84..a1499c81a 100644 --- a/README.md +++ b/README.md @@ -78,16 +78,17 @@ for more information about extending configuration files. ## Rules -| Rule | Description | Recommended | Fixable | -| -------------------------------------------------------------- | ----------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------- | -| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | -| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | -| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | -| [no-large-snapshots](docs/rules/no-large-snapshots.md) | Disallow large snapshots | | | -| [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using toHaveLength() | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | -| [prefer-to-be-null](docs/rules/prefer-to-be-null.md) | Suggest using toBeNull() | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | -| [prefer-to-be-undefined](docs/rules/prefer-to-be-undefined.md) | Suggest using toBeUndefined() | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | -| [valid-expect](docs/rules/valid-expect.md) | Enforce valid expect() usage | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| Rule | Description | Recommended | Fixable | +| ------------------------------------------------------------------ | ----------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------- | +| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| [no-large-snapshots](docs/rules/no-large-snapshots.md) | Disallow large snapshots | | | +| [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using toHaveLength() | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | +| [prefer-to-be-null](docs/rules/prefer-to-be-null.md) | Suggest using toBeNull() | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | +| [prefer-to-be-undefined](docs/rules/prefer-to-be-undefined.md) | Suggest using toBeUndefined() | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | +| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using expect.assertions() OR expect.hasAssertions() | | | +| [valid-expect](docs/rules/valid-expect.md) | Enforce valid expect() usage | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | ## Credit diff --git a/docs/rules/prefer-expect-assertions.md b/docs/rules/prefer-expect-assertions.md new file mode 100644 index 000000000..c83e918ed --- /dev/null +++ b/docs/rules/prefer-expect-assertions.md @@ -0,0 +1,57 @@ +# Suggest using `expect.assertions() OR expect.hasAssertions()` (prefer-expect-assertions) + +Ensure every test to have either `expect.assertions()` OR +`expect.hasAssertions()` as its first expression + +## Rule details + +This rule triggers a warning if, + +* `expect.assertions()` OR `expect.hasAssertions()` is not + present as first statement in a test,e.g.: + +```js +test("my test", () => { + expect.(someThing()).toEqual("foo"); +}); +``` + +* `expect.assertions()` is the first statement in a test + where argument passed to `expect.assertions()` is not a + valid number,e.g.: + +```js +test("my test", () => { + expect.assertions("1"); + expect.(someThing()).toEqual("foo"); +}); +``` + +### Default configuration + +The following patterns are considered warnings: + +```js +test("my test", () => { + expect.assertions("1"); + expect.(someThing()).toEqual("foo"); +}); + +test("my test", () => { + expect.(someThing()).toEqual("foo"); +}); +``` + +The following patterns would not be considered warnings: + +```js +test("my test", () => { + expect.assertions(1); + expect.(someThing()).toEqual("foo"); +}); + +test("my test", () => { + expect.hasAssertions(); + expect.(someThing()).toEqual("foo"); +}); +``` From b81caffde8b606127d97d729c0aced9e904e238c Mon Sep 17 00:00:00 2001 From: tushardhole Date: Tue, 9 Jan 2018 16:58:54 +0530 Subject: [PATCH 2/3] style: minnor formating in prefer-expect-assertions doc --- docs/rules/prefer-expect-assertions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/prefer-expect-assertions.md b/docs/rules/prefer-expect-assertions.md index c83e918ed..5d13ab1b1 100644 --- a/docs/rules/prefer-expect-assertions.md +++ b/docs/rules/prefer-expect-assertions.md @@ -1,4 +1,4 @@ -# Suggest using `expect.assertions() OR expect.hasAssertions()` (prefer-expect-assertions) +# Suggest using `expect.assertions()` OR `expect.hasAssertions()` (prefer-expect-assertions) Ensure every test to have either `expect.assertions()` OR `expect.hasAssertions()` as its first expression From dd8b73122a2d9b7704f99787132b597ada03308a Mon Sep 17 00:00:00 2001 From: simbekkh Date: Tue, 9 Jan 2018 13:12:55 +0100 Subject: [PATCH 3/3] docs: tweaks --- README.md | 22 +++++++++++----------- docs/rules/prefer-expect-assertions.md | 26 +++++++++++++------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index a1499c81a..5502f65a1 100644 --- a/README.md +++ b/README.md @@ -78,17 +78,17 @@ for more information about extending configuration files. ## Rules -| Rule | Description | Recommended | Fixable | -| ------------------------------------------------------------------ | ----------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------- | -| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | -| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | -| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | -| [no-large-snapshots](docs/rules/no-large-snapshots.md) | Disallow large snapshots | | | -| [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using toHaveLength() | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | -| [prefer-to-be-null](docs/rules/prefer-to-be-null.md) | Suggest using toBeNull() | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | -| [prefer-to-be-undefined](docs/rules/prefer-to-be-undefined.md) | Suggest using toBeUndefined() | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | -| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using expect.assertions() OR expect.hasAssertions() | | | -| [valid-expect](docs/rules/valid-expect.md) | Enforce valid expect() usage | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| Rule | Description | Recommended | Fixable | +| ------------------------------------------------------------------ | --------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------- | +| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | +| [no-large-snapshots](docs/rules/no-large-snapshots.md) | Disallow large snapshots | | | +| [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | +| [prefer-to-be-null](docs/rules/prefer-to-be-null.md) | Suggest using `toBeNull()` | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | +| [prefer-to-be-undefined](docs/rules/prefer-to-be-undefined.md) | Suggest using `toBeUndefined()` | | ![fixable](https://img.shields.io/badge/-fixable-green.svg) | +| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | | +| [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | ![recommended](https://img.shields.io/badge/-recommended-lightgrey.svg) | | ## Credit diff --git a/docs/rules/prefer-expect-assertions.md b/docs/rules/prefer-expect-assertions.md index 5d13ab1b1..8eb8dd8ec 100644 --- a/docs/rules/prefer-expect-assertions.md +++ b/docs/rules/prefer-expect-assertions.md @@ -1,29 +1,29 @@ # Suggest using `expect.assertions()` OR `expect.hasAssertions()` (prefer-expect-assertions) Ensure every test to have either `expect.assertions()` OR -`expect.hasAssertions()` as its first expression +`expect.hasAssertions()` as its first expression. ## Rule details This rule triggers a warning if, * `expect.assertions()` OR `expect.hasAssertions()` is not - present as first statement in a test,e.g.: + present as first statement in a test, e.g.: ```js -test("my test", () => { - expect.(someThing()).toEqual("foo"); +test('my test', () => { + expect(someThing()).toEqual('foo'); }); ``` * `expect.assertions()` is the first statement in a test where argument passed to `expect.assertions()` is not a - valid number,e.g.: + valid number, e.g.: ```js -test("my test", () => { - expect.assertions("1"); - expect.(someThing()).toEqual("foo"); +test('my test', () => { + expect.assertions('1'); + expect(someThing()).toEqual('foo'); }); ``` @@ -34,7 +34,7 @@ The following patterns are considered warnings: ```js test("my test", () => { expect.assertions("1"); - expect.(someThing()).toEqual("foo"); + expect(someThing()).toEqual("foo"); }); test("my test", () => { @@ -45,13 +45,13 @@ test("my test", () => { The following patterns would not be considered warnings: ```js -test("my test", () => { +test('my test', () => { expect.assertions(1); - expect.(someThing()).toEqual("foo"); + expect(someThing()).toEqual('foo'); }); -test("my test", () => { +test('my test', () => { expect.hasAssertions(); - expect.(someThing()).toEqual("foo"); + expect(someThing()).toEqual('foo'); }); ```