Search code examples
flutterdartdart-test

How to combine matchers


I have a test like:

const myText = 'This is my test';

expect(myText, contains('This'));
expect(myText, contains('test'));

How can I combine those 2 matchers to have only 1 expect ?


Solution

  • You can combine the matchers with allOf:

    const myText = 'This is my test';
    
    expect(myText, allOf([contains('This'), contains('test')]));
    

    More generally, you can combine any matchers using: