Valentin Vignal
Valentin Vignal

Reputation: 8268

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.

Upvotes: 0

Views: 18

Answers (1)

Valentin Vignal
Valentin Vignal

Reputation: 8268

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()`.
});

Upvotes: 0

Related Questions