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

Use Vitest and expect methods for testing suite #1245

Merged
merged 2 commits into from
Jun 21, 2024

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 force-pushed the reorg-tests branch 2 times, most recently from 29f535e to 9e4bf4c Compare June 10, 2024 21:54
@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',
    })
  )
})

- 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
3 checks passed
yeoffrey added a commit to yeoffrey/superstruct that referenced this pull request Jun 21, 2024
* Use vitest except where possible and organize tests

* Use vi.fn() instead of CallTracker in 'deprecated' helper

- CallTracker has been deprecated in Node.js
- vi.fn() is probably more familiar to Vitest users

---------

Co-authored-by: Artur Müller <[email protected]>
yeoffrey added a commit to yeoffrey/superstruct that referenced this pull request Jun 21, 2024
* Use vitest except where possible and organize tests

* Use vi.fn() instead of CallTracker in 'deprecated' helper

- CallTracker has been deprecated in Node.js
- vi.fn() is probably more familiar to Vitest users

---------

Co-authored-by: Artur Müller <[email protected]>
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.

None yet

2 participants