Skip to content

Commit 28e1ea3

Browse files
committedMay 30, 2022
test: ensure BcryptAdapter throws if becrypt throws
1 parent 1893050 commit 28e1ea3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎src/infra/criptography/bcrypt-adapter.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import { BcryptAdapter } from './bcrypt-adapter'
23
import bcrypt from 'bcrypt'
34
jest.mock('bcrypt', () => ({
@@ -24,4 +25,10 @@ describe('Bcrypt Adapter', () => {
2425
const hash = await sut.encrypt('any_value')
2526
expect(hash).toBe('hash')
2627
})
28+
test('Should throw if hash throws', async () => {
29+
const sut = makeSut()
30+
jest.spyOn(bcrypt, 'hash').mockImplementationOnce(() => { throw new Error() })
31+
const promise = sut.encrypt('any_value')
32+
await expect(promise).rejects.toThrow()
33+
})
2734
})

0 commit comments

Comments
 (0)
Please sign in to comment.