Skip to content

Commit de06821

Browse files
committed
Add hasMessage to RecordingLogger
1 parent ddafddb commit de06821

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/testing-utils.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ export interface LoggedMessage {
184184

185185
export class RecordingLogger implements Logger {
186186
messages: LoggedMessage[] = [];
187-
groups: string[] = [];
188-
unfinishedGroups: Set<string> = new Set();
187+
readonly groups: string[] = [];
188+
readonly unfinishedGroups: Set<string> = new Set();
189189
private currentGroup: string | undefined = undefined;
190190

191191
constructor(private readonly logToConsole: boolean = true) {}
@@ -199,6 +199,19 @@ export class RecordingLogger implements Logger {
199199
}
200200
}
201201

202+
/**
203+
* Checks whether the logged messages contain `messageOrRegExp`.
204+
*
205+
* If `messageOrRegExp` is a string, this function returns true as long as
206+
* `messageOrRegExp` appears as part of one of the `messages`.
207+
*
208+
* If `messageOrRegExp` is a regular expression, this function returns true as long as
209+
* one of the `messages` matches `messageOrRegExp`.
210+
*/
211+
hasMessage(messageOrRegExp: string | RegExp): boolean {
212+
return hasLoggedMessage(this.messages, messageOrRegExp);
213+
}
214+
202215
isDebug() {
203216
return true;
204217
}
@@ -302,7 +315,7 @@ export function assertNotLogged(
302315
message: string | RegExp,
303316
) {
304317
t.false(
305-
hasLoggedMessage(logger.messages, message),
318+
logger.hasMessage(message),
306319
`'${message}' should not have been logged, but was.`,
307320
);
308321
}

0 commit comments

Comments
 (0)