Search code examples
flutterdartstatefulwidget

Write test on reassemble logic


I've created a StatefulWidget and I have included some logic into reassemble to have a specific behavior when the developer hot reloads during development.

@override
void reassemble() {
  super.reassemble();
  // My logic.
}

I would like to write a test about it, how can I trigger the reassemble method?

tester.pump() doesn't seem to do the job as it only rebuilds the widget tree.


Solution

  • You can use tester.binding.reassembleApplication() for that:

    testWidgets('Your test', (tester) async {
      await tester.pumpWidget(const YourWidget());
      
      // Test your logic before `.reassemble()`.
      
      unawaited(tester.binding.reassembleApplication());
      await tester.pump();
      
      // Test your logic after `.reassemble()`.
    });