Skip to content

Commit

Permalink
Avoid spyOn hoisting
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Jan 27, 2023
1 parent 2e02cee commit de923e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ jest.mock( '../listener', () => {
super( ...arguments );

this.constructor._instance = this;
this._spy();
}

_spy() {
jest.spyOn( this, 'add' );
jest.spyOn( this, 'remove' );
}
Expand Down
24 changes: 13 additions & 11 deletions packages/scripts/utils/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,28 @@ import {
jest.mock( '../package', () => {
const module = jest.requireActual( '../package' );

jest.spyOn( module, 'getPackagePath' );
jest.spyOn( module, 'hasPackageProp' );
( () => {
jest.spyOn( module, 'getPackagePath' );
jest.spyOn( module, 'hasPackageProp' );
} )();

return module;
} );
jest.mock( '../process', () => {
const module = jest.requireActual( '../process' );

jest.spyOn( module, 'exit' );
jest.spyOn( module, 'getArgsFromCLI' );

( () => {
jest.spyOn( module, 'exit' );
jest.spyOn( module, 'getArgsFromCLI' );
} )();
return module;
} );
jest.mock( '../file', () => {
const module = jest.requireActual( '../file' );

jest.spyOn( module, 'hasProjectFile' );
jest.spyOn( module, 'fromProjectRoot' );
jest.spyOn( module, 'fromConfigRoot' );

( () => {
jest.spyOn( module, 'hasProjectFile' );
jest.spyOn( module, 'fromProjectRoot' );
jest.spyOn( module, 'fromConfigRoot' );
} )();
return module;
} );

Expand Down

0 comments on commit de923e0

Please sign in to comment.