Skip to content

Instantly share code, notes, and snippets.

@LarryLuTW
Last active August 10, 2020 03:05
Show Gist options
  • Save LarryLuTW/6fa596b4497d273bb300f1cf31e682b2 to your computer and use it in GitHub Desktop.
Save LarryLuTW/6fa596b4497d273bb300f1cf31e682b2 to your computer and use it in GitHub Desktop.
// Test Case 3
test('若帳號密碼都沒問題則註冊成功,而且 db.createUser 一定要被呼叫', async () => {
// 把 isUserExist 跟 createUser 都替換掉,並要求 isUserExist 回傳 false
const stubIsUserExist = sinon.stub(db, 'isUserExist').returns(false)
const stubCreateUser = sinon.stub(db, 'createUser')
let user = { username: 'larry', password: 'pa55w0rd' }
// 確認註冊成功
await expect(signup(user)).resolves.toBe()
// 確認 db.isUserExist 跟 db.createUser 都有被呼叫
expect(stubIsUserExist.called).toBe(true)
expect(stubCreateUser.called).toBe(true)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment