Skip to content

Commit

Permalink
Merge branch 'private/chessurisme' of https://github.com/free-bird-op…
Browse files Browse the repository at this point in the history
…eration-project/quiz-manager into private/chessurisme
  • Loading branch information
chessurisme committed Jun 13, 2024
2 parents c047c64 + 11ed6e4 commit 9eb3c8c
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/utilities/components/__tests__/set-attributes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ describe('setAttributes', () => {
})

it('should return false when element is not provided', () => {
const spyConsoleError = jest
.spyOn(console, 'error')
.mockImplementation(() => {})
const spyConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
const attributes = {
id: 'sample-div',
class: 'container',
Expand All @@ -37,38 +35,28 @@ describe('setAttributes', () => {

const result = setAttributes(null, attributes)

expect(spyConsoleError).toHaveBeenCalledWith(
'The element must be provided.'
)
expect(spyConsoleError).toHaveBeenCalledWith('The element must be provided.')
expect(result).toBe(false)
spyConsoleError.mockRestore()
})

it('should return false when attributes are not provided or empty', () => {
const spyConsoleError = jest
.spyOn(console, 'error')
.mockImplementation(() => {})
const spyConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
const element = document.createElement('div')

const resultEmpty = setAttributes(element, {})
expect(spyConsoleError).toHaveBeenCalledWith(
'The attributes must be provided.'
)
expect(spyConsoleError).toHaveBeenCalledWith('The attributes must be provided.')
expect(resultEmpty).toBe(false)

const resultNull = setAttributes(element, null)
expect(spyConsoleError).toHaveBeenCalledWith(
'The attributes must be provided.'
)
expect(spyConsoleError).toHaveBeenCalledWith('The attributes must be provided.')
expect(resultNull).toBe(false)

spyConsoleError.mockRestore()
})

it('should return false when element provided is not a valid HTML element', () => {
const spyConsoleError = jest
.spyOn(console, 'error')
.mockImplementation(() => {})
const spyConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
const element = 'not an HTML element'
const attributes = {
id: 'sample-div',
Expand All @@ -86,17 +74,13 @@ describe('setAttributes', () => {
})

it('should return false when attributes provided are not a valid object', () => {
const spyConsoleError = jest
.spyOn(console, 'error')
.mockImplementation(() => {})
const spyConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
const element = document.createElement('div')
const attributes = 'not an object'

const result = setAttributes(element, attributes)

expect(spyConsoleError).toHaveBeenCalledWith(
'The attributes provided are not a valid object.'
)
expect(spyConsoleError).toHaveBeenCalledWith('The attributes provided are not a valid object.')
expect(result).toBe(false)
spyConsoleError.mockRestore()
})
Expand Down

0 comments on commit 9eb3c8c

Please sign in to comment.