Skip to content

Commit

Permalink
Update regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Nov 9, 2023
1 parent 1220e25 commit 70cc2b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 78 deletions.
2 changes: 1 addition & 1 deletion test/mockito.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import 'package:react/src/react_client/synthetic_event_wrappers.dart';
MockSpec<KeyboardEvent>(),
MockSpec<DataTransfer>(),
MockSpec<MouseEvent>(),
MockSpec<SyntheticMouseEvent>(),
MockSpec<SyntheticEvent>(),
])
main() {}
77 changes: 2 additions & 75 deletions test/mockito.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 19 additions & 2 deletions test/react_client/event_helpers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 70cc2b7

Please sign in to comment.