Skip to content

confused .rejects example in Jest document #9143

@Jongmun-Park

Description

@Jongmun-Park

Hi.
I learned about .rejects function in Jest document example
https://jestjs.io/docs/en/tutorial-async#rejects

here is the example.

// Testing for async errors using `.rejects`.
it('tests error with rejects', () => {
  expect.assertions(1);
  return expect(user.getUserName(3)).rejects.toEqual({
    error: 'User with 3 not found.',
  });
});

// Or using async/await with `.rejects`.
it('tests error with async/await and rejects', async () => {
  expect.assertions(1);
  await expect(user.getUserName(3)).rejects.toEqual({
    error: 'User with 3 not found.',
  });
});

The example used expect.assertions(1);
but, i searched that it is necessary to use assertions with .rejects
then i found this issue 'removed useless expect.assertions'
#7131

so i suggest how about removing expect.assertions(1); code in the example.
becauese i was not sure whether I should used assertions.

thank u.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions