mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-27 02:01:15 +08:00
feat(utils): add jestMock.ts
This commit is contained in:
parent
2bd6cfe608
commit
e41142f49b
13
packages/utils/jestMock.ts
Normal file
13
packages/utils/jestMock.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export const jestMock = (object: any, method: string, implementation: () => any, accessType?: 'get' | 'set') => {
|
||||
let mockSpy = null
|
||||
if(!accessType){
|
||||
mockSpy = jest.spyOn(object, method)
|
||||
.mockImplementation(implementation)
|
||||
}
|
||||
if(accessType === 'get' || accessType === 'set'){
|
||||
// must use `as 'get'` or `as 'set'` or `as 'any'`.
|
||||
mockSpy = jest.spyOn(object, method, accessType as 'get')
|
||||
.mockImplementation(implementation)
|
||||
}
|
||||
return mockSpy
|
||||
}
|
Loading…
Reference in New Issue
Block a user