logsToConsole function

Matcher logsToConsole(
  1. dynamic expected, {
  2. ConsoleConfiguration? consoleConfig,
  3. bool onlyIfAssertsAreEnabled = false,
})

A Matcher used to compare a list of logs against a provided matcher.

In the case the actual value is a callback that is run, any errors caused by the callback will be caught and ignored. If consoleConfig is set to errorConfig, the actual list of logs will include the error message from the caught error.

Examples:

To look for a specific String in any log index, the best solution is to use hasLog, but the behavior can be mimicked by passing in the correct Iterable matchers.

  expect(callbackFunction, logsToConsole(anyElement(contains('I expect this log'))));

When passed a List, the matcher will do an equality check on the actual log List.

Alternatively, the String can be wrapped in a contains to check the if the comparable index contains that substring.

  expect(callbackFunction, logsToConsole(['I expect this log', 'And this Log']));
  expect(callbackFunction, logsToConsole([
    contains('I expect'),
    contains('And this'),
  ]));

All usual Iterable matchers can also be used.

  expect(callbackFunction, logsToConsole(containsAll(['I expect this log'])));
  expect(callbackFunction, logsToConsole(containsAllInOrder(['I expect this log'])));
  expect(callbackFunction, logsToConsole(hasLength(1)));

Related: hasLog, hasNoLogs

Implementation

Matcher logsToConsole(dynamic expected, {ConsoleConfiguration? consoleConfig, bool onlyIfAssertsAreEnabled = false}) =>
    _LoggingFunctionMatcher(expected, config: consoleConfig, onlyIfAssertsAreEnabled: onlyIfAssertsAreEnabled);