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

One-line expects generate "Jest: it and test must return either a Promise or undefined" #1

Open
amercier opened this issue Jun 21, 2018 · 1 comment

Comments

@amercier
Copy link

amercier commented Jun 21, 2018

Summary

jest-chain throws an error when used with one-line expect (arrow functions).

Description

Please consider the following code:

function sum(a, b) { return a + b; }

describe('sum', () => {
  it('returns 4 for [1, 3]', () => expect(sum(1, 3)).toBe(4));
  it('returns -2 for [1, -3]', () => expect(sum(1, -3)).toBe(-2));
  it('returns 3 for [0, 3]', () => expect(sum(0, 3)).toBe(3));
});
  1. Running this without jest-chain works as expected.
  2. Running this with jest-chain fails with the following error:
Jest: `it` and `test` must return either a Promise or undefined.

      at Object.asyncFn (node_modules/jest-jasmine2/build/jasmine_async.js:126:11)

Versions

  • package version: 0.7.2
  • node version: v10.4.1
  • npm version: 6.1.0

Notes

  1. FWIW, I think one-line arrow functions should be supported, as they add a lot of clarity in some cases.
  2. I use the following as a (hopefully temporary) workaround:
// Workaround for https://github.com/mattphillips/jest-chain/issues/1
const it2 = (message, fn) => it(message, async (...args) => fn(...args));

describe('sum', () => {
  it2('returns 4 for [1, 3]', () => expect(sum(1, 3)).toBe(4));
  it2('returns -2 for [1, -3]', () => expect(sum(1, -3)).toBe(-2));
  it2('returns 3 for [0, 3]', () => expect(sum(0, 3)).toBe(3));
});
@mattphillips
Copy link
Owner

Hey @amercier thanks for raising this, I wasn't aware of this error inside of Jest 😄

This one will be super hard to solve in userland and feels like potentially it needs some more thought in Jest's core itself. I've raised an issue (above) in Jest to remove this error so I'll keep this open for now and hopefully we can get this closed off by stopping Jest from throwing when returning something other than a Promise/undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants