Skip to content

Commit

Permalink
Add missing specs and docs for skipping with different aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
michalwarda committed Apr 26, 2022
1 parent 839964c commit c29e59f
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 31 deletions.
76 changes: 55 additions & 21 deletions docs/GlobalAPI.md
Expand Up @@ -731,6 +731,61 @@ test.each`
});
```

### `test.failing(name, fn)`

Also under the aliases: `it.failing(name, fn)`

:::note

This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.

:::

Use `test.failing` when you are writing a test and expecting it to fail. These tests will behave the other way normal tests do. If `failing` test will throw any errors then it will pass. If it does not throw it will fail.

:::tip

You can use this type of tests i.e. when writing code in a BDD way. In that case the tests will not show up as failing until they pass. Then you can just remove the `failing` modifier to make them pass.

:::

Example:

```js
test.failing('it is not equal', () => {
expect(5).toBe(6); // this test will pass
});

test.failing('it is equal', () => {
expect(10).toBe(10); // this test will fail
});
```

### `test.only.failing(name, fn)`

Also under the aliases: `it.only.failing(name, fn)`, `fit.failing(name, fn)`

:::note

This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.

:::

Use `test.only.failing` if you want to only run specific failing test.


### `test.skip.failing(name, fn)`

Also under the aliases: `it.skip.failing(name, fn)`, `xit.failing(name, fn)`, `xtest.failing(name, fn)`

:::note

This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.

:::

Use `test.skip.failing` if you want to skip run specific failing test.

### `test.only(name, fn, timeout)`

Also under the aliases: `it.only(name, fn, timeout)`, and `fit(name, fn, timeout)`
Expand Down Expand Up @@ -878,24 +933,3 @@ const add = (a, b) => a + b;

test.todo('add should be associative');
```

### `test.failing(name, fn)`

Also under the aliases: `it.failing(name, fn)`, `xtest.failing(name, fn)`, `xit.failing(name, fn)`, `it.skip.failing(name, fn)`, `it.only.failing(name, fn)`

Use `test.failing` when you are writing a test and expecting it to fail. These tests will behave the other way normal tests do. If `failing` test will throw any errors then it will pass. If it does not throw it will fail.

_Note_: You can use this type of tests i.e. when writing code in a BDD way. In that case the tests will not show up as failing until they pass. Then you can just remove the `failing` modifier to make them pass.

Example:

```js
test.failing('it is not equal', () => {
expect(5).toBe(6); // this test will pass
});

test.failing('it is equal', () => {
expect(10).toBe(10); // this test will fail
});
```

49 changes: 45 additions & 4 deletions e2e/__tests__/__snapshots__/testFailing.test.ts.snap
Expand Up @@ -5,10 +5,13 @@ exports[`works with all statuses 1`] = `
✓ passes
✕ fails
✓ failing failes = passes
✓ failing failes = passes with test syntax
✕ failing passes = fails
○ skipped skips
○ skipped skipped failing 1
○ skipped skipped failing 2
○ skipped skipped failing with different syntax
○ skipped skipped failing with another different syntax
✎ todo todo
● fails
Expand Down Expand Up @@ -37,15 +40,53 @@ exports[`works with only mode 1`] = `
"FAIL __tests__/worksWithOnlyMode.test.js
block with only, should pass
✓ failing failes = passes, should pass
○ skipped failing test
○ skipped passing test
○ skipped failing test but skipped
○ skipped passing test but skipped
block with only, should fail
✕ failing passes = fails, should fail
○ skipped failing test
○ skipped passing test
○ skipped failing test but skipped
○ skipped passing test but skipped
block with only in other it, should skip
✕ failing test
○ skipped failing passes = fails, should fail but skipped
○ skipped passing test but skipped
block with only with different syntax, should fail
✕ failing passes = fails, should fail 1
✕ failing passes = fails, should fail 2
○ skipped failing test but skipped
○ skipped passing test but skipped
● block with only, should fail › failing passes = fails, should fail
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
● block with only in other it, should skip › failing test
expect(received).toBe(expected) // Object.is equality
Expected: 101
Received: 10
41 | // eslint-disable-next-line jest/no-focused-tests
42 | it.only('failing test', () => {
> 43 | expect(10).toBe(101);
| ^
44 | });
45 |
46 | it('passing test but skipped', () => {
at Object.toBe (__tests__/worksWithOnlyMode.test.js:43:16)
block with only with different syntax, should failfailing passes = fails, should fail 1
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
● block with only with different syntax, should fail › failing passes = fails, should fail 2
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error."
`;
Expand Down
14 changes: 13 additions & 1 deletion e2e/test-failing/__tests__/statuses.test.js
Expand Up @@ -23,14 +23,26 @@ it.failing('failing failes = passes', () => {
expect(10).toBe(101);
});

test.failing('failing failes = passes with test syntax', () => {
expect(10).toBe(101);
});

it.skip.failing('skipped failing 1', () => {
expect(10).toBe(10);
});

it.skip.failing('skipped failing 2', () => {
test.skip.failing('skipped failing 2', () => {
expect(10).toBe(101);
});

it.failing('failing passes = fails', () => {
expect(10).toBe(10);
});

xit.failing('skipped failing with different syntax', () => {
expect(10).toBe(10);
});

xtest.failing('skipped failing with another different syntax', () => {
expect(10).toBe(10);
});
41 changes: 37 additions & 4 deletions e2e/test-failing/__tests__/worksWithOnlyMode.test.js
Expand Up @@ -10,11 +10,11 @@ describe('block with only, should pass', () => {
expect(10).toBe(101);
});

it('failing test', () => {
it('failing test but skipped', () => {
expect(10).toBe(101);
});

it('passing test', () => {
it('passing test but skipped', () => {
expect(10).toBe(10);
});
});
Expand All @@ -24,11 +24,44 @@ describe('block with only, should fail', () => {
expect(10).toBe(10);
});

it('failing test', () => {
it('failing test but skipped', () => {
expect(10).toBe(101);
});

it('passing test', () => {
it('passing test but skipped', () => {
expect(10).toBe(10);
});
});

describe('block with only in other it, should skip', () => {
it.failing('failing passes = fails, should fail but skipped', () => {
expect(10).toBe(10);
});

// eslint-disable-next-line jest/no-focused-tests
it.only('failing test', () => {
expect(10).toBe(101);
});

it('passing test but skipped', () => {
expect(10).toBe(10);
});
});

describe('block with only with different syntax, should fail', () => {
fit.failing('failing passes = fails, should fail 1', () => {
expect(10).toBe(10);
});

test.only.failing('failing passes = fails, should fail 2', () => {
expect(10).toBe(10);
});

it('failing test but skipped', () => {
expect(10).toBe(101);
});

it('passing test but skipped', () => {
expect(10).toBe(10);
});
});
10 changes: 9 additions & 1 deletion packages/jest-circus/src/eventHandler.ts
Expand Up @@ -122,7 +122,15 @@ const eventHandler: Circus.EventHandler = (event, state) => {
}
case 'add_test': {
const {currentDescribeBlock, currentlyRunningTest, hasStarted} = state;
const {asyncError, fn, mode, testName: name, timeout, concurrent, failing} = event;
const {
asyncError,
fn,
mode,
testName: name,
timeout,
concurrent,
failing,
} = event;

if (currentlyRunningTest) {
currentlyRunningTest.errors.push(
Expand Down

0 comments on commit c29e59f

Please sign in to comment.