New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infer jest globals from @jest/globals #62037
Changes from all commits
3c40987
5dd2387
7605e45
7425401
4b29962
c04757c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"expect": "^29.0.0" | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"jest-mock": "^29.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"axe-core": "^3.5.5" | ||
"axe-core": "^3.5.5", | ||
"expect": "^29.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,18 @@ | |
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// Minimum TypeScript Version: 4.3 | ||
|
||
/// <reference types="jest"/> | ||
import { Matchers } from 'expect'; | ||
|
||
declare namespace jest { | ||
interface Expect { | ||
// tslint:disable-next-line: no-single-declare-module | ||
declare module 'expect' { | ||
interface BaseExpect { | ||
remcohaszing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* The `expect` function is used every time you want to test a value. | ||
* You will rarely call `expect` by itself. | ||
* | ||
* @param actual The value to apply matchers against. | ||
* @param message Clarification message | ||
*/ | ||
<T = any>(actual: T, message: string): JestMatchers<T>; | ||
(actual: any, message: string): Matchers<void>; | ||
Comment on lines
-19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be sure. Removal of the generic could possibly mess up other matchers. For example, does it work with |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
import 'jest'; | ||
import 'jest-expect-message'; | ||
import { expect } from 'expect'; | ||
|
||
declare const expect: jest.Expect; | ||
|
||
expect(2, "Two is always two").toBe(2); | ||
expect(2, 'Two is always two').toBe(2); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"expect": "^29.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { expect } from 'expect'; | ||
import { | ||
configureToMatchImageSnapshot, | ||
MatchImageSnapshotOptions, | ||
toMatchImageSnapshot, | ||
updateSnapshotState, | ||
} from 'jest-image-snapshot'; | ||
|
||
declare const it: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be typed through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine with me. It just felt like a regression. I am not a maintainer of any |
||
|
||
it('should be able to use toMatchImageSnapshot in a test', () => { | ||
expect.extend({ toMatchImageSnapshot }); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"expect": "^29.0.0", | ||
"ssim.js": "^3.1.1" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really necessary? Jest has
jest.mocked()
helper (it was moved fromts-jest
), is that not sufficient?By the way, typings of
jest.mocked()
were reworked recently and the copy above is already outdated. For reference see: https://github.com/facebook/jest/blob/835a93666a69202de2a0429cd5445cb5f56d2cea/packages/jest-mock/src/index.ts#L34-L92, and: https://github.com/facebook/jest/blob/835a93666a69202de2a0429cd5445cb5f56d2cea/packages/jest-mock/src/index.ts#L1219-L1230There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should this be changed to the following then?
I’m not familiar with
heft-jest
. It’s just affected by the updates.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking through Heft’s docs. The way they use Jest does not work with
ts-jest
, so to havemocked()
working they copied it to@types/heft-jest
. Seemed like they are fine to deprecate@types/heft-jest
after Heft will ship Jest v28, which hasjest.mocked()
builtin. I think that would be the best solution. See microsoft/rushstack#3609