Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement test.each and describe.each #3622

Closed
Electroid opened this issue Jul 12, 2023 · 4 comments
Closed

Implement test.each and describe.each #3622

Electroid opened this issue Jul 12, 2023 · 4 comments
Labels
enhancement New feature or request jest Something related to the `bun test` runner

Comments

@Electroid
Copy link
Contributor

import { test, expect } from "bun:test"; 

test.each([
  [1, 1, 2],
  [1, 2, 3],
  [2, 1, 3],
])('.add(%i, %i)', (a, b, expected) => {
  expect(a + b).toBe(expected);
});

test.each([
  {a: 1, b: 1, expected: 2},
  {a: 1, b: 2, expected: 3},
  {a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
  expect(a + b).toBe(expected);
});

test.each`
  a    | b    | expected
  ${1} | ${1} | ${2}
  ${1} | ${2} | ${3}
  ${2} | ${1} | ${3}
`('returns $expected when $a is added to $b', ({a, b, expected}) => {
  expect(a + b).toBe(expected);
});
@Electroid Electroid added enhancement New feature or request jest Something related to the `bun test` runner labels Jul 12, 2023
@wojtekmaj
Copy link

wojtekmaj commented Nov 6, 2023

Why is this still open? It looks like it's available, only missing documentation?

@Jarred-Sumner
Copy link
Collaborator

Good question. It is available. Our documentation is out of date.

@coodoo
Copy link

coodoo commented Apr 17, 2024

@Jarred-Sumner Just ran following test copied directly from above doc and seemed $a and $b were not substituted correctly, is this expected behavior or known issue?

test.each([
  {a: 1, b: 1, expected: 2},
  {a: 1, b: 2, expected: 3},
  {a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
  expect(a + b).toBe(expected);
})

and got this result:

bun test v1.1.4 (fbe2fe0c)

z.test.js:
 .add($a, $b) [1.30ms]
 .add($a, $b) [0.02ms]
 .add($a, $b)

 3 pass
 0 fail
 3 expect() calls
Ran 3 tests across 1 files. [266.00ms]

I would expect the result should be

bun test v1.1.4 (fbe2fe0c)

z.test.js:
 .add(1, 1) [1.30ms]
 .add(1, 2) [0.02ms]
 .add(1, 1)

 3 pass
 0 fail
 3 expect() calls
Ran 3 tests across 1 files. [266.00ms]

@coodoo
Copy link

coodoo commented Apr 17, 2024

and seemed this is a known issue being tracked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jest Something related to the `bun test` runner
Projects
None yet
Development

No branches or pull requests

4 participants