Can I use Jasmine functions from a Jest test? - jestjs

I've read that Jest is built on top of Jasmine, so I was assuming I could still call Jasmine functions from a Jest test.
But I'm getting things like "spyOnProperty is not defined" from my Jest test (even though I have Jasmine and Jasmine types defined in the project).
Is this just not possible?

Related

ReferenceError: AudioContext is not defined is appearing in my Jest Suite

I get this error ReferenceError: AudioContext is not defined in all of my Jest tests. I don't use it in my test cases -- 100% sure. But I noticed one of the external libraries is using it (library is proprietary and not in npm). But that library is not even part of any test files. Does anyone have an idea how to circumvent this annoying issue?

why mocha doesn't show passed tests ? like jest. it just says 5 test passed not more details

I am new to mocha but experienced in jest. so when I run my test I hope it should display a complete log. but it just says 9 test passed. I am using nyan reporter
here is a screen shot
I recommend using mochawesome reporter and utilizing a .mocharc.js file or .mocharc.json file for your configurations unless you want to run mocha programmatically

Is it possible to generate the test coverage for a project using Jest which is tested with Chai JS?

I have a project which has various unit tests running successfully using chai js.
Is it possible to use Jest and generate the coverage for this project without rewriting unit tests with Jest JS?
Please provide any documentation to support
It is not possible to do so without rewriting unit tests with Jest JS.
You can search for plugins otherwise
It isn't because Jest has no way to understand your Chai tests.
You will have to migrate them to Jest. As their interfaces are pretty much similar it will not be a painful task.
Airbnb details why and how they do it from Mocha to Jest on a large codebase in this Medium post.
It is possible to migrate from chai using jest-codemods. However you might have to rewrite some configurations and tests(for version compatibility). You can automate changes to your codebase through this.
Please go through these links for further details.
https://jestjs.io/docs/en/migration-guide
https://github.com/skovhus/jest-codemods

Node.js test coverage

Could anyone, please, recommend simple test coverage tool for Node.js without using Mocha because I use simple functions from assert module of Node in my own test framework.
The standard library for code coverage is nyc, so that's my suggestion; however, you aren't going to get code coverage to work with a test framework you came up with yourself for free -- you'll need to make sure you are instrumenting the appropriate source files so the report contains what you expect.
The following links, which discuss non-standard uses of nyc (non-standard meaning, not jasmine or mocha) might be useful - one for classic istanbul, one for the newer nyc:
https://github.com/gotwarlost/istanbul/issues/574
https://github.com/istanbuljs/nyc/issues/548
You can use Jest and Supertest.
Jest -> https://jestjs.io/
SuperTest -> https://www.npmjs.com/package/supertest

Unit testing vs Integration testing of an Express.js app

I'm writing tests for an Express.js app and I don't know how to choose between unit tests and integration tests.
currently I experimented with:
unit tests - using Sinon for stubs/mocks/spies and Injects for dependency injection to modules. with this approach I have to stub MongoDB and other external methods.
I thought about unit testing the individual routes and then using an integration test to verify that the correct routes are actually invoked.
integration tests - using Supertest and Superagent, much less code to write (no need to mock/stub anything) but a test environment should exist (databases, etc..)
I'm using Mocha to run both styles of tests.
how should I choose between those two different approaches ?
You should probably do both. Unit test each non-helper method that does non-trivial work. Run the whole thing through a few integration tests. If you find yourself having to do tons and tons and tons of mocks and stubs, it's probably a sign to refactor.

Resources