Created
January 27, 2020 11:46
-
-
Save ddialar/91dba1d18aac633d72b558696e50aff6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { orm } from '@orm'; | |
// Other needed imports and operations... | |
describe('Block description', () => { | |
// Type error restoring the mock (mocking strategy #1)... | |
test('whatever test description.', async (done) => { | |
// Creating the spyOn... | |
jest.spyOn(orm.controllers, 'enableUserAccount') | |
// Mocking the function... | |
orm.controllers.enableUserAccount = jest | |
.fn() | |
.mockImplementation(() => { | |
throw new Error('Enabling user account Testing Error Message.') | |
}); | |
// ... | |
// Test content... | |
// ... | |
// Restoring the function... | |
orm.controllers.enableUserAccount.mockRestore(); | |
// Error: The property 'mockRestore' doesn't exist for type '(userId: number) => Promise<void>'. | |
done(); | |
}); | |
// Type error restoring the mock (mocking strategy #2)... | |
test('whatever test description.', async (done) => { | |
// Creating the spyOn and mocking the function at the same time... | |
jest | |
.spyOn(orm.controllers, 'enableUserAccount') | |
.mockImplementation(() => { | |
throw new Error('Enabling user account Testing Error Message.') | |
}); | |
// ... | |
// Test content... | |
// ... | |
// Restoring the function... | |
orm.controllers.enableUserAccount.mockRestore(); | |
// Error: The property 'mockRestore' doesn't exist for type '(userId: number) => Promise<void>'. | |
done(); | |
}); | |
// Without type error restoring the mocked function... | |
test('whatever test description.', async (done) => { | |
// Creating the spyOn and mocking the function at the same time... | |
jest | |
.spyOn(orm.controllers, 'enableUserAccount') | |
.mockImplementation(() => { | |
throw new Error('Enabling user account Testing Error Message.') | |
}); | |
// ... | |
// Test content... | |
// ... | |
// Restoring the function... | |
jest.spyOn(orm.controllers, 'enableUserAccount').mockRestore(); | |
// No type error | |
done(); | |
}); | |
)}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment