Created
April 26, 2019 19:27
-
-
Save the-teacher/098de371e873fe669d9d36f571765391 to your computer and use it in GitHub Desktop.
console.warn.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import 'jest-dom/extend-expect' | |
import { render, cleanup } from 'react-testing-library' | |
import SystemError from './SystemError' | |
afterEach(cleanup) | |
describe('SystemError', () => { | |
const error = { | |
name: 'errorName', | |
message: 'errorMessage' | |
} | |
const originalWarn = console.warn | |
afterEach(() => (console.warn = originalWarn)) | |
describe('Check console.warn() output', () => { | |
let consoleOutput = [] | |
const mockedWarn = output => consoleOutput.push(output) | |
beforeEach(() => (console.warn = mockedWarn)) | |
it('has to show in console warning messages', () => { | |
const { container } = render(<SystemError error={error} />) | |
expect(consoleOutput).toEqual([ | |
'errorName', | |
'errorMessage' | |
]) | |
}) | |
}) | |
describe('Check displayed Error information', () => { | |
const mockedWarn = () => {} | |
beforeEach(() => (console.warn = mockedWarn)) | |
it('has to contain required copies', () => { | |
const { container } = render(<SystemError error={error} />) | |
const innerHtml = container.innerHTML | |
expect(innerHtml).toEqual(expect.stringContaining('Sorry!')) | |
expect(innerHtml).toEqual( | |
expect.stringContaining('Something went wrong. Please try again later.') | |
) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment