@@ -224,6 +224,66 @@ test('todo() method with message', (t) => {
224224});
225225```
226226
227+ ## Expecting tests to fail
228+
229+ These are tests written to otherwise pass but there is some issue (often
230+ upstream) causing them to fail. Rather than using ` skip ` or ` todo ` , which would
231+ effectively silence the failure, the test would instead be marked ` xfail ` (` x `
232+ from "expected" + ` fail ` ). That way, when the issue is resolved, that is
233+ explicitly surfaced.
234+
235+ The test would normally be written:
236+
237+ ``` js
238+ it (' should do the thing' , () => {
239+ assert .strictEqual (doTheThing (), true );
240+ });
241+
242+ it (' should do the thing' , () => {
243+ assert .strictEqual (doTheThing (), true );
244+ });
245+ ```
246+
247+ But for whatever reason, ` doTheThing ` is not and _ currently_ cannot return ` true ` .
248+
249+ ``` js
250+ it .xfail (' should do the thing' , () => {
251+ assert .strictEqual (doTheThing (), true );
252+ });
253+
254+ it (' should do the thing' , { xfail: true }, () => {
255+ assert .strictEqual (doTheThing (), true );
256+ });
257+ ```
258+
259+ ` skip ` and/or ` todo ` are mutually exclusive to ` xfail ` , and ` skip ` or ` todo `
260+ will "win" when both are applied (` skip ` wins against both, and ` todo ` wins
261+ against ` xfail ` ).
262+
263+ These tests will be skipped (and not run):
264+
265+ ``` js
266+ it .xfail (' should do the thing' , { skip: true }, () => {
267+ assert .strictEqual (doTheThing (), true );
268+ });
269+
270+ it .skip (' should do the thing' , { xfail: true }, () => {
271+ assert .strictEqual (doTheThing (), true );
272+ });
273+ ```
274+
275+ These tests will be marked "todo" (silencing errors):
276+
277+ ``` js
278+ it .xfail (' should do the thing' , { todo: true }, () => {
279+ assert .strictEqual (doTheThing (), true );
280+ });
281+
282+ it .todo (' should do the thing' , { xfail: true }, () => {
283+ assert .strictEqual (doTheThing (), true );
284+ });
285+ ```
286+
227287## ` describe() ` and ` it() ` aliases
228288
229289Suites and tests can also be written using the ` describe() ` and ` it() `
0 commit comments