diff options
Diffstat (limited to 'packages/turbo-test-utils/src/validateLogs.ts')
| -rw-r--r-- | packages/turbo-test-utils/src/validateLogs.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/turbo-test-utils/src/validateLogs.ts b/packages/turbo-test-utils/src/validateLogs.ts new file mode 100644 index 0000000..b8e59ac --- /dev/null +++ b/packages/turbo-test-utils/src/validateLogs.ts @@ -0,0 +1,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); + } + } + }); +} |
