vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Show example chai.use example

Open emahuni opened this issue 3 years ago • 3 comments

Show how to extend vitest.chai using chai.use for existing plugins or ones that the developer creates. It's not clear in the documentation how to do this and I believe this is the place to just briefly mention it.

emahuni avatar Aug 19 '22 11:08 emahuni

I am not sure if we should guide this. While we already provide built-in mocking, I'd consider using Sinon would be a bit niche and advanced usage. Guiding here might make it a bit misleading.

antfu avatar Aug 29 '22 00:08 antfu

I am not sure if we should guide this. While we already provide built-in mocking, I'd consider using Sinon would be a bit niche and advanced usage. Guiding here might make it a bit misleading.

oh i see. What can we change the example to? The real reason here is just to show how to use Chai plugins. The documentation was somehow missing that. I had to go through a bit of digging to figure it out. Just documenting it will remove that hustle.

emahuni avatar Aug 30 '22 12:08 emahuni

I am not sure if we should guide this. While we already provide built-in mocking, I'd consider using Sinon would be a bit niche and advanced usage. Guiding here might make it a bit misleading.

oh i see. What can we change the example to? The real reason here is just to show how to use Chai plugins. The documentation was somehow missing that. I had to go through a bit of digging to figure it out. Just documenting it will remove that hustle.

May you edit with the appropriate example plugin?

emahuni avatar Aug 30 '22 12:08 emahuni

this would be a great addition to the documentation. since migrating to vitest, i've been using import chai from 'chai' rather than import { chai } from 'vitest' in my setup file. i didn't realize i should've been using the latter until upgrading to 0.28.4 and i started getting Invalid Chai property errors

unicornware avatar Feb 08 '23 04:02 unicornware

also, as far as examples go, would showing how to modify chai.config work?

maybe something like this:

import { chai } from 'vitest'

chai.config.includeStack = true
chai.config.truncateThreshold = 0

unicornware avatar Feb 08 '23 04:02 unicornware

also, as far as examples go, would showing how to modify chai.config work?

We support chaiConfig directly in the config now, so I don't think this is necessary.

But it would be nice to have a mention about chai.use in "Extending Matchers", but I think it should be explained in detail - not just reference other libraries, but shows how to add your own matcher.

@emahuni do you think you can add this? Or should this PR be closed?

sheremet-va avatar Jun 19 '23 12:06 sheremet-va

Seems like the original author cannot work on this PR anymore (I asked if this should be closed a year ago). Feel free to open a new PR.

sheremet-va avatar Jul 01 '24 16:07 sheremet-va