-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: the way we deprecate methods
- Loading branch information
1 parent
2a77c9b
commit 151a8ef
Showing
6 changed files
with
150 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
// @ts-nocheck | ||
import { expect, jest } from '@jest/globals'; | ||
import { createConsoleWarningMessageTest } from './index'; | ||
|
||
export const checkV9Deprecation = (modularFunction: () => void, nonModularFunction: () => void) => { | ||
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
consoleWarnSpy.mockRestore(); | ||
modularFunction(); | ||
expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
consoleWarnSpy.mockClear(); | ||
const consoleWarnSpy2 = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
nonModularFunction(); | ||
expect(consoleWarnSpy).toHaveBeenCalledTimes(1); | ||
consoleWarnSpy.mockRestore(); | ||
|
||
expect(consoleWarnSpy2).toHaveBeenCalledTimes(1); | ||
consoleWarnSpy2.mockClear(); | ||
}; | ||
|
||
export type CheckV9DeprecationFunction = ( | ||
modularFunction: () => void, | ||
nonModularFunction: () => void, | ||
methodName: string, | ||
uniqueMessage: string = '', | ||
) => void; | ||
|
||
export const createCheckV9Deprecation = (moduleName: string): CheckV9DeprecationFunction => { | ||
return ( | ||
modularFunction: () => void, | ||
nonModularFunction: () => void, | ||
methodName: string, | ||
uniqueMessage = '', | ||
) => { | ||
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
consoleWarnSpy.mockRestore(); | ||
modularFunction(); | ||
expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
consoleWarnSpy.mockReset(); | ||
const consoleWarnSpy2 = jest.spyOn(console, 'warn').mockImplementation(warnMessage => { | ||
const message = createConsoleWarningMessageTest(moduleName, methodName, uniqueMessage); | ||
expect(message).toMatch(warnMessage); | ||
}); | ||
nonModularFunction(); | ||
|
||
expect(consoleWarnSpy2).toHaveBeenCalledTimes(1); | ||
consoleWarnSpy2.mockReset(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters