Skip to content

Allow dynamic override of arg provider in testing #35

@JJosephttg

Description

@JJosephttg

In testing, we may want to utilize the existing arg that is used inside of a widget when testing with mocks/overridden providers.

Is there some way/something we can introduce to pass the argument being created with so that when the provider is created, we can override with a different implementation function?

For example, using the number provider:

const numberProvider = Provider.withArgument((context, arg) => arg * 2);

...

testWidgets(..., (...) {
    ...
    ProviderScopeOverride(
          overrides:[numberProvider.overrideWithValue((arg) => arg * 4)]
          child: ...
    );

// Output with numberProvider(1) would be 4, not 2
});

Part of what we are testing could be that the argument provided to it is correct and produces a specific output

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions