Giter VIP home page Giter VIP logo

Comments (9)

keeganwitt avatar keeganwitt commented on June 11, 2024 1

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.

cdierkens avatar cdierkens commented on June 11, 2024 1

PR to allow declaration merging: #653

from jest-extended.

cdierkens avatar cdierkens commented on June 11, 2024 1

@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.

cdierkens avatar cdierkens commented on June 11, 2024

Related issue I've just submitted: #652

I think the issue is that the CustomMatcher interface is not exported.

from jest-extended.

cdierkens avatar cdierkens commented on June 11, 2024

@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.

cdierkens avatar cdierkens commented on June 11, 2024

@keeganwitt Here's vitest's docs if they are useful, though I get errors following those steps.

from jest-extended.

acidoxee avatar acidoxee commented on June 11, 2024

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.

keeganwitt avatar keeganwitt commented on June 11, 2024

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.

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.

acidoxee avatar acidoxee commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.