{"id":24256047,"url":"https://github.com/js-test-gen/js-test-gen","last_synced_at":"2025-09-23T19:30:25.264Z","repository":{"id":57283767,"uuid":"122140093","full_name":"js-test-gen/js-test-gen","owner":"js-test-gen","description":"Generating js test templates with a little help from babel \u0026 prettier :vhs:","archived":false,"fork":false,"pushed_at":"2018-03-12T01:13:31.000Z","size":966,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-14T01:11:51.746Z","etag":null,"topics":["babel","jest","js","js-templates","mocha","prettier","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/js-test-gen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-20T00:52:36.000Z","updated_at":"2023-08-29T09:09:53.000Z","dependencies_parsed_at":"2022-09-19T22:32:27.946Z","dependency_job_id":null,"html_url":"https://github.com/js-test-gen/js-test-gen","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-test-gen%2Fjs-test-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-test-gen%2Fjs-test-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-test-gen%2Fjs-test-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/js-test-gen%2Fjs-test-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/js-test-gen","download_url":"https://codeload.github.com/js-test-gen/js-test-gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233993696,"owners_count":18762814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel","jest","js","js-templates","mocha","prettier","unit-testing"],"created_at":"2025-01-15T04:46:16.637Z","updated_at":"2025-09-23T19:30:24.707Z","avatar_url":"https://github.com/js-test-gen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [![js-test-gen](media/jsTestGen.png)](https://js-test-gen.github.io)\n\njs-test-gen is an opinionated unit test template generator using babel and prettier.\n\nIt uses babel to identify what modules are being exported. It then generates a test template and formats the template using prettier.\n\n[![CircleCI](https://circleci.com/gh/js-test-gen/js-test-gen.svg?style=svg)](https://circleci.com/gh/js-test-gen/js-test-gen)\n\n## Installation\n\n`npm install js-tes-gen`\n\nor\n\n`yarn add js-test-gen`\n\n## Input\n\n```javascript\n//name of this file is myfuncs.js\n\nexport const someModule1 = () =\u003e {};\nexport const someModule2 = () =\u003e {};\n\nconst someModule = () =\u003e {};\n\nexport default someModule;\n```\n\n## Output\n\n```javascript\nimport someModule, { someModule1, someModule2 } from \"./myfuncs\";\n\ndescribe(\"someModule\", () =\u003e {\n  it(\"should fail auto generated test\", () =\u003e {\n    expect(someModule()).toBe(false);\n  });\n});\ndescribe(\"someModule1\", () =\u003e {\n  it(\"should fail auto generated test\", () =\u003e {\n    expect(someModule1()).toBe(false);\n  });\n});\ndescribe(\"someModule2\", () =\u003e {\n  it(\"should fail auto generated test\", () =\u003e {\n    expect(someModule2()).toBe(false);\n  });\n});\n```\n\n## API\n\n### `generateTestTemplate({contents, srcfileName, importFromPath, typeSystem})`\n\n`generateTestTemplate` is used to generate a complete js unit test template.\n\n| property         | type                 | description                                                                                     |\n| ---------------- | -------------------- | ----------------------------------------------------------------------------------------------- |\n| `contents`       | `string`             | The JS contents to generate a test from.                                                        |\n| `srcFileName`    | `string`             | The name of the JS module the test is being created for.                                        |\n| `importFromPath` | `string`             | The path of where the module is located in relation to the generated test file E.G `.` or `../` |\n| `typeSystem`     | `FLOW or TYPESCRIPT` | If the js module is using a type system this needs to be specified.                             |\n\n### `generateTest(contents, typeSystem)`\n\n`generateTest` is used to generate test cases from given js contents.\n\n| arguments    | type                 | description                                                           |\n| ------------ | -------------------- | --------------------------------------------------------------------- |\n| `contents`   | `string`             | The JS contents to generate a test from.                              |\n| `typeSystem` | `FLOW or TYPESCRIPT` | If the js contents is using a type system this needs to be specified. |\n\n## Usage\n\n```javascript\nimport { generateTestTemplate } from \"js-test-gen\";\n\nconst contentToParse = `export const addOne = (x) =\u003e x +1`;\n\nconst testTemplate = generateTestTemplate({\n  contents: contentsToParse, // contents of the mod\n  srcFileName: \"addOne\", // the name of the mod we want to test\n  importFromPath: \"..\" // where the test should import the mod from\n});\n```\n\n### result\n\n```javascript\nimport { addOne } from \"../addOne\";\n\ndescribe(\"addOne\", () =\u003e {\n  it(\"should fail auto generated test\", () =\u003e {\n    expect(addOne()).toBe(false);\n  });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-test-gen%2Fjs-test-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjs-test-gen%2Fjs-test-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjs-test-gen%2Fjs-test-gen/lists"}