diff --git a/test/mockito.dart b/test/mockito.dart index 4b1af68f..6e84894f 100644 --- a/test/mockito.dart +++ b/test/mockito.dart @@ -11,6 +11,6 @@ import 'package:react/src/react_client/synthetic_event_wrappers.dart'; MockSpec(), MockSpec(), MockSpec(), - MockSpec(), + MockSpec(), ]) main() {} diff --git a/test/mockito.mocks.dart b/test/mockito.mocks.dart index af7cfae9..709c03ae 100644 --- a/test/mockito.mocks.dart +++ b/test/mockito.mocks.dart @@ -446,83 +446,10 @@ class MockMouseEvent extends _i1.Mock implements _i2.MouseEvent { ); } -/// A class which mocks [SyntheticMouseEvent]. +/// A class which mocks [SyntheticEvent]. /// /// See the documentation for Mockito's code generation for more information. -class MockSyntheticMouseEvent extends _i1.Mock - implements _i4.SyntheticMouseEvent { - @override - bool get altKey => (super.noSuchMethod( - Invocation.getter(#altKey), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - @override - num get button => (super.noSuchMethod( - Invocation.getter(#button), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - num get buttons => (super.noSuchMethod( - Invocation.getter(#buttons), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - num get clientX => (super.noSuchMethod( - Invocation.getter(#clientX), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - num get clientY => (super.noSuchMethod( - Invocation.getter(#clientY), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - bool get ctrlKey => (super.noSuchMethod( - Invocation.getter(#ctrlKey), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - @override - bool get metaKey => (super.noSuchMethod( - Invocation.getter(#metaKey), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - @override - num get pageX => (super.noSuchMethod( - Invocation.getter(#pageX), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - num get pageY => (super.noSuchMethod( - Invocation.getter(#pageY), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - num get screenX => (super.noSuchMethod( - Invocation.getter(#screenX), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - num get screenY => (super.noSuchMethod( - Invocation.getter(#screenY), - returnValue: 0, - returnValueForMissingStub: 0, - ) as num); - @override - bool get shiftKey => (super.noSuchMethod( - Invocation.getter(#shiftKey), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); +class MockSyntheticEvent extends _i1.Mock implements _i4.SyntheticEvent { @override bool get bubbles => (super.noSuchMethod( Invocation.getter(#bubbles), diff --git a/test/react_client/event_helpers_test.dart b/test/react_client/event_helpers_test.dart index a61d3bdc..4613e5d0 100644 --- a/test/react_client/event_helpers_test.dart +++ b/test/react_client/event_helpers_test.dart @@ -1705,7 +1705,15 @@ main() { }); test('when the argument is a mocked event object with no mocked `type` property, and does not throw', () { - expect(eventTypeTester(MockSyntheticMouseEvent()), isFalse); + // Typically consumers would mock a specific SyntheticEvent subtype, but creating null-safe mocks for those + // causes property checks like `_hasProperty('button')` in helper methods to return true in DDC + // (e.g., `.isMouseEvent` for a `MockSyntheticMouseEvent` would return true). + // + // We really just want to check the `type` behavior here, especially for non-null-safe mocks, so we'll use + // the generic MockSyntheticEvent. + // + // *See other test with similar note to this one.* + expect(eventTypeTester(MockSyntheticEvent()), isFalse); }); }); } @@ -1996,8 +2004,17 @@ main() { }); // Regression test for Mock class behavior consumers rely on. + // + // Typically consumers would mock a specific SyntheticEvent subtype, but creating null-safe mocks for those + // causes property checks like `_hasProperty('button')` in helper methods to return true in DDC + // (e.g., `.isMouseEvent` for a `MockSyntheticMouseEvent` would return true). + // + // We really just want to check the `type` behavior here, especially for non-null-safe mocks, so we'll use + // the generic MockSyntheticEvent. + // + // *See other test with similar note to this one.* test('checks types correctly for Mock objects with `type` mocked', () { - final mockEvent = MockSyntheticMouseEvent(); + final mockEvent = MockSyntheticEvent(); when(mockEvent.type).thenReturn('click'); expect(mockEvent.isMouseEvent, isTrue); expect(mockEvent.isKeyboardEvent, false);