Last active
November 21, 2021 16:46
-
-
Save vzaidman/0900f1eadf5aa980d82fcd9912eadb69 to your computer and use it in GitHub Desktop.
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
import user from './user' | |
describe('user', () => { | |
// before each test | |
beforeEach(() => { | |
// spy on the "isValid" function on the "user" object | |
jest.spyOn(user, 'isValid'); | |
}) | |
// after each test | |
afterEach(() => { | |
// remove the mock from the "isValid" function | |
user.isValid.mockRestore(); | |
}) | |
it('is validated for valid users', () => { | |
user.isValid.mockReturnValue(true) | |
// Testing someFn with user where user.isValid() returns true | |
assert(validate(user)) | |
}) | |
it('does not validated for invalid users', () => { | |
user.isValid.mockReturnValue(false) | |
// Testing someFn with user where user.isValid() returns true | |
assert(!validate(user)) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment