# Initialize

ezFlap's WidgetWrapper class wraps around ezFlap widgets and helps to initialize their props, route parameters, and models.

# Props

Use WidgetWrapper's mapProps constructor parameter to provide values for the wrapped widget's props.

For example:

# Widget

TestingProps

# Test

TestingPropsTest

# Route Params

Use WidgetWrapper's mapRouteParams parameter to provide route parameters to populate @EzRouteParam fields.

# Widget

TestingRouteParams

# Test

TestingRouteParamsTest

# Emit Handlers

WidgetWrapper allows to register callbacks as emit handlers.

If we actually want some test code to be invoked when an event is emitted - we can register a callback using the WidgetWrapper's constructor's mapEmitHandlers parameter:

# Widget

TestingEmits

# Test

TestingEmitsTest

However, if all we want is to make sure the event was emitted - then it is not necessary to register emit handlers.

Instead, we can use WidgetWrapper's getNumEmits method to get the number of times a certain event has been emitted.

For example, using the widget from the previous example, we can verify that events are emitted as expected like this:

# Test

TestingEmitsCountTest

# Models

Models need to be initialized individually.

"Initializing a model" in WidgetWrapper is like providing a model with z-model.

There are two variations

  • Initialize a model with a value.
  • Initialize a model with an Rx instance that contains the value.

# With Value

Use the WidgetWrapper.initModel() function.

# Signature

Rx<T> initModel<T>({
	String? key,
	required T value,
})
1
2
3
4

# Widget

TestingModelsInitValue

# Test

TestingModelsInitValueTest

# With Rx

It is also possible to initialize a model with a pre-existing Rx variable.

This is useful in case we want multiple models to read from and write to the same variable.

For example:

# Widget

TestingModelsInitRx

# Test

TestingModelsInitRxTest

# Assertions

WidgetWrapper allows the test code to get and set the current value of a model.

This is done with WidgetWrapper's getModelValue and setModelValue methods.

For example:

# Widget

TestingModelsInitValueAssert

# Test

TestingModelsInitValueAssertTest