blob: b8e59ac8480db28a32184007f0eadd73233c27d2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { SpyConsole } from "./spyConsole";
export default function validateLogs(
logs: Array<string | (() => boolean | Array<any>)>,
mockConsole: SpyConsole["log"] | SpyConsole["error"],
options: { prefix?: string } = {}
) {
logs.forEach((log, idx) => {
if (typeof log === "function") {
const expected = log();
expect(mockConsole).toHaveBeenNthCalledWith(
idx + 1,
...(Array.isArray(expected) ? expected : [expected])
);
} else {
if (options.prefix) {
expect(mockConsole).toHaveBeenNthCalledWith(
idx + 1,
options.prefix,
log
);
} else {
expect(mockConsole).toHaveBeenNthCalledWith(idx + 1, log);
}
}
});
}
|