forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror-boundary-spec.js
42 lines (39 loc) · 1.15 KB
/
error-boundary-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// <reference types="cypress" />
/// <reference types="../../lib" />
import { ErrorBoundary } from '../../src/error-boundary.jsx'
import React from 'react'
/* eslint-env mocha */
describe('Error Boundary', () => {
const errorMessage = 'I crashed!'
const ChildWithoutError = () => <h1>Normal Child</h1>
const ChildWithError = () => {
throw new Error(errorMessage)
return null
}
it('renders normal children', () => {
cy.mount(
<ErrorBoundary>
<ChildWithoutError />
</ErrorBoundary>
)
cy.get('h1').should('have.text', 'Normal Child')
cy.get(ErrorBoundary)
.its('state.error')
.should('not.exist')
})
it('on error, display fallback UI', () => {
cy.mount(
<ErrorBoundary>
<ChildWithError />
</ErrorBoundary>
)
cy.get('header h1').should('contain', 'Something went wrong.')
cy.get('header h3').should('contain', 'failed to load')
cy.get(ErrorBoundary)
.its('state.error.message')
.should('equal', errorMessage)
cy.get(ErrorBoundary)
.its('state.error.stack')
.should('contain', 'ChildWithError')
})
})