Guest User

Untitled

a guest
Oct 21st, 2017
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. function SimpleApp(service) {
  2. this.service = service
  3.  
  4. this.echo = (nickname) => {
  5. var n = 'xxx'
  6. var firstname = this.service(nickname)
  7. return `Hello ${firstname}!`
  8. }
  9. }
  10.  
  11. function BuuAuthen(authService) {
  12. this.authService = authService
  13.  
  14. this.signIn = (username, password) => {
  15. var obj = this.authService(username, password)
  16. return {
  17. name: obj.name,
  18. token: '0000000000'
  19. }
  20. }
  21. }
  22.  
  23. test('Simple Mock', () => {
  24. const mockFn = jest.fn()
  25. .mockReturnValue('Weera')
  26.  
  27. var app = new SimpleApp(mockFn)
  28. var nickname = 'Ball'
  29. var result = app.echo(nickname)
  30.  
  31. expect(mockFn).toHaveBeenCalled()
  32. expect(mockFn).toHaveBeenCalledWith(nickname)
  33. expect(result).toBe('Hello Weera!')
  34. })
  35.  
  36. test('Sign-in with Facebook', () => {
  37. const facebookAuthMock = jest.fn()
  38. .mockReturnValue({
  39. name: 'Weera',
  40. facebookId: '1234567890',
  41. email: 'ball@buu.ac.th'
  42. })
  43.  
  44. var auth = new BuuAuthen(facebookAuthMock)
  45.  
  46. var username = 'ball@buu.ac.th'
  47. var password = '1234'
  48. var accountInfo = auth.signIn(username, password)
  49.  
  50. expect(facebookAuthMock).toHaveBeenCalled()
  51. expect(facebookAuthMock).toHaveBeenCalledWith(username, password)
  52. expect(accountInfo.name).toBe('Weera')
  53. expect(accountInfo).toHaveProperty('token')
  54. expect(accountInfo.token).toHaveLength(10)
  55. })
Add Comment
Please, Sign In to add comment