Comments (6)
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.
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.
The new version was done in typescript, so everything should be already natively available
from jest-matcher-deep-close-to.
error TS2339: Property 'toMatchCloseTo' does not exist on type 'JestMatchers<[string, number][]>'.
Using version 2.0.1
.
from jest-matcher-deep-close-to.
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.
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)
- Be within x percent of? HOT 2
- The last state of the master is not released, yet. HOT 1
- Show more context to where the error is HOT 3
- Add changelog
- Ambient jest.d.ts not visible from ./lib/index.d.ts HOT 1
- Typed arrays dont seem to work in newer version? HOT 2
- Support setup via jest.config.js HOT 3
- Unexpected difference from toBeCloseTo HOT 1
- Merge this repository into jest HOT 1
- Separate in functions for each type
- Allow comparison of functions HOT 4
- support all Iterables
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-matcher-deep-close-to.