2.0.0 • Published 7 years ago

eslint-plugin-should-promised v2.0.0

Weekly downloads
487
License
MIT
Repository
github
Last release
7 years ago

NPM Version Build Status Coverage Status Peer Dependencies

eslint-plugin-should-promised

Eslint rule for checking that should-promised assertions return

Install

$ npm i -D eslint-plugin-should-promised

Configure

{
  "plugins": [
    "should-promised"
  ],
  "rules": {
    "should-promised/return-promise": 2
  }
}

Rules

Require promise assertions to return or await (return-promise)

This rule is intended to be used with the should assertion library.

When testing an async function by returning a promise to mocha it is important to remember to actually return the promise. Forgetting to return will cause the test case to pass even if the promise is eventually rejected.

This rule will point out when a should assertion is made without returning.

Rule Details

This rule looks for any of the properties Promise, fulfilled, fulfilledWith, rejected, rejectedWith, finally and eventually.

The following patterns are considered warnings:

describe('forgetting to return the promise', () => {

  it('should report when not returning the promise from should.be.fulfilled', () => {
    promiseFn().should.be.fulfilled();
  });

  it('should report when not returning the promise from should.eventually', () => {
    promiseFn().should.eventually.eql(1);
  });

});

These patterns would not be considered warnings:

describe('returning the promise', () => {

  it('should not report when returning the promise from should.be.fulfilled', () => {
    return promiseFn().should.be.fulfilled();
  });

  it('should allow implicit return in a single expression arrow function', () =>
    promiseFn().should.be.fulfilled());

  it('should not report when using async/await', async () => {
    await promiseFn().should.eventually.eql(expected_value);
  });

  it('should not report when using a generator function', function * () {
    yield generatorFn().should.eventually.eql(expected_value);
  });

});

Further Reading

2.0.0

7 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago