Skip to content

Use Vitest and expect methods for testing suite#1245

Merged
arturmuller merged 2 commits intoianstormtaylor:mainfrom
yeoffrey:reorg-tests
Jun 21, 2024
Merged

Use Vitest and expect methods for testing suite#1245
arturmuller merged 2 commits intoianstormtaylor:mainfrom
yeoffrey:reorg-tests

Conversation

@yeoffrey
Copy link
Contributor

@yeoffrey yeoffrey commented Jun 10, 2024

In this PR, the test suite has been modified:

  • deepStrictEqual and deepEqual have been changed to .toStrictEqual for objects and arrays and .toBe for literals.
  • Moved the deprecated tests to their own file.
  • I've opted to keep the usage of throws and doesNotThrow because it offers a nicer api to check whether an error was thrown or not than the Jesty expect solution.
  • Expect documentation from Vitest for your reference!

#1244

@yeoffrey yeoffrey marked this pull request as draft June 10, 2024 21:42
@yeoffrey yeoffrey marked this pull request as ready for review June 10, 2024 22:05
@yeoffrey yeoffrey changed the title Use vitest except where possible and organize tests Use Vitest and except methods for testing suite Jun 10, 2024
@arturmuller arturmuller self-requested a review June 20, 2024 16:26
Copy link
Collaborator

@arturmuller arturmuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thank you @yeoffrey! 🙌

I would change the throws/doesNotThrow calls as well. Unless we really have to, I would avoid special cases and exceptions — I doubt that new contributors would realise that we use assert for error handling, but Vitest for everything else.

I tested this snippet and it seems to print almost the same exact message like assert, so I don't think we're losing any more functionality.

it('custom error message', () => {
  expect(() => string().create(42, 'Not a string!')).toThrow(
    expect.objectContaining({
      message: 'Not a string!',
      cause: 'Expected a string, but received: 42',
    })
  )
})

yeoffrey and others added 2 commits June 20, 2024 18:00
- CallTracker has been deprecated in Node.js
- vi.fn() is probably more familiar to Vitest users
@arturmuller arturmuller changed the title Use Vitest and except methods for testing suite Use Vitest and expect methods for testing suite Jun 21, 2024
@arturmuller arturmuller self-requested a review June 21, 2024 14:58
@arturmuller arturmuller merged commit 625cea5 into ianstormtaylor:main Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants