/** * External dependencies */ import TestRenderer from 'react-test-renderer'; /** * Internal dependencies */ import withCategory from '../with-category'; import * as mockUtils from '../../components/utils'; import * as mockBaseUtils from '../../base/utils/errors'; jest.mock( '../../components/utils', () => ( { getCategory: jest.fn(), } ) ); jest.mock( '../../base/utils/errors', () => ( { formatError: jest.fn(), } ) ); const mockCategory = { name: 'Clothing' }; const attributes = { categoryId: 1 }; const TestComponent = withCategory( ( props ) => { return (
); } ); const render = () => { return TestRenderer.create( ); }; describe( 'withCategory Component', () => { let renderer; afterEach( () => { mockUtils.getCategory.mockReset(); } ); describe( 'lifecycle events', () => { beforeEach( () => { mockUtils.getCategory.mockImplementation( () => Promise.resolve() ); renderer = render(); } ); it( 'getCategory is called on mount with passed in category id', () => { const { getCategory } = mockUtils; expect( getCategory ).toHaveBeenCalledWith( attributes.categoryId ); expect( getCategory ).toHaveBeenCalledTimes( 1 ); } ); it( 'getCategory is called on component update', () => { const { getCategory } = mockUtils; const newAttributes = { ...attributes, categoryId: 2 }; renderer.update( ); expect( getCategory ).toHaveBeenNthCalledWith( 2, newAttributes.categoryId ); expect( getCategory ).toHaveBeenCalledTimes( 2 ); } ); it( 'getCategory is hooked to the prop', () => { const { getCategory } = mockUtils; const props = renderer.root.findByType( 'div' ).props; props.getCategory(); expect( getCategory ).toHaveBeenCalledTimes( 2 ); } ); } ); describe( 'when the API returns category data', () => { beforeEach( () => { mockUtils.getCategory.mockImplementation( ( categoryId ) => Promise.resolve( { ...mockCategory, id: categoryId } ) ); renderer = render(); } ); it( 'sets the category props', () => { const props = renderer.root.findByType( 'div' ).props; expect( props.error ).toBeNull(); expect( typeof props.getCategory ).toBe( 'function' ); expect( props.isLoading ).toBe( false ); expect( props.category ).toEqual( { ...mockCategory, id: attributes.categoryId, } ); } ); } ); describe( 'when the API returns an error', () => { const error = { message: 'There was an error.' }; const getCategoryPromise = Promise.reject( error ); const formattedError = { message: 'There was an error.', type: 'api' }; beforeEach( () => { mockUtils.getCategory.mockImplementation( () => getCategoryPromise ); mockBaseUtils.formatError.mockImplementation( () => formattedError ); renderer = render(); } ); it( 'sets the error prop', ( done ) => { const { formatError } = mockBaseUtils; getCategoryPromise.catch( () => { const props = renderer.root.findByType( 'div' ).props; expect( formatError ).toHaveBeenCalledWith( error ); expect( formatError ).toHaveBeenCalledTimes( 1 ); expect( props.error ).toEqual( formattedError ); expect( typeof props.getCategory ).toBe( 'function' ); expect( props.isLoading ).toBe( false ); expect( props.category ).toBeNull(); done(); } ); } ); } ); } ); Mostbet India – HOW TO CRIC

Mostbet India

Mostbet Real Or Perhaps Fake: Check Our Official Licenc

Mostbet Real Or Perhaps Fake: Check Our Official Licence Mostbet Official Testimonials Read Customer Service Reviews Of Mostbet Com Content You Will Be Focused Into Your Account Responsible Gambling Is Mostbet Lawful In India? Mostbet On-line Casino – Acquire Your First Bonus Up To Twenty-five, 000 Rs With Promo Code Can I Use Your Own …

Mostbet Real Or Perhaps Fake: Check Our Official Licenc Read More »

Mostbet Bd Support: Helpline Number And Other Support Channel

Mostbet Bd Support: Helpline Number And Other Support Channels Mostbet India: Official Site, Registration, Bonus 25000 Login Content 📲 क्या मैं Google Play या ऐप स्टोर से आधिकारिक एप्लिकेशन डाउनलोड कर सकता हूं? Sport Betting Welcome Bonus Mostbet Official Reviews Registration And Verification At Mostbet Is The Bookmaker Available On Mobile Devices? अपने स्मार्टफोन या टैबलेट …

Mostbet Bd Support: Helpline Number And Other Support Channel Read More »

Mostbet Official Reviews Read Customer Service Reviews Of Mostbet Co

Mostbet Official Reviews Read Customer Service Reviews Of Mostbet Com Mostbet App Download For Android And Ios 2023 Content How Do I Install The Mostbet App On Android? Is Mostbet Legal To Play In India? Mostbet Video Review Mostbet Mobile App Vs Browser Version Mostbet Casino How To Bet On Cricket Using Mostbet App? Registration …

Mostbet Official Reviews Read Customer Service Reviews Of Mostbet Co Read More »

Mostbet India: Official Site, Registration, Bonus 25000 Logi

Mostbet India: Official Site, Registration, Bonus 25000 Login Official Website For Sports Betting With Bdt 25,000 Bonus Content Deposit And Withdrawal Methods At Mostbet Casino What Is The Secret To Win Most Bet Aviator Game? How To Place A Bet In 3 Steps? How To Download The Mostbet Casino App? Ios Download Instruction Drops & …

Mostbet India: Official Site, Registration, Bonus 25000 Logi Read More »

Scroll to Top