Add JS Test READMEAdd JS Test is an extension that quickly adds a template test file for a javascript/typescript-module using either jest, vitest or mocha/chai. By right-clicking on a module and selecting Add Test this extension will analyze your file and create the appropriate, corresponding test file for your module. In addition to standard unit tests the extension also supports adding tests for react components, mainly using @testing-library/react (but also Enzyme for legacy projects). UsageWhat?Let's say that you have this file in your project:
If you right-click on the file in the explorer and select Add Test, the following file will be generated:
Now, were you to use JavaScript instead of TypeScript, the appropriate extension will be used. And if you use jest or mocha instead of vitest, that will be imported. Likewise, if you have a JSX/TSX file that looks like this:
Then you right-click on this file and select Add React Component Test and it will add a test similar to this:
SettingsBy default, this extension will try to figure out which test framework to use by analyzing your package.json file. In case this file cannot be found, parsed or in other ways used, it will default to jest for unit tests and @testing-library/react for component testing. If you, however, want to explicitly set which test framework to use, have the files be called x.spec.ts instead of x.test.ts, or change any other setting, these things are configurable in your settings file. Just open VS Code Settings and search for add-js-test to view and edit them: Key bindingsThe command is automatically bound to the short cut To change this binding, right-click on the row and select DevelopmentIf you want to fork this, or contribute, just clone the repository and: Install the dependencies
Then either run the dev watch:
Or just make your changes and, if you're running VS Code while developing this, WHICH I REALLY SUGGEST YOU DO, then press F5 to build and run it in a new instance of VS Code. There are test files available in the ./test-suite-folder in this repo, you can use these to test various use-cases. And if you're missing a case, then new additions are always welcome! DocumentationHere are some links to documentation that may be of assistance:
|