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 f…


This content originally appeared on DEV Community and was authored by Giulio Dellorbo

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


This content originally appeared on DEV Community and was authored by Giulio Dellorbo


Print Share Comment Cite Upload Translate Updates
APA

Giulio Dellorbo | Sciencx (2021-10-17T19:50:57+00:00) Write less, test faster with jest-test-gen. Retrieved from https://www.scien.cx/2021/10/17/write-less-test-faster-with-jest-test-gen/

MLA
" » Write less, test faster with jest-test-gen." Giulio Dellorbo | Sciencx - Sunday October 17, 2021, https://www.scien.cx/2021/10/17/write-less-test-faster-with-jest-test-gen/
HARVARD
Giulio Dellorbo | Sciencx Sunday October 17, 2021 » Write less, test faster with jest-test-gen., viewed ,<https://www.scien.cx/2021/10/17/write-less-test-faster-with-jest-test-gen/>
VANCOUVER
Giulio Dellorbo | Sciencx - » Write less, test faster with jest-test-gen. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/17/write-less-test-faster-with-jest-test-gen/
CHICAGO
" » Write less, test faster with jest-test-gen." Giulio Dellorbo | Sciencx - Accessed . https://www.scien.cx/2021/10/17/write-less-test-faster-with-jest-test-gen/
IEEE
" » Write less, test faster with jest-test-gen." Giulio Dellorbo | Sciencx [Online]. Available: https://www.scien.cx/2021/10/17/write-less-test-faster-with-jest-test-gen/. [Accessed: ]
rf:citation
» Write less, test faster with jest-test-gen | Giulio Dellorbo | Sciencx | https://www.scien.cx/2021/10/17/write-less-test-faster-with-jest-test-gen/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.