Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add end to end tests
  • Loading branch information
mattphillips committed Sep 18, 2018
commit 392c1d055ece909abc80575cff87c88664b84da5
82 changes: 82 additions & 0 deletions e2e/__tests__/__snapshots__/test-todo.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`shows error messages when called with invalid argument 1`] = `
"FAIL __tests__/todo_non_string.test.js
● Test suite failed to run

Invalid first argument: () => {}. Todo must be called with a string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might look weird, when the fn is not a oneliner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, perhaps we should just remove this as per @rickhanlonii's comments below. I'm pretty flexible with how this API looks. Maybe just validation of a minimum one arg with the first being a string? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just a simple "todo must be called with just a string", or something similar, is better. No need to stringify the implementation as long as our stack trace point points back to the declaration


6 | */
7 |
> 8 | it.todo(() => {});
| ^
9 |

at packages/jest-jasmine2/build/jasmine/Env.js:480:15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we strip this from stack trace? cc @SimenB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB please teach me this magic (again), I've tried but not been able to remove it :(

at __tests__/todo_non_string.test.js:8:4

"
`;

exports[`shows error messages when called with multiple arguments 1`] = `
"FAIL __tests__/todo_multiple_args.test.js
● Test suite failed to run

Todo must be called with only a description.

6 | */
7 |
> 8 | it.todo('todo later', () => {});
| ^
9 |

at packages/jest-jasmine2/build/jasmine/Env.js:476:15
at __tests__/todo_multiple_args.test.js:8:4

"
`;

exports[`shows error messages when called with no arguments 1`] = `
"FAIL __tests__/todo_no_args.test.js
● Test suite failed to run

Todo must be called with only a description.

6 | */
7 |
> 8 | it.todo();
| ^
9 |

at packages/jest-jasmine2/build/jasmine/Env.js:476:15
at __tests__/todo_no_args.test.js:8:4

"
`;

exports[`works with all statuses 1`] = `
"FAIL __tests__/statuses.test.js
✓ passes
✕ fails
✎ todo
○ skipped 1 test

● fails

expect(received).toBe(expected) // Object.is equality

Expected: 101
Received: 10

11 |
12 | it('fails', () => {
> 13 | expect(10).toBe(101);
| ^
14 | });
15 |
16 | it.skip('skips', () => {

at __tests__/statuses.test.js:13:14

"
`;
55 changes: 55 additions & 0 deletions e2e/__tests__/test-todo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

const path = require('path');
const runJest = require('../runJest');
const {extractSummary} = require('../Utils');
const dir = path.resolve(__dirname, '../test-todo');

test('works with all statuses', () => {
const result = runJest(dir, ['statuses.test.js']);
expect(result.status).toBe(1);
const output = extractSummary(result.stderr)
.rest.split('\n')
.map(line => line.trimRight())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? If yes, please extract to a helper function instead of copying it in every test

.join('\n');
expect(output).toMatchSnapshot();
});

test('shows error messages when called with no arguments', () => {
const result = runJest(dir, ['todo_no_args.test.js']);
expect(result.status).toBe(1);
const output = extractSummary(result.stderr)
.rest.split('\n')
.map(line => line.trimRight())
.join('\n');
expect(output).toMatchSnapshot();
});

test('shows error messages when called with multiple arguments', () => {
const result = runJest(dir, ['todo_multiple_args.test.js']);
expect(result.status).toBe(1);
const output = extractSummary(result.stderr)
.rest.split('\n')
.map(line => line.trimRight())
.join('\n');
expect(output).toMatchSnapshot();
});

test('shows error messages when called with invalid argument', () => {
const result = runJest(dir, ['todo_non_string.test.js']);
expect(result.status).toBe(1);
const output = extractSummary(result.stderr)
.rest.split('\n')
.map(line => line.trimRight())
.join('\n');
expect(output).toMatchSnapshot();
});
20 changes: 20 additions & 0 deletions e2e/test-todo/__tests__/statuses.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

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

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

it.skip('skips', () => {
expect(10).toBe(101);
});

it.todo('todo');
8 changes: 8 additions & 0 deletions e2e/test-todo/__tests__/todo_multiple_args.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

it.todo('todo later', () => {});
8 changes: 8 additions & 0 deletions e2e/test-todo/__tests__/todo_no_args.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

it.todo();
8 changes: 8 additions & 0 deletions e2e/test-todo/__tests__/todo_non_string.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

it.todo(() => {});
5 changes: 5 additions & 0 deletions e2e/test-todo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"testEnvironment": "node"
}
}