-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix(tests): clean up jest.Mock
usage in tests
#13238
Changes from all commits
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 |
---|---|---|
|
@@ -16,11 +16,11 @@ import {DependencyResolver} from '../index'; | |
const maxWorkers = 1; | ||
let dependencyResolver: DependencyResolver; | ||
let runtimeContextResolver: Resolver; | ||
let Runtime: typeof import('jest-runtime'); | ||
let Runtime: typeof import('jest-runtime').default; | ||
let config: Config.ProjectConfig; | ||
const cases: Record<string, jest.Mock> = { | ||
fancyCondition: jest.fn(path => path.length > 10), | ||
testRegex: jest.fn(path => /.test.js$/.test(path)), | ||
Comment on lines
-21
to
-23
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.
|
||
const cases: Record<string, (path: string) => boolean> = { | ||
fancyCondition: path => path.length > 10, | ||
testRegex: path => /.test.js$/.test(path), | ||
}; | ||
const filter = (path: string) => | ||
Object.keys(cases).every(key => cases[key](path)); | ||
|
@@ -84,7 +84,7 @@ test('resolves dependencies for scoped packages', () => { | |
}); | ||
|
||
test('resolves no inverse dependencies for empty paths set', () => { | ||
const paths = new Set(); | ||
const paths = new Set<string>(); | ||
const resolved = dependencyResolver.resolveInverse(paths, filter); | ||
expect(resolved.length).toEqual(0); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,28 @@ | |
|
||
import {createContext, runInContext} from 'vm'; | ||
|
||
declare global { | ||
function DTRACE_NET_SERVER_CONNECTION(): unknown; | ||
} | ||
|
||
const fake = jest.fn(); | ||
globalThis.DTRACE_NET_SERVER_CONNECTION = fake; | ||
|
||
let installCommonGlobals: typeof import('../installCommonGlobals').default; | ||
let fake: jest.Mock; | ||
|
||
function getGlobal(): typeof globalThis { | ||
return runInContext('this', createContext()); | ||
} | ||
|
||
beforeEach(() => { | ||
fake = jest.fn(); | ||
// @ts-expect-error | ||
globalThis.DTRACE_NET_SERVER_CONNECTION = fake; | ||
|
||
installCommonGlobals = require('../installCommonGlobals').default; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
jest.resetModules(); | ||
}); | ||
Comment on lines
+27
to
+30
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. Tricky one. If I got it right: |
||
|
||
it('returns the passed object', () => { | ||
const myGlobal = getGlobal(); | ||
|
||
|
@@ -33,8 +40,9 @@ it('turns a V8 global object into a Node global object', () => { | |
|
||
expect(myGlobal.process).toBeDefined(); | ||
expect(myGlobal.DTRACE_NET_SERVER_CONNECTION).toBeDefined(); | ||
|
||
expect(myGlobal.DTRACE_NET_SERVER_CONNECTION).not.toBe(fake); | ||
|
||
myGlobal.DTRACE_NET_SERVER_CONNECTION(); | ||
expect(fake.mock.calls.length).toBe(1); | ||
|
||
expect(fake).toHaveBeenCalledTimes(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.
Otherwise the default is
jest.Mock<any, any>
.