Skip to content

Instantly share code, notes, and snippets.

@LarryLuTW
Last active August 10, 2020 03:04
Show Gist options
  • Save LarryLuTW/0341e452d73903c072869279b06932ff to your computer and use it in GitHub Desktop.
Save LarryLuTW/0341e452d73903c072869279b06932ff to your computer and use it in GitHub Desktop.
const signup = require('./signup')
const db = require('./db')
// Test Case 1
test('若密碼太短則註冊失敗,而且 db.isUserExist 不該被呼叫', async () => {
// 用 stub 把 db.isUserExist 替換掉
const stubIsUserExist = sinon.stub(db, 'isUserExist')
// 給一個超短的 password
let user = { username: 'larry', password: 'pwd' }
// 確認註冊失敗、而且 db.isUserExist 沒有被呼叫
await expect(signup(user)).rejects.toThrowError()
expect(stubIsUserExist.called).toBe(false)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment