1

I have some providers (e.g provider A,B,C) created above a certain widget and testing the ProviderNotFoundException in the case that a provider was removed from the widget tree.

Right now I'm testing the ProviderNotFoundException like this:

expect(tester.takeException(), isA<ProviderNotFoundException>());

This is very generic because this will work for all the Providers A,B and C if they were removed. I would like to add additional constraints to check if only Provider B was not found.

I tried using the having method on the isA but could not get it to work.

expect(
              tester.takeException(),
              isA<ProviderNotFoundException>().having(
                (e) => e.valueType,
                'valueType',
                contains('A'),
              ));
Calvin Gonsalves
  • 1,738
  • 11
  • 15
  • 1
    `having` should be the way to go - Do you mind posting the code you tried with having? – Michael Horn Jul 06 '21 at 15:53
  • @MichaelHorn I realized my error. The `matcher` argument should have the type of the Provider and not check if it contains the name of the Provider. I will post the solution below – Calvin Gonsalves Jul 06 '21 at 17:43

1 Answers1

0

Using the having method to add additional constraints and check if the feature argument matches the matcher argument correctly.

 expect(
              tester.takeException(),
              isA<ProviderNotFoundException>().having(
                (e) => e.valueType,
                'valueType',
                A,
              ));

Calvin Gonsalves
  • 1,738
  • 11
  • 15