Skip to content

fix(expect): fix sinon-chai style API#9943

Open
hi-ogawa wants to merge 6 commits intovitest-dev:mainfrom
hi-ogawa:fix-expect-fix-sinon-chai-api
Open

fix(expect): fix sinon-chai style API#9943
hi-ogawa wants to merge 6 commits intovitest-dev:mainfrom
hi-ogawa:fix-expect-fix-sinon-chai-api

Conversation

@hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Mar 22, 2026

Description

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link

netlify bot commented Mar 22, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cfea456
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69bf7f8d5ecbc20008e036ba
😎 Deploy Preview https://deploy-preview-9943--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa changed the title fix(expect): fix sinon-chai API fix(expect): fix sinon-chai style API Mar 22, 2026
Comment on lines -745 to -746
| `spy.returned` | `returned` | Spy returned successfully |
| `spy.returnedWith(value)` | `returnedWith(value)` | Spy returned specific value |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like this was oversight or hallucination. Probably no way back to remove returnedWith, so now returnedWith and returned are essentially same.

delegateTo: keyof Assertion,
) {
utils.addChainableMethod(
utils.addMethod(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Chai's addChainableMethod uses Object.defineProperty({ get }) and addMethod uses simple assignment. Thus addMethod allows later addMethod to take over, but addChainableMethod breaks.

Not sure what was the purpose but ours aren't chainable anyways, so just switched to addMethod.

// https://github.com/chaijs/sinon-chai
defProperty('called', 'toHaveBeenCalled')
defProperty('calledOnce', 'toHaveBeenCalledOnce')
defProperty('returned', 'toHaveReturned')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

defProperty uses defineProperty(get), so later call of addMethod('returned') by sinon-chai breaks.

Comment on lines +82 to +83
// TODO: implement
// defMethod('thrown', 'toHaveThrown')
Copy link
Collaborator Author

@hi-ogawa hi-ogawa Mar 22, 2026

Choose a reason for hiding this comment

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

Not sure if we'd implement but just noted that they aren't fully ported yet.

@hi-ogawa hi-ogawa marked this pull request as ready for review March 22, 2026 05:50
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.

4.1.0 upgrade breaking sinon-chai

1 participant