Last active
August 10, 2020 03:04
-
-
Save LarryLuTW/0341e452d73903c072869279b06932ff 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
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