Skip to content

Commit f56d0ec

Browse files
committed
Add hasMessage to RecordingLogger
1 parent 33edb83 commit f56d0ec

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
@@ -157,8 +157,8 @@ export interface LoggedMessage {
157157

158158
export class RecordingLogger implements Logger {
159159
messages: LoggedMessage[] = [];
160-
groups: string[] = [];
161-
unfinishedGroups: Set<string> = new Set();
160+
readonly groups: string[] = [];
161+
readonly unfinishedGroups: Set<string> = new Set();
162162
private currentGroup: string | undefined = undefined;
163163

164164
constructor(private readonly logToConsole: boolean = true) {}
@@ -172,6 +172,19 @@ export class RecordingLogger implements Logger {
172172
}
173173
}
174174

175+
/**
176+
* Checks whether the logged messages contain `messageOrRegExp`.
177+
*
178+
* If `messageOrRegExp` is a string, this function returns true as long as
179+
* `messageOrRegExp` appears as part of one of the `messages`.
180+
*
181+
* If `messageOrRegExp` is a regular expression, this function returns true as long as
182+
* one of the `messages` matches `messageOrRegExp`.
183+
*/
184+
hasMessage(messageOrRegExp: string | RegExp): boolean {
185+
return hasLoggedMessage(this.messages, messageOrRegExp);
186+
}
187+
175188
isDebug() {
176189
return true;
177190
}
@@ -275,7 +288,7 @@ export function assertNotLogged(
275288
message: string | RegExp,
276289
) {
277290
t.false(
278-
hasLoggedMessage(logger.messages, message),
291+
logger.hasMessage(message),
279292
`'${message}' should not have been logged, but was.`,
280293
);
281294
}

0 commit comments

Comments
 (0)