首页 > 解决方案 > 如何模拟反应原生 3rd 方模块“rn-sliding-up-panel”

问题描述

我正在尝试在我的新react native init项目中运行纱线测试,并在我的项目中添加了第 3 方模块,例如 rn-sliding-up-panel

在我的 App.js 中看起来像这样:

import React from 'react';
import {View, Button, Text} from 'react-native';

import SlidingUpPanel from 'rn-sliding-up-panel';

const styles = {
  container: {
    flex: 1,
    backgroundColor: 'white',
    alignItems: 'center',
    justifyContent: 'center'
  }
}

class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Button title='Show panel' onPress={() => this._panel.show()} />
        <SlidingUpPanel ref={c => this._panel = c}>
          <View style={styles.container}>
            <Text>Here is the content inside panel</Text>
            <Button title='Hide' onPress={() => this._panel.hide()} />
          </View>
        </SlidingUpPanel>
      </View>
    )
  }
}

不知何故,在我运行纱线测试后,它失败了:

 ● Test suite failed to run

/The Codes/ssa-mobile/node_modules/rn-sliding-up-panel/SlidingUpPanel.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react'
                                                                                                ^^^^^

SyntaxError: Unexpected identifier

有没有办法通过添加这个第 3 方模块来通过纱线测试笑话?

注意:在我使用这个“rn-sliding-up-panel”模块之前,测试工作完美

标签: react-nativejestjs

解决方案


推荐阅读