Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up lint and test #1

Merged
merged 9 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format markdown files witg prettier
  • Loading branch information
SimenB committed Nov 8, 2017
commit 7a86fa6064aa18b62cedaf9d2f2b64fdbf6283fe
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ Eslint plugin for Jest
$ yarn add --dev eslint eslint-plugin-jest
```

**Note:** If you installed ESLint globally then you must also install `eslint-plugin-jest` globally.
**Note:** If you installed ESLint globally then you must also install
`eslint-plugin-jest` globally.

## Usage

Add `jest` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
Add `jest` to the plugins section of your `.eslintrc` configuration file. You
can omit the `eslint-plugin-` prefix:

```json
{
"plugins": [
"jest"
]
"plugins": ["jest"]
}
```


Then configure the rules you want to use under the rules section.

```json
Expand All @@ -50,33 +49,41 @@ You can also whitelist the environment variables provided by Jest by doing:

## Supported Rules

- [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - disallow disabled tests.
- [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - disallow focused tests.
- [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallow identical titles.
- [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly.
* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) -
disallow disabled tests.
* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) -
disallow focused tests.
* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) -
disallow identical titles.
* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) -
ensure expect is called correctly.

## Shareable configurations

### Recommended

This plugin exports a recommended configuration that enforces good testing practices.
This plugin exports a recommended configuration that enforces good testing
practices.

To enable this configuration use the `extends` property in your `.eslintrc` config file:
To enable this configuration use the `extends` property in your `.eslintrc`
config file:

```json
{
"extends": ["plugin:jest/recommended"]
}
```

See [ESLint documentation](http:https://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.
See [ESLint
documentation](http:https://eslint.org/docs/user-guide/configuring#extending-configuration-files)
for more information about extending configuration files.

The rules enabled in this configuration are:

- [jest/no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md)
- [jest/no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md)
- [jest/no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md)
- [jest/valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md)
* [jest/no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md)
* [jest/no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md)
* [jest/no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md)
* [jest/valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md)

## Credit

Expand Down
3 changes: 2 additions & 1 deletion docs/rules/no-disabled-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This rule raises a warning about disabled tests.
## Rule Details

There are a number of ways to disable tests in Jest:

* by appending `.skip` to the test-suite or test-case
* by prepending the test function name with `x`
* by declaring a test with a name but no function body
Expand All @@ -34,7 +35,7 @@ it('bar');
test('bar');

it('foo', () => {
pending()
pending();
});
```

Expand Down
16 changes: 10 additions & 6 deletions docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Disallow Focused Tests (no-focused-tests)

Jest has a feature that allows you to focus tests by appending `.only` or prepending `f` to a test-suite or a test-case.
This feature is really helpful to debug a failing test, so you don’t have to execute all of your tests.
After you have fixed your test and before committing the changes you have to remove `.only` to ensure all tests are executed on your build system.
Jest has a feature that allows you to focus tests by appending `.only` or
prepending `f` to a test-suite or a test-case. This feature is really helpful to
debug a failing test, so you don’t have to execute all of your tests. After you
have fixed your test and before committing the changes you have to remove
`.only` to ensure all tests are executed on your build system.

This rule reminds you to remove `.only` from your tests by raising a warning whenever you are using the exclusivity feature.
This rule reminds you to remove `.only` from your tests by raising a warning
whenever you are using the exclusivity feature.

## Rule Details

This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`, `fit` and `ftest` occurrences within the source code.
Of course there are some edge-cases which can’t be detected by this rule e.g.:
This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`,
`fit` and `ftest` occurrences within the source code. Of course there are some
edge-cases which can’t be detected by this rule e.g.:

```js
const describeOnly = describe.only;
Expand Down
15 changes: 11 additions & 4 deletions docs/rules/no-identical-title.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Disallow identical titles (no-identical-title)

Having identical titles for two different tests or test suites may create confusion. For example, when a test with the same title as another test in the same test suite fails, it is harder to know which one failed and thus harder to fix.
Having identical titles for two different tests or test suites may create
confusion. For example, when a test with the same title as another test in the
same test suite fails, it is harder to know which one failed and thus harder to
fix.

## Rule Details

This rule looks at the title of every test and test suites. It will report when two test suites or two test cases at the same level of a test suite have the same title.
This rule looks at the title of every test and test suites. It will report when
two test suites or two test cases at the same level of a test suite have the
same title.

The following patterns are considered warnings:

Expand All @@ -17,7 +22,8 @@ describe('foo', () => {
// ...
});

describe('baz', () => { // Has the same title as a previous test suite
describe('baz', () => {
// Has the same title as a previous test suite
// ...
});
});
Expand All @@ -37,7 +43,8 @@ describe('foo', () => {
it('should work', () => {});
});

describe('baz', () => { // Has the same title as a previous test suite
describe('baz', () => {
// Has the same title as a previous test suite
// Has the same name as a test in a sibling test suite, which is fine
it('should work', () => {});
});
Expand Down
8 changes: 5 additions & 3 deletions docs/rules/prefer-to-have-length.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Suggest using `toHaveLength()` (prefer-to-have-length)
# Suggest using `toHaveLength()` (prefer-to-have-length)

In order to have a better failure message, `toHaveLength()` should be used upon asserting expections on object's length property.
In order to have a better failure message, `toHaveLength()` should be used upon
asserting expections on object's length property.

## Rule details

This rule triggers a warning if `toBe()` is used to assert object's length property.
This rule triggers a warning if `toBe()` is used to assert object's length
property.

```js
expect(files.length).toBe(1);
Expand Down
8 changes: 5 additions & 3 deletions docs/rules/valid-expect.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Enforce valid `expect()` usage (valid-expect)

Ensure `expect()` is called with a single argument and there is an actual expectation made.
Ensure `expect()` is called with a single argument and there is an actual
expectation made.

## Rule details

This rule triggers a warning if `expect()` is called with more than one argument or without arguments.
It would also issue a warning if there is nothing called on `expect()`, e.g.:
This rule triggers a warning if `expect()` is called with more than one argument
or without arguments. It would also issue a warning if there is nothing called
on `expect()`, e.g.:

```js
expect();
Expand Down