Skip to content

Commit 2e81fc6

Browse files
committed
Fix broken ErrorBoundary test
1 parent c98d079 commit 2e81fc6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/React__test.res

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ open TestFramework
22
open ReactTestUtils
33
open Belt
44

5+
module Console = {
6+
type fn
7+
let disableError: unit => fn = %raw(`
8+
function() {
9+
var fn = console.error
10+
console.error = () => {}
11+
}
12+
`)
13+
14+
let restoreError: fn => unit = %raw(`
15+
function(fn){
16+
console.error = fn
17+
}
18+
`)
19+
}
20+
521
module DummyStatefulComponent = {
622
@react.component
723
let make = (~initialValue=0, ()) => {
@@ -440,11 +456,19 @@ describe("React", ({test, beforeEach, afterEach}) => {
440456
test("ErrorBoundary", ({expect}) => {
441457
let container = getContainer(container)
442458

459+
// We need to disable error temporarily due to React always
460+
// printing errors / warnings
461+
let consoleFn = Console.disableError()
462+
443463
act(() =>
444464
ReactDOM.render(
445465
<ReasonReactErrorBoundary
446466
fallback={({error, info}) => {
447-
expect.value(error).toEqual(ComponentThatThrows.TestError)
467+
switch error {
468+
| ComponentThatThrows.TestError => ()
469+
| _ => Js.Exn.raiseError("TestError exn should have been captured by fallback")
470+
}
471+
Console.restoreError(consoleFn)
448472
expect.bool(info.componentStack->Js.String2.includes("ComponentThatThrows")).toBeTrue()
449473
<strong> {"An error occured"->React.string} </strong>
450474
}}>

0 commit comments

Comments
 (0)