-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: to review: `jest-utils/jasmine-pit` and `__integration_tests_/promise_it/**` It does not work with jasmine1 yet. If the direction is ok i'll add jasmine1 support to this PR. Closes #970 Reviewed By: dmitriiabramov Differential Revision: D3309064 fbshipit-source-id: ff597945554e8cad4f2add8232236429810a966c
- Loading branch information
Dmitrii Abramov
authored and
Facebook Github Bot 3
committed
May 17, 2016
1 parent
08a5cdd
commit 644a512
Showing
27 changed files
with
425 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
jest.unmock('../runJest'); | ||
|
||
const runJest = require('../runJest'); | ||
|
||
describe('promise it', () => { | ||
it('works with fit', () => { | ||
const result = runJest.json('promise_it', ['promise_fit-test.js']); | ||
const json = result.json; | ||
|
||
expect(json.numTotalTests).toBe(3); | ||
expect(json.numPassedTests).toBe(1); | ||
expect(json.numFailedTests).toBe(1); | ||
expect(json.numPendingTests).toBe(1); | ||
expect(json.testResults[0].message).toMatch(/will run and fail/); | ||
}); | ||
|
||
it('works with xit', () => { | ||
const result = runJest.json('promise_it', ['promise_xit-test.js']); | ||
const json = result.json; | ||
|
||
expect(json.numTotalTests).toBe(2); | ||
expect(json.numPassedTests).toBe(1); | ||
expect(json.numFailedTests).toBe(0); | ||
expect(json.numPendingTests).toBe(1); | ||
}); | ||
|
||
it('throws when not a promise is returned', () => { | ||
const result = runJest.json('promise_it', ['returning_values-test.js']); | ||
const json = result.json; | ||
|
||
expect(json.numTotalTests).toBe(11); | ||
expect(json.numPassedTests).toBe(0); | ||
expect(json.numFailedTests).toBe(11); | ||
expect(json.numPendingTests).toBe(0); | ||
}); | ||
|
||
it('tests async promise code', () => { | ||
const result = runJest.json('promise_it', ['promise_it-test.js']); | ||
const json = result.json; | ||
const message = json.testResults[0].message; | ||
|
||
expect(json.numTotalTests).toBe(7); | ||
expect(json.numPassedTests).toBe(4); | ||
expect(json.numFailedTests).toBe(3); | ||
|
||
expect(message).toMatch('fails if promise is rejected'); | ||
expect(message).toMatch('works with done.fail'); | ||
expect(message).toMatch('fails a sync test'); | ||
}); | ||
|
||
it('works with pit', () => { | ||
const result = runJest.json('promise_it', ['pit-test.js']); | ||
const json = result.json; | ||
expect(json.numTotalTests).toBe(2); | ||
expect(json.numPassedTests).toBe(1); | ||
expect(json.numFailedTests).toBe(1); | ||
expect(json.testResults[0].message).toMatch(/will run and fail/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('pit alias', () => { | ||
pit('will run', () => { | ||
return Promise.resolve(); | ||
}); | ||
|
||
pit('will run and fail', () => { | ||
return Promise.reject(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
integration_tests/promise_it/__tests__/promise_fit-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('promise fit', () => { | ||
it('fails but will be skipped', () => { | ||
expect(true).toBe(false); | ||
}); | ||
|
||
fit('will run', () => { | ||
return Promise.resolve(); | ||
}); | ||
|
||
fit('will run and fail', () => { | ||
return Promise.reject(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('promise it', () => { | ||
beforeEach(() => { | ||
this.someContextValue = 'value'; | ||
}); | ||
|
||
// passing tests | ||
it('passes a sync test', () => { | ||
expect(1).toBe(1); | ||
}); | ||
|
||
it('waits for promise to be resolved', () => { | ||
return Promise.resolve(); | ||
}); | ||
|
||
it('works with done', done => { | ||
done(); | ||
}); | ||
|
||
it('is bount to context object', () => { | ||
return new Promise(resolve => { | ||
if (this.someContextValue !== 'value') { | ||
throw new Error('expected this.someContextValue to be set', this.someContextValue); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
|
||
// failing tests | ||
it('fails if promise is rejected', () => { | ||
return Promise.reject(new Error('rejected promise returned')); | ||
}); | ||
|
||
it('works with done.fail', done => { | ||
done.fail(new Error('done.fail was called')); | ||
}); | ||
|
||
it('fails a sync test', () => { | ||
expect('sync').toBe('failed'); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
integration_tests/promise_it/__tests__/promise_xit-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('promise xit', () => { | ||
xit('fails but will be skipped', () => { | ||
expect(true).toBe(false); | ||
}); | ||
|
||
it('will run', () => { | ||
return Promise.resolve(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
integration_tests/promise_it/__tests__/returning_values-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('returning values', () => { | ||
[1, 'string', 0.1, null, NaN, Infinity, true, false, [1], {}, () => {}] | ||
.forEach(val => { | ||
it(`throws if '${val}:${typeof val}' is returned`, () => { | ||
return val; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.