over_react_test library

Classes

ClassNameMatcher
Match a list of class names on a component
ConsoleConfiguration
Configuration class that sets options within recordConsoleLogs and recordConsoleLogsAsync.
IsNode
Simulate
TestJacket<T extends Component>
Provides more a more consistent and easier to use API to test and manipulate a rendered ReactComponent.
WrapperComponent

Mixins

WrapperProps

Constants

allConfig → const ConsoleConfiguration
The configuration that will capture all logs, whether they be logs, warnings, or errors.
errorConfig → const ConsoleConfiguration
The configuration needed to capture errors while running recordConsoleLogs.
forwardedPropBeacon → const String
Prop key for use in conjunction with getForwardingTargets.
isFocused → const Matcher
A matcher that matches the currently focused element (document.activeElement).
logConfig → const ConsoleConfiguration
The configuration needed to capture logs while running recordConsoleLogs.
warnConfig → const ConsoleConfiguration
The configuration needed to capture warnings while running recordConsoleLogs.

Properties

$r → dynamic
Returns a reference to the currently selected component in the React Dev Tools.
no setter
blur → _EventSimulatorAlias
Helper function to simulate blur
final
change → _EventSimulatorAlias
Helper function to simulate change
final
click → _EventSimulatorAlias
Helper function to simulate clicks
final
focus → _EventSimulatorAlias
Helper function to simulate focus
final
hasNoLogs → Matcher
A matcher to verify that a callback function does not emit any logs.
final
keyDown → _EventSimulatorAlias
Helper function to simulate keyDown events.
final
keyPress → _EventSimulatorAlias
Helper function to simulate keyPress events.
final
keyUp → _EventSimulatorAlias
Helper function to simulate keyUp events.
final
logsNoPropTypeWarnings → _PropTypeLogMatcher
Matcher used enforce that there are no propType warnings.
final
mouseDown → _EventSimulatorAlias
Helper function to simulate mouseDown events.
final
mouseEnter → _EventSimulatorAlias
Helper function to simulate mouseEnter events.
final
mouseLeave → _EventSimulatorAlias
Helper function to simulate mouseLeave events.
final
mouseMove → _EventSimulatorAlias
Helper function to simulate mouseMove events.
final
mouseUp → _EventSimulatorAlias
Helper function to simulate mouseDown events.
final
testJsComponentFactory Function
A factory for a JS composite component, for use in testing.
final
Wrapper ↔ UiFactory<WrapperProps>
A helper component for use in tests where a component needs to be rendered inside a wrapper, but a composite component must be used for compatability with getByTestId().
getter/setter pair

Functions

chainRef(ReactElement element, CallbackRef? newCallbackRef) CallbackRef?
Returns a function that chains the callback or createRef-based ref of the provided element with newCallbackRef.
clearValidationWarnings() → void
Clears the list of ValidationUtil.warnings that have been recorded since startRecordingValidationWarnings was first called.
cloneElement(ReactElement element, [Map? props, Iterable? children]) → ReactElement
Dart wrapper for React.cloneElement.
commonComponentTests(BuilderOnlyUiFactory<UiProps> factory, {bool shouldTestPropForwarding = true, List unconsumedPropKeys = const [], List skippedPropKeys = const [], List getUnconsumedPropKeys(PropsMetaCollection)?, List getSkippedPropKeys(PropsMetaCollection)?, Map nonDefaultForwardingTestProps = const {}, bool shouldTestClassNameMerging = true, bool shouldTestClassNameOverrides = true, bool ignoreDomProps = true, bool shouldTestRequiredProps = true, bool? isComponent2, dynamic childrenFactory()?}) → void
Run common component tests around default props, prop forwarding, class name merging, and class name overrides.
createPortal(dynamic children, Element container) → ReactPortal
Returns a portal that renders children into a container.
excludesClasses(dynamic classes) → Matcher
Returns a matcher that matches an element that does not have classes.
expectCleanTestSurfaceAtEnd() → void
Adds a setUpAll and tearDownAll pair to the current group that verifies that no new elements exist on the test surface after everything is done running.
findDescendantsWithProp(dynamic root, dynamic propKey) List
Returns all descendants of a component that contain the specified prop key.
findDomNode(dynamic instance) Element?
Returns the DOM node associated with a mounted React component instance, which can be a ReactComponent/Element or react.Component2.
getAllByTestId(dynamic root, String value, {String key = defaultTestIdKey}) List
Returns all descendants of root with a key test ID prop value set to a space-delimited string containing value.
getAllComponentsByTestId<T extends Component>(dynamic root, String value, {String key = defaultTestIdKey}) List<T>
Similar to getAllByTestId, but filters out results that aren't Dart components.
getByTestId(dynamic root, String value, {String key = defaultTestIdKey}) → dynamic
Returns the first descendant of root that has its key test ID prop value set to a space-delimited string containing value, or null if no matching descendant can be found.
getComponentByTestId(dynamic root, String value, {String key = defaultTestIdKey}) → Component?
Returns the react.Component of the first descendant of root that has its key prop value set to value.
getComponentRootDomByTestId(dynamic root, String value, {String key = defaultTestIdKey}) Element?
Returns the Element of the first descendant of root that has its key prop value set to value.
getDartComponent<T extends Component>(dynamic instance) → T?
Returns the native Dart component associated with a mounted component instance.
getForwardingTargets(dynamic reactInstance, {int expectedTargetCount = 1, dynamic shallowRendered = false}) List
Return the components to which props have been forwarded.
getInstanceKey(ReactElement instance) → dynamic
Returns the ReactElement.key associated with the specified instance.
getInstanceRef(ReactElement instance) → dynamic
Returns the ReactElement.ref associated with the specified instance.
getProps(dynamic instance, {bool traverseWrappers = false}) Map
Returns an unmodifiable Map view of props for a ReactElement or composite ReactComponent instance.
getPropsByTestId(dynamic root, String value, {String key = defaultTestIdKey}) Map?
Returns the props of the first descendant of root that has its key prop value set to value.
getValidationWarnings() List<String>?
Returns the list of ValidationUtil.warnings that have been recorded since startRecordingValidationWarnings was first called.
hasAttr(String attributeName, dynamic value) → Matcher
Returns a matcher that matches an element that has attributeName set to value.
hasClasses(dynamic classes) → Matcher
Returns a matcher that matches an element that has classes.
hasExactClasses(dynamic classes) → Matcher
Returns a matcher that matches an element that has classes, with no additional or duplicated classes.
hasLog(dynamic expected, {ConsoleConfiguration? consoleConfig, bool onlyIfAssertsAreEnabled = false}) → Matcher
A Matcher used to compare a list of logs against a provided String.
hasNodeName(String nodeName) → Matcher
Returns a matcher that matches an element with the nodeName of nodeName.
hasProp(dynamic propKey, dynamic propValue) → Matcher
Returns a matcher that matches Dart, JS composite, and DOM ReactElements and ReactComponents that contain the prop pair (propKey, propValue).
hasToStringValue(dynamic value) → Matcher
Returns a matcher that matches an object whose toString value matches value.
isDartComponent(Object? instance) bool
Returns whether an instance is a native Dart component (a react-dart ReactElement or ReactComponent).
isDomElement(dynamic instance) bool
Returns whether instance is a ReactElement for a DOM node.
isValidElement(dynamic object) bool
Dart wrapper for React.isValidElement.
logsPropCombinationError(String propName, String prop2Name, [String message = '']) → _PropTypeLogMatcher
A matcher to verify that a PropError.combination is thrown with the provided propName, prop2Name, and optional message.
logsPropError(String propName, [String message = '']) → _PropTypeLogMatcher
A matcher to verify that a PropError is returned within UiComponent2.propTypes with the provided propName and optional message.
logsPropRequiredError(String propName, [String message = '']) → _PropTypeLogMatcher
A matcher to verify that a PropError.required is returned within UiComponent2.propTypes with the provided propName and optional message.
logsPropTypeWarning(String expected) → _PropTypeLogMatcher
Matcher used to check for a specific propType warning being emitted during the runtime of a callback function.
logsPropTypeWarnings(dynamic expected) → _PropTypeLogMatcher
Matcher used to check for specific propType warnings being emitted during the runtime of a callback function.
logsPropValueError(dynamic invalidValue, String propName, [String message = '']) → _PropTypeLogMatcher
A matcher to verify that a PropError.value is thrown with the provided invalidValue, propName, and optional message.
logsToConsole(dynamic expected, {ConsoleConfiguration? consoleConfig, bool onlyIfAssertsAreEnabled = false}) → Matcher
A Matcher used to compare a list of logs against a provided matcher.
mount<T extends Component>(ReactElement reactElement, {Element? mountNode, bool attachedToDocument = false, bool autoTearDown = true}) TestJacket<T>
Renders reactElement, and returns a TestJacket instance to use in a test.
preparePropsChangeset(ReactElement element, Map? newProps, [Iterable? newChildren]) → dynamic
Returns a new JS map with the specified props and children changes, properly prepared for consumption by React JS methods such as cloneElement, setProps, and other methods that accept changesets of props to be merged into existing props.
queryAllByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) List<Element>
Returns all descendant Elements of root that has their key html attribute value set to value.
queryByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) Element?
Returns the Element of the first descendant of root that has its key html attribute value set to a space-delimited string containing value.
recordConsoleLogs(dynamic callback(), {ConsoleConfiguration configuration = allConfig, bool shouldResetPropTypesWarningCache = true}) List<String?>
Runs a provided callback and returns the logs that occur during the runtime of that function.
recordConsoleLogsAsync(Future asyncCallback(), {ConsoleConfiguration configuration = allConfig, bool shouldResetPropTypesWarningCache = true}) FutureOr<List<String?>>
Captures console logs created during the runtime of a provided asynchronous callback.
rejectValidationWarning(dynamic warningMatcher) → void
Verify that no validation warning(s) matching warningMatcher were logged.
render(dynamic component, {bool autoTearDown = true, Element? container, Callback? autoTearDownCallback}) → dynamic
Renders a React component or builder into a detached node and returns the component instance.
renderAndGetComponent(dynamic component, {bool autoTearDown = true, Callback? autoTearDownCallback}) → Component?
Renders a React component or builder into a detached node and returns the associated Dart component.
renderAndGetDom(dynamic component, {bool autoTearDown = true, Callback? autoTearDownCallback}) Element?
Renders a React component or builder into a detached node and returns the associated DOM node.
renderAttachedToDocument(dynamic component, {bool autoTearDown = true, Element? container, Callback? autoTearDownCallback}) → dynamic
Renders the component into a node attached to document.body as opposed to a detached node.
renderShallow(ReactElement instance, {bool autoTearDown = true, Callback? autoTearDownCallback}) → ReactElement
Shallow-renders a component using react_test_utils.ReactShallowRenderer.
setComponentZone([Zone? zone]) → void
Sets the zone that React components are run in.
startRecordingValidationWarnings() → void
Starts recording an OverReact ValidationUtil.warning.
stopRecordingValidationWarnings() → void
Stops recording the OverReact ValidationUtil.warnings that were being recorded as a result of calling startRecordingValidationWarnings.
storeZone([Zone? zone]) → void
Store the specified (or current if none is specified) zone for use within zonedExpect.
tearDownAttachedNodes() → void
Unmounts and removes the mount nodes for components rendered via renderAttachedToDocument that are not automatically unmounted.
testClassNameMerging(BuilderOnlyUiFactory<UiProps> factory, dynamic childrenFactory()) → void
Common test for verifying that DomProps.classNames are merged/blacklisted as expected.
testClassNameOverrides(BuilderOnlyUiFactory<UiProps> factory, dynamic childrenFactory()) → void
Common test for verifying that DomProps.classNames added by the component can be blacklisted by the consumer using DomProps.classNameBlacklist.
testRequiredProps(BuilderOnlyUiFactory<UiProps> factory, dynamic childrenFactory()) → void
Common test for verifying that props annotated as a requiredProp are validated correctly.
throwsPropError(String propName, [String message = '']) → Matcher
A matcher to verify that a PropError is thrown with the provided propName and optional message.
throwsPropError_Combination(String propName, String prop2Name, [String message = '']) → Matcher
A matcher to verify that a PropError.combination is thrown with the provided propName, prop2Name, and optional message.
throwsPropError_Required(String propName, [String? message = '']) → Matcher
A matcher to verify that a PropError.required is thrown with the provided propName and optional message.
throwsPropError_Value(dynamic invalidValue, String propName, [String message = '']) → Matcher
A matcher to verify that a PropError.value is thrown with the provided invalidValue, propName, and optional message.
triggerDocumentClick(Element target) → void
Dispatches a click event to the specified target.
triggerDocumentMouseEvent(Element target, String event) → void
Dispatches a MouseEvent of type event to the specified target.
triggerFocus(Element target, {Duration timeout = _defaultTriggerTimeout}) Future
Focuses the target and returns a Future when that focus event is fired.
triggerTransitionEnd(Element element, {Duration timeout = _defaultTriggerTimeout}) Future
Dispatches a transitionend event when the CSS transition of the element is complete. Returns a Future that completes after the event has been dispatched.
unmount(dynamic instanceOrContainerNode) → void
Unmounts a React component.
validateZone() → void
Validates that storeZone was called before zonedExpect was.
verifyValidationWarning(dynamic warningMatcher) → void
Verify that a validation warning(s) matching warningMatcher were logged.
zonedExpect(dynamic actual, dynamic matcher, {String? reason}) → void
Calls expect in package:test/test.dart in the zone stored in storeZone.

Typedefs

CallbackRef = dynamic Function(dynamic ref)
A function that, when supplied as ReactPropsMixin.ref, is called with the component instance as soon as it is mounted.