输入下面代码的Jest单元测试:import React Component from react;import StyleSheet View Text Image AppState Linking from react-native;import BottomSheet from BottomSheet;import LColors from assetsStringsLColors;
import React from 'react'; import { shallow } from 'enzyme'; import PayModal from '../PayModal';
describe('PayModal', () => { let wrapper;
beforeEach(() => {
wrapper = shallow(
it('should render correctly', () => { expect(wrapper).toMatchSnapshot(); });
it('should call _handleBack method when onClose is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_handleBack'); instance.onClose(); expect(instance._handleBack).toHaveBeenCalled(); });
it('should call _handleAppStateChange method when AppState change', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_handleAppStateChange'); instance._handleAppStateChange('active'); expect(instance._handleAppStateChange).toHaveBeenCalledWith('active'); });
it('should call doWhileGetPayResult method when _handleAppStateChange is called with nextAppState as "active"', () => { const instance = wrapper.instance(); jest.spyOn(instance, 'doWhileGetPayResult'); instance._handleAppStateChange('active'); expect(instance.doWhileGetPayResult).toHaveBeenCalled(); });
it('should call _checkPay method when doWhileGetPayResult is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_checkPay'); instance.doWhileGetPayResult(); expect(instance._checkPay).toHaveBeenCalled(); });
it('should call _fetchData method when _checkPay is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_fetchData'); instance._checkPay(); expect(instance._fetchData).toHaveBeenCalled(); });
it('should call _fetchData method when _handleBack is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_fetchData'); instance._handleBack(); expect(instance._fetchData).toHaveBeenCalled(); });
it('should call _handleAppStateChange method when _handleOnClose is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_handleAppStateChange'); instance._handleOnClose(); expect(instance._handleAppStateChange).toHaveBeenCalled(); });
it('should call _handleAppStateChange method when show is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_handleAppStateChange'); instance.show({}); expect(instance._handleAppStateChange).toHaveBeenCalled(); });
it('should call _fetchData method when show is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_fetchData'); instance.show({}); expect(instance._fetchData).toHaveBeenCalled(); });
it('should call _fetchData method when _handleNetResult is called', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_fetchData'); instance._handleNetResult({}); expect(instance._fetchData).toHaveBeenCalled(); });
it('should call _fetchData method when _handlePayResult is called with code as 6001', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_fetchData'); instance._handlePayResult({ code: 6001 }); expect(instance._fetchData).toHaveBeenCalled(); });
it('should call _fetchData method when _handlePayResult is called with code as -1', () => { const instance = wrapper.instance(); jest.spyOn(instance, '_fetchData'); instance._handlePayResult({ code: -1 }); expect(instance._fetchData).toHaveBeenCalled(); });
it('should call _handlePayResult method when _handlePayResult is called with code as 8000', () => { const instance = wrapper.instance(); jest.spyO
原文地址: http://www.cveoy.top/t/topic/hAic 著作权归作者所有。请勿转载和采集!