Comments (9)
I added these instructions in #610, but I'm not a Vitest user and wasn't sure they were complete, so thank you for chiming in about where they need more work. Thank you also for the reproduction examples! It really helps someone like me that's kinda stumbling my way through Vitest stuff. I will take a look this weekend and see what I can come up with.
from jest-extended.
PR to allow declaration merging: #653
from jest-extended.
@keeganwitt That worked for me!
Here's the updated stackblitz that shows it working: https://stackblitz.com/edit/vitest-dev-vitest-whsqfe?file=test%2Fextended.test.ts
import 'jest-extended';
import 'vitest';
interface MyCustomMatchers {
toBeFoo(): any;
}
declare module 'vitest' {
interface Assertion<T = any> extends CustomMatchers<T>, MyCustomMatchers {}
interface AsymmetricMatchersContaining<T = any>
extends CustomMatchers<T>,
MyCustomMatchers {}
interface ExpectStatic extends CustomMatchers, MyCustomMatchers {}
}
from jest-extended.
Related issue I've just submitted: #652
I think the issue is that the CustomMatcher
interface is not exported.
from jest-extended.
@acidoxee I was able to get this working without the above PR.
Here is your updated reproduction. https://stackblitz.com/edit/vitest-dev-vitest-whsqfe?file=jest-extended.d.ts
Here's the jest-extended.d.ts
file I'm currently using
import "jest-extended";
import "vitest";
declare module "vitest" {
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining<T = any> extends CustomMatchers<T> {}
interface ExpectStatic extends CustomMatchers {}
}
from jest-extended.
@keeganwitt Here's vitest's docs if they are useful, though I get errors following those steps.
from jest-extended.
That's a good start @cdierkens, thanks! Although I can't seem to make this work as soon as I add my own custom matchers (following the docs you've linked, which is exactly what I had followed on my own). This was kinda always the problem: the setup for my own matchers (exclusively) works perfectly, and so does the setup you're suggesting with only jest-extended
's matchers. But how to make it work with both? I have a toMatchJSON
and a toBeUUID
custom matchers, for which I need to define types, and add jest-extended
's ones also. That, I couldn't figure out for now.
from jest-extended.
That's a good start @cdierkens, thanks! Although I can't seem to make this work as soon as I add my own custom matchers (following the docs you've linked, which is exactly what I had followed on my own). This was kinda always the problem: the setup for my own matchers (exclusively) works perfectly, and so does the setup you're suggesting with only
jest-extended
's matchers. But how to make it work with both? I have atoMatchJSON
and atoBeUUID
custom matchers, for which I need to define types, and addjest-extended
's ones also. That, I couldn't figure out for now.
Would it work to define an interface for your custom matchers and extend that interface in addition to jest-extended's? Shooting a bit from the hip here, since I don't have a test project with this setup.
from jest-extended.
OK yeah this time it seems to work nicely, well done @keeganwitt @cdierkens 👏 thanks a bunch for the help!
from jest-extended.
Related Issues (20)
- Vitest typings override instead of augmenting module HOT 26
- Feature Request: Support "export" package
- Number matches should not coerce non-numbers to numbers. HOT 1
- `toEqual` passes on non-equal arrays where trailing undefined HOT 1
- `toIncludeSameMembers` output is hard to understand HOT 2
- `toHaveBeenCalledExactlyOnceWith` expects an array of objects, when the object is passed as `args` HOT 6
- [Bug]: The second param of toHaveBeenCalledBefore/toHaveBeenCalledAfter has default value, but is not typed as optional HOT 1
- Declaration merging does not work without exporting the CustomMatchers interface. HOT 2
- `fail` does not work when testing code using a `try/catch`
- toBeInRange bug in implementation HOT 4
- value '...actual' is not correct for toHaveBeenCalledExactlyOnceWith fail case HOT 1
- TypeScript declarations are not working when used with @jest/globals
- Use jest-diff in toHaveBeenCalledWith matcher results
- Chore: Is there any plan to upgrade yarn to the latest? HOT 2
- `toContainOneOf([string1, string2, string3])` would be nice
- BUG: nested matcher printing "object Object"
- Feature Request: Array matcher diff
- Simplify typescript recommendations HOT 4
- Feature Request: `stringContainingCaseInsensitive`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-extended.