Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.

feat: add Jest to AVA pattern#117

Open
sullvn wants to merge 1 commit intogetgrit:mainfrom
sullvn:jest-to-ava
Open

feat: add Jest to AVA pattern#117
sullvn wants to merge 1 commit intogetgrit:mainfrom
sullvn:jest-to-ava

Conversation

@sullvn
Copy link

@sullvn sullvn commented Jul 11, 2023

Work-in-progress pattern for converting Jest tests to AVA tests.

Minimal test case:

test('test name', () => {
  const actual = { value: 3 }
  expect(actual).toEqual({ value: 3 })
  expect(actual).not.toEqual({ value: 4 })

  const ref1 = { singleton: true }
  const ref2 = ref1
  expect(ref1).toBe(ref2)
  expect(ref1).not.toBe({ singleton: true })

  expect([0, 1, 2]).toHaveLength(3)
  expect([0, 1, 2]).not.toHaveLength(4)

  expect(Math.PI).toBeCloseTo(3.14, 5)
  expect(Math.PI).not.toBeCloseTo(3.14, 5)
  expect(Math.PI).toBeCloseTo(3.14)
  expect(Math.PI).not.toBeCloseTo(3.14)

  const testRegex = /123?/
  expect('12').toMatch(testRegex)
  expect('ab').toMatch(/abc?/)
  expect('xyz').toMatch('xyz')
})

Should result in:

test('test name', t => {
  const actual = { value: 3 }
  t.deepEqual(actual, { value: 3 })
  t.notDeepEqual(actual, { value: 4 })

  const ref1 = { singleton: true }
  const ref2 = ref1
  t.is(ref1, ref2)
  t.not(ref1, { singleton: true })

  t.is([0, 1, 2].length, 3)
  t.not([0, 1, 2].length, 4)

  t.true(Math.abs(Math.PI - 3.14) < 10 ** -5 / 2)
  t.false(Math.abs(Math.PI - 3.14) < 10 ** -5 / 2)
  t.true(Math.abs(Math.PI - 3.14) < 0.005)
  t.false(Math.abs(Math.PI - 3.14) < 0.005)

  const testRegex = /123?/
  t.regex('12', testRegex)
  t.regex('ab', /abc?/)
  t.is('xyz', 'xyz')})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant