/** * 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(); } ); } ); } ); } ); CRICKET NEWS – Page 4 – HOW TO CRIC

CRICKET NEWS

IPL SCHEDULE 2023 – Live Update, Team list, Fixtures, Venues, Team wise Captains, First Match, IPL 2023 Live Streaming And Live Telecast in India

हर साल की तरह इस साल भी IPL 2023 के क्रिकेट को चाहने वालों के लिए बहुत ही सुनहरा मौका है, क्योंकि इस बार आईपीएल 2023 में हमें बहुत कुछ नया देखने के लिए मिलेगा| अब कुछ नया जानेंगे, आईपीएल 2023 की नीलामी पिछले महीने दिसंबर में हुई थी और टूर्नामेंट के लिए सभी फ्रेंचाइजियो …

IPL SCHEDULE 2023 – Live Update, Team list, Fixtures, Venues, Team wise Captains, First Match, IPL 2023 Live Streaming And Live Telecast in India Read More »

IPL All Team Squad 2023: यहां से देखिए आईपीएल के सभी टीमों के खिलाड़ी की लिस्ट?

IPL All Team Squad 2023: यहां से देखिए आईपीएल के सभी टीमों के खिलाड़ी की लिस्ट? आईपीएल ऑल टीम स्क्वाड 2023 इस साल होने वाले आईपीएल 2023 बहुत ज्यादा रोमांचक खेल होने वाला है| आईपीएल के मिनी ऑक्शन खत्म हो चुके हैं| इस साल के आईपीएल टीमों नीलामी 167 करोड़ों रुपए की लगाई गई है| …

IPL All Team Squad 2023: यहां से देखिए आईपीएल के सभी टीमों के खिलाड़ी की लिस्ट? Read More »

IPL 2023: सभी टीमों के सबसे Best ग्यारह खिलाड़ी | IPL 2023: Best playing eleven of all the teams

IPL Team List 2023 IPL 2023 सभी टीमों के सबसे Best 11 खिलाड़ी जो आईपीएल में जाने के लिए यह 10 टीम के ऐसे खिलाड़ी होंगे| जिनका रिकॉर्ड अब तक आईपीएल के अपनी टीम के बेहतरीन खिलाड़ियों में से एक होगा| हाल ही में समाप्त हुए, आईपीएल 2023 की नीलामी में कुछ बड़ी खरीदारी के …

IPL 2023: सभी टीमों के सबसे Best ग्यारह खिलाड़ी | IPL 2023: Best playing eleven of all the teams Read More »

Scroll to Top