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
{{ message }}
Repository navigation
Commit d8bfdb6
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: packages/deprecated/README.md
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,14 +73,16 @@ _Type_
73
73
74
74
## Unit testing deprecations
75
75
76
-
Each deprecation message is logged only once per loaded instance of this package. The exported `logged` object tracks the full message text, so an earlier test can prevent a later test from observing the same warning. Resetting a console spy does not clear this state.
76
+
Each deprecation message is logged only once per loaded instance of this package. The exported `logged` object tracks the full message text. Resetting a console spy does not clear this state.
77
77
78
-
For a suite that exercises a deprecated feature, mark its message as logged in `beforeEach` to suppress it during tests of other behavior. Delete that entry before testing the warning itself, and clean it up in `afterEach` so tests do not depend on their execution order. Limit cleanup to the messages the suite uses.
78
+
Gutenberg's internal Vitest setup clears `logged` before each test in Node, jsdom, and Browser Mode. Suites do not need their own deprecation-history cleanup. If every test that triggers a deprecation asserts the warning, no interaction with `logged` is needed. A message still logs only once within a test. See [Expected console calls](/docs/contributors/code/testing-overview.md#expected-console-calls).
79
+
80
+
For a suite that exercises a deprecated feature, mark its message as logged in `beforeEach` to suppress it during tests of other behavior. Delete that entry before testing the warning itself.
79
81
80
82
This example uses Vitest and the `toHaveWarnedWith` matcher provided by Gutenberg's test setup:
81
83
82
84
```js
83
-
import { afterEach, beforeEach, describe, expect, it } from'vitest';
85
+
import { beforeEach, describe, expect, it } from'vitest';
Setting a `logged` entry also prevents the `deprecated` action from firing. Leave the entry absent when testing that action.
107
105
108
-
If every test that triggers a deprecation already asserts the warning, delete the message's entry in both `beforeEach` and `afterEach`instead of marking it as logged. This keeps the warning assertions independent without suppressing them.
106
+
If your test setup does not clear `logged`, an earlier test can prevent a later test from observing the same warning. Delete the entries for messages your suite uses in `beforeEach` and `afterEach`to keep tests independent. For tests that suppress a warning, set its entry in `beforeEach` instead of deleting it. Limit cleanup to the messages the suite uses.
0 commit comments