Skip to content

Commit

Permalink
Fix ErrorBoundary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyjodon-wk committed Jan 30, 2025
1 parent 0762492 commit af7c35e
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/over_react/component/error_boundary/shared_stack_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:html';

import 'package:meta/meta.dart';
import 'package:over_react/over_react.dart' hide ErrorBoundary;
import 'package:react_testing_library/react_testing_library.dart' as rtl;
import 'package:over_react/react_dom.dart' as react_dom;
import 'package:over_react/components.dart';
import 'package:test/test.dart';

Expand All @@ -27,17 +29,13 @@ void sharedErrorBoundaryStackTests() {
void expectRenderErrorWithComponentName(ReactElement element,
{required String expectedComponentName}) {
final capturedInfos = <ReactErrorInfo>[];
expect(() {
rtl.render((ErrorBoundary()
..shouldLogErrors = false
..onComponentDidCatch = (error, info) {
capturedInfos.add(info);
})(element));
// Use prints as an easy way to swallow `print` calls and
// prevent RTL from forwarding console errors to the test output,
// since React error boundary logging is pretty noisy.
// TODO instead, disable logging in this rtl.render call once that option is available: FED-1641
}, prints(anything));
final mountNode = DivElement();
react_dom.render((ErrorBoundary()
..shouldLogErrors = false
..onComponentDidCatch = (error, info) {
capturedInfos.add(info);
})(element), mountNode);
addTearDown(() => react_dom.unmountComponentAtNode(mountNode));

expect(capturedInfos, hasLength(1),
reason: 'test setup check; should have captured a single component error');
Expand Down

0 comments on commit af7c35e

Please sign in to comment.