Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

[Tests] Testing for promise does not fail #5185

@lukaszsobek

Description

@lukaszsobek

We have several situations in our tests where we want the return value of a function and use .toBe(...) to compare it with the desired outcome. There is no problem with synchronous functions to be handled this way. But there might be a problem with asynchronous functions, as they require an additional step, where we do not compare the result of the function itself but chain the expect.toBe into the .then part of the test. e.g.

test('the data is peanut butter', () => {
  expect.assertions(1);
  return fetchData().then(data => {
    expect(data).toBe('peanut butter');
  });
});

Or wait for the state to update with waitForState(). Otherwise we will pass tests even though they should be failing:
screenshot-20180124074207-544x781

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Priority

None yet

Jira

None yet

Severity

None yet

Estimate

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions