UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

47 lines (42 loc) 1.46 kB
import {normalizeErrors} from '../normalizeErrors' describe('normalizeErrors', () => { it('should convert strings to error objects accepted by InstUI components', () => { const errors = ['error1', 'error2'] const expected = [ {text: 'error1', type: 'newError'}, {text: 'error2', type: 'newError'}, ] expect(normalizeErrors(errors)).toEqual(expected) }) it('should convert message objects to the new error format', () => { const errors = [ {text: 'error1', type: 'error'}, {text: 'error2', type: 'error'}, ] const expected = [ {text: 'error1', type: 'newError'}, {text: 'error2', type: 'newError'}, ] expect(normalizeErrors(errors)).toEqual(expected) }) it('should not convert any other type of message', () => { const errors = [ {text: 'warning1', type: 'warning'}, {text: 'info1', type: 'info'}, {text: 'error1', type: 'error'}, {text: 'error2', type: 'newError'}, ] const expected = [ {text: 'warning1', type: 'warning'}, {text: 'info1', type: 'info'}, {text: 'error1', type: 'newError'}, {text: 'error2', type: 'newError'}, ] expect(normalizeErrors(errors)).toEqual(expected) }) it('should return an empty array when no messages are provided', () => { expect(normalizeErrors(undefined)).toEqual([]) expect(normalizeErrors(null)).toEqual([]) expect(normalizeErrors([])).toEqual([]) }) })