我当前的工作应用程序在整个屏幕上都被锁定为纵向模式。该应用程序在 webview 上播放嵌入的 YouTube 视频,我只想在全屏播放时才允许横向模式。
我看到本地方式有一些技巧,我认为与 React Native 不兼容。我还检查了react-native-orientation但它对我没有帮助。
有没有一种简单而干净的方法可以实现这一点?
我将使用酶测试生命周期功能,包括componentWillReceiveProps.
在其他任何事情之前,我的组件应该包裹materialUi样式并与redux连接.否则,渲染函数中会出现错误,因为我使用了包括FlatButton在内的material-ui组件.
const wrapper = mount(
<MuiThemeProvider muiTheme={muiTheme}>
<Provider store={store}>
<MemoryRouter>
<MyComponent />
</MemoryRouter>
</Provider>
</MuiThemeProvider>)
// absolutely fail
wrapper.find(MyComponent).setProps({ something })
expect(MyComponent.prototype.componentWillReceiveProps.calledOnce).toBe(true)
Run Code Online (Sandbox Code Playgroud)
所以问题是我不能将setProps()用于MyComponent,因为酶不允许应用非根组件.我无法通过改变道具来测试componentWillReceiveProps或其他必要的部分.
如何设置/更改MyComponent的道具以便我可以测试componentWillReceiveProps?
我按照文档中的步骤来测试史诗.
...
store.dispatch({ type: FETCH_USER });
expect(store.getActions()).toEqual([
{ type: FETCH_USER },
{ type: FETCH_USER_FULFILLED, payload }
]);
...
Run Code Online (Sandbox Code Playgroud)
但是我失败了,因为后来接到了第二个动作.
Test failed
Expected value to equal:
[{"type": "FETCH_USER"}, {"type": "FETCH_USER_FULFILLED", "payload": [some]}]
Received:
[{"type": "FETCH_USER"}]
Difference:
- Expected
+ Received
@@ -1,20 +1,5 @@
Array [
Object {"type": "FETCH_USER"},
Object {"type": "FETCH_USER_FULFILLED", "payload": [some]} ] // this is what should be.
Run Code Online (Sandbox Code Playgroud)
所以我想我应该知道派遣何时完成或类似的事情.我怎么解决这个问题?
我使用了fetch()和Rx.Observable.fromPromise而不是ajax.getJSON()
这是我的史诗.
const fetchUserEpic = (action$) =>
action$
.ofType(FETCH_USER)
.mergeMap(() => {
return Rx.Observable.fromPromise(api.fetchUser())
.map((users) => ({ …Run Code Online (Sandbox Code Playgroud) jestjs ×2
reactjs ×2
unit-testing ×2
android ×1
enzyme ×1
ios ×1
javascript ×1
material-ui ×1
react-native ×1
webview ×1