brianegan/scoped_model

Testing when using scopedModelDescendant

Closed this issue · 2 comments

I'm trying to make my widget which uses scopedModelDescendant. The test is failing with this message

"Could not find the correct scopedModel"
To fix please:
*Provide types to scopedModel
*Provide types to scopedModelDescendant
*Provide types to scopedModel.of()

this is how I'm configuring my test

Widget widgetSetupToBeTested({Widget child}) { return ScopedModel( model: mainModel, child: MaterialApp( home: child, navigatorObservers: [mockObserver], routes: <String, WidgetBuilder>{ "/Procesamiento": (BuildContext context) => new ProcessingPage(mainModel), "/Error": (BuildContext context) => new ErrorPage() }, ),); }

where main model is: class MockMainModel extends Mock implements MainModel {}

What am I missing? If I pass the model through the constructor the test is working properly. So mocking of MainModel is working properly.

Hey there -- not trying to be rude, but it does look like you need to:

*Provide types to ScopedModel
*Provide types to ScopedModelDescendant

This means changing your code above to this:

Widget widgetSetupToBeTested({Widget child}) { return ScopedModel<MainModel>( model: mainModel...

and

ScopedModelDescendant<MainModel>(

In this case, Dart seems to infer the concrete MockMainModel as the type rather than the abstract MainModel, so you need to specify you want to provide and consume any MainModel.

I'll try to see if I can reword those error messages a bit better.

Thank you so much. That was it. Since I have my app wrapped without specifying the type for the ScopedModel class I did not realized that the type should be specified there for the test to run. That should be a good practice, to specify the type when using ScopedModel so I can avoid future delays or mistakes. I really appreciate your quick response.