Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Testing: InputChip click on delete

I use InputChips in my app.

InputChip(
  key: Key(label.id),
  label: Text(label.name),
  onDeleted: () => deleteChip(),
),

I want now to create unit tests to test the delete function. Unfortunatly I found no way to press the delete icon of the chip in the unit test. With await tester.tap(find.byKey(Key('1'))); it's possible to find the chip. How can I now define that I want to click the delete icon on the chip?

like image 657
oberprah Avatar asked Dec 03 '25 17:12

oberprah


1 Answers

Your finder is finding and tapping the InputChip itself, not the "X" on the Chip.

Your finder should look something like:

find.descendant(
      of: find.byKey(Key(label.id)),
      matching: find.byIcon(Icons.cancel),
    );

This says "find the descendent of the InputChip who is the cancel Icon. Then you can tap that if you'd like :)

When you're missing a tap-target, or aren't sure what is happening in the test, have a look at the console after running debugDumpApp();

like image 105
Michael Lee Avatar answered Dec 06 '25 16:12

Michael Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!