An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
Write less, test faster with jest-test-gen
Hello everyone
First time posting here in the dev.to community!
What is jest-test-gen
I wanted to introduce a small cli utility jest-test-gen that I wrote to speed up writing Jest unit tests.
Every time I start writing a new test file for my code some initial boilerplate is always required:
- import all the exports from the source file to be tested
- import the external dependencies used in my source file
- setup jest mocks for the dependencies used in the source code
- create tests blocks for every exported function / class method in my source file.
I wanted to automate part of this process by parsing the source file and generating an initial test file containing the initial scaffolding, this way I can quickly start writing the actual logic for my tests.
How to use it
To generate a test file just install the tool
npm i -g jest-test-gen
and invoke it passing the path to your source file as the first argument:
jest-test-gen ~/demoproject/src/services/myServiceClass.js
The tool will generate a file named myServiceClass.generated.test.js
in the same folder.
Try it out and give it a like here or the repo if you find it useful.
You can find the repo here: jest-test-gen on Github
Original Link: https://dev.to/egm0121/write-less-test-faster-with-jest-test-gen-3lm0
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To