{"id":26587510,"url":"https://github.com/wistudent/jest-each-improved-types","last_synced_at":"2025-03-23T12:20:11.611Z","repository":{"id":36961453,"uuid":"296925294","full_name":"WIStudent/jest-each-improved-types","owner":"WIStudent","description":"Using recursive conditional types from typescript 4.1 to improve typings of table driven jest-each tests","archived":false,"fork":false,"pushed_at":"2023-12-07T01:38:47.000Z","size":2698,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T14:17:41.617Z","etag":null,"topics":["jest","jest-each","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WIStudent.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-09-19T18:09:03.000Z","updated_at":"2023-02-25T02:01:45.000Z","dependencies_parsed_at":"2023-01-17T08:45:33.340Z","dependency_job_id":null,"html_url":"https://github.com/WIStudent/jest-each-improved-types","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WIStudent%2Fjest-each-improved-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WIStudent%2Fjest-each-improved-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WIStudent%2Fjest-each-improved-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WIStudent%2Fjest-each-improved-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WIStudent","download_url":"https://codeload.github.com/WIStudent/jest-each-improved-types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245098896,"owners_count":20560491,"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":["jest","jest-each","typescript"],"created_at":"2025-03-23T12:20:10.908Z","updated_at":"2025-03-23T12:20:11.579Z","avatar_url":"https://github.com/WIStudent.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-each-improved-types\n[![npm version](https://badge.fury.io/js/%40wistudent%2Fjest-each-improved-types.svg)](https://badge.fury.io/js/%40wistudent%2Fjest-each-improved-types)\n\nWhen using `.each` with the table notation, it is possible to set the type of the test function argument on the `.each` function as a generic argument:\n```ts\nimport {test, expect} from \"@jest/globals\";\n\ntest.each\u003c{a: string, b: number, expected: boolean}\u003e`\na      | b    | expected\n${'1'} | ${1} | ${true}\n${'1'} | ${2} | ${false}\n`('some test', ({a, b, expected}) =\u003e {\n  expect(a === `${b}`).toBe(expected)\n});\n```\n\nBut this only sets the type for the test function argument, it does not ensure that the correct values were used inside the table. The following does not result in a typescript error:\n```ts\nimport {test, expect} from \"@jest/globals\";\n\ntest.each\u003c{a: string, b: number, expected: boolean}\u003e`\na            | b     | expected\n${undefined} | ${{}} | ${null}\n`('some test', ({a, b, expected}) =\u003e {\n  expect(a === `${b}`).toBe(expected)\n});\n```\n\nThis package adds an additional way of providing type definitons to `.each` table tests that ensures that the values used inside the table are compatible with the provided typescript types. It does by reexporting `@jest/globals` and extending the type definition of the `.each` function.\n\n```ts\nimport {test, expect} from \"@wistudent/jest-each-improved-types\"\n\ntest.each\u003c[['a', string], ['b', number], ['expected', boolean]], 2\u003e`\na      | b    | expected\n${'1'} | ${1} | ${true}\n${'1'} | ${2} | ${false}\n`('some test', ({a, b, expected}) =\u003e {\n  expect(a === `${b}`).toBe(expected)\n});\n```\n\nInstead of using an interface as the generic argument, a tuple of Key-Type pairs and the number of rows is used. Using a value with the wrong type inside the table, or the number of values not being (*Number of Key-Type pairs* * *Declared number of rows*), will result in a typescript error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwistudent%2Fjest-each-improved-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwistudent%2Fjest-each-improved-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwistudent%2Fjest-each-improved-types/lists"}