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

example expect().rejects.toThrow not working as expected #4945

Closed
eric4545 opened this issue Nov 24, 2017 · 4 comments
Closed

example expect().rejects.toThrow not working as expected #4945

eric4545 opened this issue Nov 24, 2017 · 4 comments

Comments

@eric4545
Copy link

eric4545 commented Nov 24, 2017

Do you want to request a feature or report a bug?

What is the current behavior?

Test case cannot pass got following

 FAIL  ./test.spec.js
  ✕ rejects to octopus (10ms)
  ✕ rejects to octopus (2ms)

  ● rejects to octopus

    expect(function).toThrow(string)

    Received value must be a function, but instead "object" was found

      at Object.<anonymous> (node_modules/expect/build/index.js:162:51)
          at Generator.throw (<anonymous>)
      at step (node_modules/expect/build/index.js:40:727)
      at node_modules/expect/build/index.js:40:926
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

Following example in https://facebook.github.io/jest/docs/en/expect.html#rejects

// test.spec.js
test('rejects to octopus', async () => {
	await expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus');
});
test('rejects to octopus', () => {
	// make sure to add a return statement
	return expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus');
});

jest test.spec.js

What is the expected behavior?

expected test case should be pass.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

{
   jest: "21.2.1",
   node: "v8.9.1",
   yarn: "1.3.2",
   os: "Ubuntu 16.04.3 LTS"
}
@eric4545
Copy link
Author

#4884

@JamesTheHacker
Copy link

Does this work in the current stable release? I'm using 21.2.1 and still getting issues.

 test('Testing rejects.toThrow', async () => {
    await expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus');
  });

I still get the same error:

expect(function).toThrow(string)
    Received value must be a function, but instead "object" was found

And if not how can I solve this problem without using a non stable branch?

@SimenB
Copy link
Member

SimenB commented Nov 24, 2017

This is just supported in the beta for now (new stable coming in the not too distant future). Please see #3601 for workarounds

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants