Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Created April 26, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-teacher/098de371e873fe669d9d36f571765391 to your computer and use it in GitHub Desktop.
Save the-teacher/098de371e873fe669d9d36f571765391 to your computer and use it in GitHub Desktop.
console.warn.js
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