Last active
August 10, 2020 03:05
-
-
Save LarryLuTW/191fb79b9e2e38d40e2d7b8a28a0dbe3 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
// Test Case 2 | |
test('若有重複的 username 則 註冊失敗,而且 db.createUser 不能被呼叫', async () => { | |
// 把 db.isUserExist 跟 db.createUser 都替換掉 | |
const stubIsUserExist = sinon.stub(db, 'isUserExist').returns(true) | |
const stubCreateUser = sinon.stub(db, 'createUser') | |
let user = { username: 'larry', password: 'pa55w0rd' } | |
// 確認註冊失敗 | |
await expect(signup(user)).rejects.toThrowError() | |
// 確認 db.isUserExist 有被呼叫,但 db.createUser 沒有被呼叫 | |
expect(stubIsUserExist.called).toBe(true) | |
expect(stubCreateUser.called).toBe(false) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment