import React from 'react'; import { Text } from 'react-native'; import renderer from 'react-test-renderer'; import PayModal from '../PayModal';

jest.mock('@utils/native', () => ({ aliPay: jest.fn(), wxPay: jest.fn(), }));

describe('PayModal', () => { it('renders correctly', () => { const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); });

it('renders loading state', () => { const tree = renderer.create(); tree.getInstance().setState({ isLoading: true }); expect(tree.toJSON()).toMatchSnapshot(); });

it('renders success state', () => { const tree = renderer.create(); tree.getInstance().setState({ isLoading: false, leftTime: 0 }); expect(tree.toJSON()).toMatchSnapshot(); });

it('renders pay way row', () => { const tree = renderer.create(); const payWayRow = tree.getInstance()._renderPayWayRow({ title: '支付宝', appId: 'alipayapp', index: 0, }); expect(payWayRow).toMatchSnapshot(); });

it('handles payment', () => { const tree = renderer.create(); const instance = tree.getInstance(); instance._doPayment = jest.fn(); instance._doPayment({ appId: 'alipayapp' }); expect(instance._doPayment).toHaveBeenCalledWith({ appId: 'alipayapp' }); }); })


原文地址: https://www.cveoy.top/t/topic/hAi0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录