You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+25-10
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,22 @@
1
1
# jest-to-log
2
2
3
-
# What
3
+
##What
4
4
5
5
Test log messages with [`jest`](https://jestjs.io/)
6
6
7
-
# Why?
7
+
##Why?
8
8
9
9
Grown out of the need to test `console.log/error` messages or writes to `process.stdout/stderr` in my cli-facing apps. Note: this is not a full-blown cli-testing tool, but a check for important log messages from your app that's tested with jest.
10
10
11
-
# Usage
11
+
##Usage
12
12
13
13
```javascript
14
14
require("jest-to-log");
15
15
//or
16
16
import"jest-to-log";
17
17
```
18
18
19
-
# Example
19
+
##Example
20
20
21
21
```javascript
22
22
//in jest test file
@@ -36,8 +36,21 @@ describe("toLog", () => {
36
36
});
37
37
});
38
38
```
39
+
## Caveat
40
+
- When using with typescript (i.e., `ts-jest` and `@types/jest`), it's advised to explicitly import the `expect` from `@jest/globals` to avoid type conflicts:
39
41
40
-
# Matchers
42
+
```javascript
43
+
//test.ts
44
+
45
+
import {expect} from"@jest/globals"
46
+
47
+
// ...your test
48
+
```
49
+
50
+
- Do NOT set the `injectGlobals` jest option to `false`, or else a `ReferenceError` will be thrown. This is because the matchers are extended onto the `expect` object _without_ importing it from `@jest/globals`.
|`toLogStderr `| Checks if a function **explicitly** write to `process.stderr`. Cannot be used to capture `console.error/warn` calls due to the custom console implementation of `jest`. |
47
60
|`toLogErrorOrWarn`| Checks if a function logs an error or warning via `console.error()` or `console.warn()`, respectively. |
0 commit comments