{"id":13464993,"url":"https://github.com/atlassian/jest-in-case","last_synced_at":"2025-12-29T14:24:32.430Z","repository":{"id":37752393,"uuid":"101966650","full_name":"atlassian/jest-in-case","owner":"atlassian","description":"Jest utility for creating variations of the same test","archived":false,"fork":false,"pushed_at":"2023-12-15T02:22:03.000Z","size":182,"stargazers_count":1060,"open_issues_count":14,"forks_count":19,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-19T16:10:04.252Z","etag":null,"topics":["jest","test","testing"],"latest_commit_sha":null,"homepage":"http://thejameskyle.com/jest-in-case.html","language":"JavaScript","has_issues":false,"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/atlassian.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-31T06:21:10.000Z","updated_at":"2025-04-06T04:02:51.000Z","dependencies_parsed_at":"2024-06-18T12:25:16.062Z","dependency_job_id":"026a32d3-2e76-41fb-991f-9849c86a3c2b","html_url":"https://github.com/atlassian/jest-in-case","commit_stats":{"total_commits":18,"total_committers":6,"mean_commits":3.0,"dds":0.6111111111111112,"last_synced_commit":"78fb05fd0a021fb183d0c78f0d13bc65c5dbfae3"},"previous_names":["thinkmill/jest-cases","thinkmill/jest-in-case"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fjest-in-case","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fjest-in-case/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fjest-in-case/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Fjest-in-case/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atlassian","download_url":"https://codeload.github.com/atlassian/jest-in-case/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"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","test","testing"],"created_at":"2024-07-31T14:00:54.398Z","updated_at":"2025-12-29T14:24:32.380Z","avatar_url":"https://github.com/atlassian.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jest-in-case\n\n\u003e [Jest](https://facebook.github.io/jest/) utility for creating variations of\n\u003e the same test\n\n## Example\n\n```js\nimport { add, subtract } from './math';\nimport cases from 'jest-in-case';\n\ncases('add(augend, addend)', opts =\u003e {\n  expect(add(opts.augend, opts.addend)).toBe(opts.total);\n}, [\n  { name: '1 + 1 = 2', augend: 1, addend: 1, total: 2 },\n  { name: '2 + 1 = 3', augend: 2, addend: 1, total: 3 },\n  { name: '3 + 1 = 4', augend: 3, addend: 1, total: 4 },\n]);\n```\n\n## Installation\n\n```sh\nyarn add --dev jest-in-case\n```\n\n## Usage\n\nIn your [Jest](https://facebook.github.io/jest/) tests, import `cases` from\n`jest-in-case`.\n\n```js\nimport cases from 'jest-in-case';\n// or\nconst cases = require('jest-in-case');\n```\n\nThen you can call `cases` with a `title`, a `tester`, and some `testCases`.\n\n```js\ncases(title, tester, testCases);\n```\n\n`testCases` can either be an array of objects with a `name` property:\n\n```js\ncases('add(augend, addend)', opts =\u003e {\n  expect(add(opts.augend, opts.addend)).toBe(opts.total);\n}, [\n  { name: '1 + 1 = 2', augend: 1, addend: 1, total: 2 },\n  { name: '2 + 1 = 3', augend: 2, addend: 1, total: 3 },\n  { name: '3 + 1 = 4', augend: 3, addend: 1, total: 4 },\n]);\n```\n\nOr an object of objects with the names as the keys:\n\n```js\ncases('subtract(minuend, subtrahend)', opts =\u003e {\n  expect(subtract(opts.minuend, opts.subtrahend)).toBe(opts.difference);\n}, {\n  '1 - 1 = 0': { minuend: 1, subtrahend: 1, difference: 0 },\n  '2 - 1 = 1': { minuend: 2, subtrahend: 1, difference: 1 },\n  '3 - 1 = 2': { minuend: 3, subtrahend: 1, difference: 2 },\n});\n```\n\nInside of a test case you can put whatever properties you want, except for\n`name`, `only`, or `skip`:\n\n```js\ncases('title', fn, [\n  { name: 'reserved 1', only: true, skip: true, whatever: 'you', want: 'here' },\n  { name: 'reserved 2', only: true, skip: true, whatever: 'you', want: 'here' },\n  { name: 'reserved 3', only: true, skip: true, whatever: 'you', want: 'here' },\n]);\n```\n\n- `name` is passed to `test(name, fn)` to become the name of your test\n- When `only` is set to `true` it will use Jest's `test.only` function\n- When `skip` is set to `true` it will use Jest's `test.skip` function\n\nThe `tester` function is called on each test case with your options:\n\n```js\ncases('title', opts =\u003e {\n  console.log('passed: ', opts);\n}, {\n  'test 1': { foo: 1 },\n  'test 2': { bar: 2 },\n  'test 3': { baz: 3 },\n});\n\n// passed: { foo: 1 }\n// passed: { bar: 2 }\n// passed: { baz: 3 }\n```\n\nYour tester function works just like functions passed to Jest's `test` function\ndo (Just with a prepended argument):\n\n```js\ncases('async functions', async opts =\u003e {\n  let result = await somethingAsync(opts.input);\n  expect(result).toEqual(opts.result);\n}, {\n  'test 1': { ... },\n  'test 2': { ... },\n});\n\ncases('done callback', (opts, done) =\u003e {\n  somethingAsync(opts.input, result =\u003e {\n    expect(result).toEqual(result);\n    done();\n  });\n}, {\n  'test 1': { ... },\n  'test 2': { ... },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Fjest-in-case","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatlassian%2Fjest-in-case","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Fjest-in-case/lists"}