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

[Question] Is Jest a good fit for backend unit tests? #1368

Closed
Secretmapper opened this issue Aug 4, 2016 · 4 comments
Closed

[Question] Is Jest a good fit for backend unit tests? #1368

Secretmapper opened this issue Aug 4, 2016 · 4 comments

Comments

@Secretmapper
Copy link

Secretmapper commented Aug 4, 2016

I've been loving Jest so far testing React components.

I've used/been using Mocha/Jasmine for testing node backends though, and I just wanted to ask if it's possible (and recommended) to use Jest for backend testing, since I could not find any indication of it in the docs (React, React-Native, Async, Webpack, i.e. no Node)

I just tried using it, and unfortunately I hit an instant roadblock. brcypt triggers a [SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random() warning and the test fails due to a runtime error (TypeError: Path must be a string. Received undefined)

Is it possible to use Jest for backend testing right now, or is it not part of the project's scope and something like Jasmine be a better fit?

@Secretmapper Secretmapper changed the title Is Jest a good fit for backend unit tests? [Question] Is Jest a good fit for backend unit tests? Aug 4, 2016
@cpojer
Copy link
Member

cpojer commented Aug 4, 2016

What kind of backend testing are you trying to do? Jest itself uses Jest for tests and loads of libraries use Jest for testing. Can you provide a repository on github that I can use to npm install and npm test that shows your issue?

Two things I recommend: try setting "automock": false and "testEnvironment": "node". If your other tests rely on this, you can create a separate Jest config and run jest with --config=pathToConfig.json and use modulePathIgnorePatterns to ignore the frontend tests.

@Secretmapper
Copy link
Author

Secretmapper commented Aug 4, 2016

Thanks for the quick reply @cpojer!

Glad to hear Jest can be used with Node! I was thinking it would, since it's essentially a testing library and the API should just work, but felt the need to ask it especially since there's almost no resources online showing it being used with Node backends and mostly with react (or my Google-Fu just wasn't good enough).

I was already mocking my node_modules so that wasn't the case, but testEnvironment: node did the trick!

Cheers!

@cpojer
Copy link
Member

cpojer commented Aug 4, 2016

Yes, the default environment (jsdom) doesn't always lend itself well to node testing. Another benefit is that the node env will load 500ms faster (effectively instant) because jsdom is kinda slow.

@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 14, 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

2 participants