Skip to content

Commit

Permalink
test(envited.ascs.digital): refactor useNotification test
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Scheeren <[email protected]>
  • Loading branch information
royscheeren committed Jan 31, 2024
1 parent 2e78ce8 commit 8bb2d1d
Showing 1 changed file with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
/**
* @jest-environment node
*/
import { toast } from 'react-toastify'

import { notification } from './useNotification.hook'

jest.mock('react-toastify', () => ({
toast: {
info: jest.fn().mockImplementation(x => x),
success: jest.fn().mockImplementation(x => x),
error: jest.fn().mockImplementation(x => x),
warning: jest.fn().mockImplementation(x => x),
},
}))

describe('common/notification', () => {
describe('info', () => {
it('should return as expected', async () => {
it('should return an info toast expected', async () => {
// when ... we want to show a info notification
// then ... it should show the info notification as expected
const toast = {
info: jest.fn().mockReturnValue('INFO_TOAST'),
} as any

const { info } = notification(toast)()
const result = info('INFO_TOAST')

// when ... we want to get the notification
// then ... it returns the content as expected
expect(result).toEqual('INFO_TOAST')
expect(toast.info).toHaveBeenCalledWith('INFO_TOAST')
})
})

describe('success', () => {
it('should return as expected', async () => {
it('should return a success toast as expected', async () => {
// when ... we want to show a success notification
// then ... it should show the success notification as expected
const toast = {
success: jest.fn().mockReturnValue('SUCCESS_TOAST'),
} as any

const { success } = notification(toast)()
const result = success('SUCCESS_TOAST')

// when ... we want to get the notification
// then ... it returns the content as expected
expect(result).toEqual('SUCCESS_TOAST')
expect(toast.success).toHaveBeenCalledWith('SUCCESS_TOAST')
})
})

describe('warning', () => {
it('should return as expected', async () => {
it('should return a warning toast as expected', async () => {
// when ... we want to show a warning notification
// then ... it should show the warning notification as expected
const toast = {
warning: jest.fn().mockReturnValue('WARNING_TOAST'),
} as any

const { warning } = notification(toast)()
const result = warning('WARNING_TOAST')

// when ... we want to get the notification
// then ... it returns the content as expected
expect(result).toEqual('WARNING_TOAST')
expect(toast.warning).toHaveBeenCalledWith('WARNING_TOAST')
})
})

describe('error', () => {
it('should return as expected', async () => {
it('should return a error toast', async () => {
// when ... we want to show an error notification
// then ... it should show the error notification as expected
const toast = {
error: jest.fn().mockReturnValue('ERROR_TOAST'),
} as any

const { error } = notification(toast)()
const result = error('ERROR_TOAST')

// when ... we want to get the notification
// then ... it returns the content as expected
expect(result).toEqual('ERROR_TOAST')
expect(toast.error).toHaveBeenCalledWith('ERROR_TOAST')
})
})
})

0 comments on commit 8bb2d1d

Please sign in to comment.