mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 12:45:37 +08:00
Move JS integration tests to root folder
Reviewed By: mkonicek Differential Revision: D2658454 fb-gh-sync-id: b639ea995411a7e43903264318b5fca4d2f1e9f7
This commit is contained in:
committed by
facebook-github-bot-9
parent
7a794cc72b
commit
a027218641
74
IntegrationTests/PromiseTest.js
Normal file
74
IntegrationTests/PromiseTest.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2015-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.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var React = require('react-native');
|
||||
var { TestModule } = React.NativeModules;
|
||||
|
||||
var PromiseTest = React.createClass({
|
||||
shouldResolve: false,
|
||||
shouldReject: false,
|
||||
shouldSucceedAsync: false,
|
||||
shouldThrowAsync: false,
|
||||
|
||||
componentDidMount() {
|
||||
Promise.all([
|
||||
this.testShouldResolve(),
|
||||
this.testShouldReject(),
|
||||
this.testShouldSucceedAsync(),
|
||||
this.testShouldThrowAsync(),
|
||||
]).then(() => TestModule.markTestPassed(
|
||||
this.shouldResolve && this.shouldReject &&
|
||||
this.shouldSucceedAsync && this.shouldThrowAsync
|
||||
));
|
||||
},
|
||||
|
||||
testShouldResolve() {
|
||||
return TestModule
|
||||
.shouldResolve()
|
||||
.then(() => this.shouldResolve = true)
|
||||
.catch(() => this.shouldResolve = false);
|
||||
},
|
||||
|
||||
testShouldReject() {
|
||||
return TestModule
|
||||
.shouldReject()
|
||||
.then(() => this.shouldReject = false)
|
||||
.catch(() => this.shouldReject = true);
|
||||
},
|
||||
|
||||
async testShouldSucceedAsync() : Promise {
|
||||
try {
|
||||
await TestModule.shouldResolve();
|
||||
this.shouldSucceedAsync = true;
|
||||
} catch (e) {
|
||||
this.shouldSucceedAsync = false;
|
||||
}
|
||||
},
|
||||
|
||||
async testShouldThrowAsync() : Promise {
|
||||
try {
|
||||
await TestModule.shouldReject();
|
||||
this.shouldThrowAsync = false;
|
||||
} catch (e) {
|
||||
this.shouldThrowAsync = true;
|
||||
}
|
||||
},
|
||||
|
||||
render() : ReactElement {
|
||||
return <React.View />;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PromiseTest.displayName = 'PromiseTest';
|
||||
|
||||
module.exports = PromiseTest;
|
||||
Reference in New Issue
Block a user