expectToastShown function

void expectToastShown({
  1. String? id,
  2. String? description,
})

Assert that a toast notification was shown.

Requires NyToastRecorder.setup to be called before the test. Toast notifications must be recorded via NyToastRecorder.record (integrate into your test's toast notification handler).

Example:

expectToastShown(id: 'success');
expectToastShown(id: 'danger', description: 'Something went wrong');

Implementation

void expectToastShown({String? id, String? description}) {
  final wasShown = NyToastRecorder.wasShown(id: id, description: description);
  expect(
    wasShown,
    isTrue,
    reason:
        'Expected toast to be shown'
        '${id != null ? ' with id "$id"' : ''}'
        '${description != null ? ' with description "$description"' : ''}'
        '. Recorded toasts: ${NyToastRecorder.records}',
  );
}