alt*_*alt 6 testing automated-tests react-native
我有一个create-react-native-app
,我需要编写一个测试来防止用户将应用程序带回前台时问题的回归(似乎很难重新连接 socket.io 连接)。
目前我必须通过以下一些步骤手动测试:
我该如何为此编写自动化测试?我jest
在应用程序中用于单元测试。
Har*_*ani -1
基本用法
要查看当前状态,您可以检查 AppState.currentState,它将保持最新状态。但是,currentState 在启动时将为 null,而 AppState 通过桥检索它。
import React, {Component} from 'react'
import {AppState, Text} from 'react-native'
class AppStateExample extends Component {
state = {
appState: AppState.currentState
}
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!')
}
this.setState({appState: nextAppState});
}
render() {
return (
<Text>Current state is: {this.state.appState}</Text>
);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
527 次 |
最近记录: |