Giter Club home page Giter Club logo

Comments (6)

lummish avatar lummish commented on September 12, 2024 4

Looks like the maintainers have fixed the issue in the source code, but those changes have yet to be published on NPM. Until they bump the NPM version, here's a workaround:

If you don't already have one, create a @types directory somewhere in your repository path (mine is at src/@types). Inside of this directory, create another directory called jest-matcher-deep-close-to. This directory will have a single file, index.d.ts, with the following contents (note: I have made some small modifications to the current index.d.ts):

// src/@types/jest-matcher-deep-close-to/index.d.ts

declare namespace jest {
  interface Matchers<R> {
    toBeDeepCloseTo: (expected: number | number[] | object, decimals?: number) => R;
    toMatchCloseTo: (expected: number | number[] | object, decimals?: number) => R;
  }
}

declare module 'jest-matcher-deep-close-to' {
  export function toBeDeepCloseTo(
    received: number | number[] | object,
    expected: number | number[] | object,
    decimals?: number,
  ): {
    message(): string;
    pass: boolean;
  };

  export function toMatchCloseTo(
    received: number | number[] | object,
    expected: number | number[] | object,
    decimals?: number,
  ): {
    message(): string;
    pass: boolean;
  };
}

Newer versions of TypeScript should pick up this module declaration automatically. If they don't you may need to modify your compiler options types and/or typeRoots.

@rob893 This should make it much easier to work on multiple machines/reinstall packages as you'll have your own declaration committed to source control.

from jest-matcher-deep-close-to.

rob893 avatar rob893 commented on September 12, 2024

I had this same issue. I just put the index.d.ts file from here into the node module, but it is annoying to do that for each computer that I work on.

from jest-matcher-deep-close-to.

maasencioh avatar maasencioh commented on September 12, 2024

The new version was done in typescript, so everything should be already natively available

from jest-matcher-deep-close-to.

wholebuzz avatar wholebuzz commented on September 12, 2024

error TS2339: Property 'toMatchCloseTo' does not exist on type 'JestMatchers<[string, number][]>'.

Using version 2.0.1.

from jest-matcher-deep-close-to.

wholebuzz avatar wholebuzz commented on September 12, 2024

I tried import 'jest-matcher-deep-close-to/src/jest.d.ts' as the jest.d.ts is present only in src and not in lib but no help Probably needs to be added somewhere in tsconfig? Uninstalling for now.

from jest-matcher-deep-close-to.

danvk avatar danvk commented on September 12, 2024

It's silly that you have to do this, but you can import just the jest augmentation using a TypeScript triple-slash directive. Put this in something like test-utils.ts:

/// <reference types="jest-matcher-deep-close-to/src/jest" />
/** Utility code for unit tests */

import {toBeDeepCloseTo} from 'jest-matcher-deep-close-to';
expect.extend({toBeDeepCloseTo});

Then import that from your tests and you should be good to go, both for types and runtime.

from jest-matcher-deep-close-to.

Related Issues (13)

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.