Jest TypeError: 无法读取 undefined 的属性 (读取 'width')
import 'react-native'; import React from 'react'; import {describe, it, expect} from '@jest/globals'; import {render, screen} from '@testing-library/react-native'; import renderer from 'react-test-renderer'; import {Button} from 'native-base'; import {Text} from 'react-native'; import {NativeBaseProvider} from 'native-base'; import {Metrics, SafeAreaProvider} from 'react-native-safe-area-context';
const MOCK_INITIAL_METRICS: Metrics = { frame: {width: 320, height: 640, x: 0, y: 0}, insets: {left: 0, right: 0, bottom: 0, top: 0}, };
const Wrapper = ({children}: {children: React.ReactNode}) => {children} ;
describe('Snapshot Testing', () => {
it('Render NativeBase Button with @testing-library/react-native', () => { render( ); expect(screen.toJSON()).toMatchSnapshot(); });
it('Render NativeBase Button with react-test-renderer', () => { const component = renderer.create( …
内容来源: GeekyAnts/NativeBase