Skip to content

Commit

Permalink
feat(no-pending-tests): add rule to disallow pending specs
Browse files Browse the repository at this point in the history
  • Loading branch information
djungowski authored and tlvince committed Nov 16, 2019
1 parent 596d706 commit ab30e3e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Rule | Recommended | Options
[no-expect-in-setup-teardown][] | 1, `'expect()'`, `'expectAsync()'` | expectation function names
[no-focused-tests][] | 2 |
[no-global-setup][] | 2 |
[no-pending-tests][] | 1 |
[no-promise-without-done-fail][] | 1 |
[no-spec-dupes][] | 1, `'block'` | `['block', 'branch']`
[no-suite-callback-args][] | 2 |
Expand Down Expand Up @@ -122,6 +123,7 @@ See [configuring rules][] for more information.
[no-expect-in-setup-teardown]: docs/rules/no-expect-in-setup-teardown.md
[no-focused-tests]: docs/rules/no-focused-tests.md
[no-global-setup]: docs/rules/no-global-setup.md
[no-pending-tests]: docs/rules/no-pending-tests.md
[no-promise-without-done-fail]: docs/rules/no-promise-without-done-fail.md
[no-spec-dupes]: docs/rules/no-spec-dupes.md
[no-suite-callback-args]: docs/rules/no-suite-callback-args.md
Expand Down
35 changes: 35 additions & 0 deletions docs/rules/no-pending-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Disallow use of pending tests (no-pending-tests)

Jasmine uses `pending` ("[pending specs][]") to mark a spec
as not implemented yet.

`pending` should only be used when creating a test suite skeleton.

[pending specs]: https://jasmine.github.io/api/3.5/global.html#pending

## Rule details

This rule triggers a **warning** (is set to **1** by default) whenever it
encounters `pending`.

The following patterns are considered warnings:

```js
it('My pending spec', function() { pending('I am pending'); });

describe('My suite', function() {
it('My pending spec', function() {
pending('I am pending');
});
});
```

The following patterns are not warnings:

```js
it('My spec', function() {});

describe('My suite', function() {
it('My spec', function() {});
});
```
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
'no-assign-spyon': require('./lib/rules/no-assign-spyon'),
'no-unsafe-spy': require('./lib/rules/no-unsafe-spy'),
'no-global-setup': require('./lib/rules/no-global-setup'),
'no-pending-tests': require('./lib/rules/no-pending-tests'),
'no-promise-without-done-fail': require('./lib/rules/no-promise-without-done-fail'),
'no-expect-in-setup-teardown': require('./lib/rules/no-expect-in-setup-teardown'),
'new-line-between-declarations': require('./lib/rules/new-line-between-declarations'),
Expand All @@ -39,6 +40,7 @@ module.exports = {
'jasmine/no-assign-spyon': 0,
'jasmine/no-unsafe-spy': 1,
'jasmine/no-global-setup': 2,
'jasmine/no-pending-tests': 1,
'jasmine/no-promise-without-done-fail': 1,
'jasmine/no-expect-in-setup-teardown': 1,
'jasmine/new-line-between-declarations': 1,
Expand Down
16 changes: 16 additions & 0 deletions lib/rules/no-pending-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

/**
* @fileoverview Disallow the use of focused tests
* @author Tom Vincent
*/

var prohibit = require('../helpers/prohibit')

module.exports = function (context) {
var prohibiteds = [
'pending'
]

return prohibit(prohibiteds, context)
}
35 changes: 35 additions & 0 deletions test/rules/no-pending-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

var rule = require('../../lib/rules/no-pending-tests')
var RuleTester = require('eslint').RuleTester

var eslintTester = new RuleTester()

eslintTester.run('no-pending-tests', rule, {
valid: [
'describe("", function() { it("", function() {} ) })',
'it("", function() {})'
],

invalid: [
{
// code: 'describe("My suite with pending test", function() { it("my pending test", function() { pending(); } });',
code: 'describe("My suite with pending test", function() { it("my pending test", function() { pending(); }); });',
errors: [
{
message: 'Unexpected pending.',
type: 'CallExpression'
}
]
},
{
code: 'it("My pending spec", function() { pending("I am pending"); });',
errors: [
{
message: 'Unexpected pending.',
type: 'CallExpression'
}
]
}
]
})

0 comments on commit ab30e3e

Please sign in to comment.