/** * 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(); } ); } ); } ); } ); 1xbet Casino AZ – HOW TO CRIC

1xbet Casino AZ

1xbet Nadir Rəsmi Sayt 1xbet Azərbaycan Bukmeker Kontoru, Bonuslar, Apk

1xbet Nadir Rəsmi Sayt 1xbet Azərbaycan Bukmeker Kontoru, Bonuslar, ApkHər vahid promosyonun öz mərcləri mülk və siz əmsalları 1,4 olan mərclərə hadisələrə mərc etməlisiniz. Content Təzə Bahisçilər üçün Sakit Gəlmisiniz Bonusu Bukmeker Kontorunda Idman Mərclərinin Növləri Bukmeker Kontorunda Qeydiyyat 1xbet Android ötrü 1xbet Mobil Müştəri Bet-də Mərcdən Imtina Eləmək Mümkündürmü? Bukmeker Proqramları Oranlar Və Bukmeyker …

1xbet Nadir Rəsmi Sayt 1xbet Azərbaycan Bukmeker Kontoru, Bonuslar, Apk Read More »

1xbet Azerbaycan Yükle Mobil Az Indir Android Os I

1xbet Azerbaycan Yükle Mobil Az Indir Android Os I1xbet mobi saytında idman, canlı bahis, oyunlar və ən bir daha bölmə mövcuddur. Content Bet Azerbaycan Qeydiyyat Mobi Seyrək Yukle Elaqe Nomresi 614 Push Elan Sizi Xəbərdarlıq Edəcək Bet Azərbaycan Yükle Android Os Və Iphone: Added Bonus 100, Başlanğıc, Idman Mərcləri Link Bet Proloq, Güzgü 1 Xbet …

1xbet Azerbaycan Yükle Mobil Az Indir Android Os I Read More »

1win Yükl? Android Apk V? Ios App 2023 Müftə Indir Dizajnum 11< Tg

1win Yükl? Android Apk V? Ios App 2023 Müftə Indir Dizajnum 11< TgEyni zamanda, bu gün müxtəlif üsullarla yayına biləcəyiniz blokadaya hazır olmalısınız 1xbet. Content Bet Yukle Onlayn Yuvalar Android-də Necə çubuqlamaq Olar? Bet Azerbaycan Yukle Bet Bədii Dəstək Win Seyrək Oyunlar Və Bədii Oyunlar Android In Yüklə Android Apk Və Ios App 2023 Müftə …

1win Yükl? Android Apk V? Ios App 2023 Müftə Indir Dizajnum 11< Tg Read More »

Scroll to Top