/** * External dependencies */ import TestRenderer, { act } from 'react-test-renderer'; import { createRegistry, RegistryProvider } from '@wordpress/data'; import { Component as ReactComponent } from '@wordpress/element'; import { COLLECTIONS_STORE_KEY as storeKey } from '@woocommerce/block-data'; /** * Internal dependencies */ import { useCollection } from '../use-collection'; jest.mock( '@woocommerce/block-data', () => ( { __esModule: true, COLLECTIONS_STORE_KEY: 'test/store', } ) ); class TestErrorBoundary extends ReactComponent { constructor( props ) { super( props ); this.state = { hasError: false, error: {} }; } static getDerivedStateFromError( error ) { // Update state so the next render will show the fallback UI. return { hasError: true, error }; } render() { if ( this.state.hasError ) { return
; } return this.props.children; } } describe( 'useCollection', () => { let registry, mocks, renderer; const getProps = ( testRenderer ) => { const { results, isLoading } = testRenderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query return { results, isLoading, }; }; const getWrappedComponents = ( Component, props ) => ( ); const getTestComponent = () => ( { options } ) => { const items = useCollection( options ); return
; }; const setUpMocks = () => { mocks = { selectors: { getCollectionError: jest.fn().mockReturnValue( false ), getCollection: jest .fn() .mockImplementation( () => ( { foo: 'bar' } ) ), hasFinishedResolution: jest.fn().mockReturnValue( true ), }, }; registry.registerStore( storeKey, { reducer: () => ( {} ), selectors: mocks.selectors, } ); }; beforeEach( () => { registry = createRegistry(); mocks = {}; renderer = null; setUpMocks(); } ); it( 'should throw an error if an options object is provided without ' + 'a namespace property', () => { const TestComponent = getTestComponent(); act( () => { renderer = TestRenderer.create( getWrappedComponents( TestComponent, { options: { resourceName: 'products', query: { bar: 'foo' }, }, } ) ); } ); //eslint-disable-next-line testing-library/await-async-query const props = renderer.root.findByType( 'div' ).props; expect( props.error.message ).toMatch( /options object/ ); expect( console ).toHaveErrored( /your React components:/ ); renderer.unmount(); } ); it( 'should throw an error if an options object is provided without ' + 'a resourceName property', () => { const TestComponent = getTestComponent(); act( () => { renderer = TestRenderer.create( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', query: { bar: 'foo' }, }, } ) ); } ); //eslint-disable-next-line testing-library/await-async-query const props = renderer.root.findByType( 'div' ).props; expect( props.error.message ).toMatch( /options object/ ); expect( console ).toHaveErrored( /your React components:/ ); renderer.unmount(); } ); it( 'should return expected behaviour for equivalent query on props ' + 'across renders', () => { const TestComponent = getTestComponent(); act( () => { renderer = TestRenderer.create( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'products', query: { bar: 'foo' }, }, } ) ); } ); const { results } = getProps( renderer ); // rerender act( () => { renderer.update( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'products', query: { bar: 'foo' }, }, } ) ); } ); // re-render should result in same products object because although // query-state is a different instance, it's still equivalent. const { results: newResults } = getProps( renderer ); expect( newResults ).toBe( results ); // now let's change the query passed through to verify new object // is created. // remember this won't actually change the results because the mock // selector is returning an equivalent object when it is called, // however it SHOULD be a new object instance. act( () => { renderer.update( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'products', query: { foo: 'bar' }, }, } ) ); } ); const { results: resultsVerification } = getProps( renderer ); expect( resultsVerification ).not.toBe( results ); expect( resultsVerification ).toEqual( results ); renderer.unmount(); } ); it( 'should return expected behaviour for equivalent resourceValues on' + ' props across renders', () => { const TestComponent = getTestComponent(); act( () => { renderer = TestRenderer.create( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'products', resourceValues: [ 10, 20 ], }, } ) ); } ); const { results } = getProps( renderer ); // rerender act( () => { renderer.update( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'products', resourceValues: [ 10, 20 ], }, } ) ); } ); // re-render should result in same products object because although // query-state is a different instance, it's still equivalent. const { results: newResults } = getProps( renderer ); expect( newResults ).toBe( results ); // now let's change the query passed through to verify new object // is created. // remember this won't actually change the results because the mock // selector is returning an equivalent object when it is called, // however it SHOULD be a new object instance. act( () => { renderer.update( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'products', resourceValues: [ 20, 10 ], }, } ) ); } ); const { results: resultsVerification } = getProps( renderer ); expect( resultsVerification ).not.toBe( results ); expect( resultsVerification ).toEqual( results ); renderer.unmount(); } ); it( 'should return previous query results if `shouldSelect` is false', () => { mocks.selectors.getCollection.mockImplementation( ( state, ...args ) => { return args; } ); const TestComponent = getTestComponent(); act( () => { renderer = TestRenderer.create( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'products', resourceValues: [ 10, 20 ], }, } ) ); } ); const { results } = getProps( renderer ); // rerender but with shouldSelect to false act( () => { renderer.update( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'productsb', resourceValues: [ 10, 30 ], shouldSelect: false, }, } ) ); } ); const { results: results2 } = getProps( renderer ); expect( results2 ).toBe( results ); // expect 2 calls because internally, useSelect invokes callback twice // on mount. expect( mocks.selectors.getCollection ).toHaveBeenCalledTimes( 2 ); // rerender again but set shouldSelect to true again and we should see // new results act( () => { renderer.update( getWrappedComponents( TestComponent, { options: { namespace: 'test/store', resourceName: 'productsb', resourceValues: [ 10, 30 ], shouldSelect: true, }, } ) ); } ); const { results: results3 } = getProps( renderer ); expect( results3 ).not.toEqual( results ); expect( results3 ).toEqual( [ 'test/store', 'productsb', {}, [ 10, 30 ], ] ); } ); } ); ; About Us – Digital Marketing Agency Nashik

About

Nashik Digital Solutions started as a small operation a few years ago, born out of a passion for helping local businesses thrive in the digital age. 

Founded by digital marketing veterans, our agency quickly gained a reputation for delivering results-driven strategies tailored to the unique needs of businesses in Nashik and beyond.

Over the years, we’ve grown into a full-service digital marketing powerhouse, now employing a team of 30+ specialists across various digital disciplines. Our growth is a testament to our commitment to staying ahead of the curve in the ever-evolving digital landscape. 

We’ve helped transform countless businesses, from small local shops to large corporations, by leveraging the power of digital marketing.

What sets us apart is our deep understanding of the local market combined with our global perspective on digital trends. We believe in a personalized approach, treating each client’s business as if it were our own. Our team is dedicated to continuous learning and innovation, ensuring that we always bring the most effective and cutting-edge strategies to the table.

4.9

87+ Reviews

4.8

100+ Reviews

9/10

400+ Reviews

What We Do

Full-service Digital Marketing Solutions

What We Do

At Nashik Digital Solutions, we offer comprehensive digital marketing services tailored for Nashik businesses. Our team of experts combines local market knowledge with cutting-edge digital strategies to help your brand stand out. We focus on data-driven approaches and creative solutions to maximize your online presence and ROI.

Search Engine Optimization (SEO)

 Our SEO experts work their magic to help your website rank higher in search results, drive organic traffic, and improve visibility.

Social Media Marketing

Our creative minds create engaging content and manage your social media presence to build brand awareness and connect with your audience.

Content Marketing

We develop high-quality, relevant content that resonates with your target market and establishes your brand as an industry authority.

Email Marketing

Our targeted email campaigns help nurture leads, retain customers, and drive conversions through personalized messaging.

Pay-Per-Click Advertising (PPC)

We create and manage targeted ad campaigns on platforms like Google Ads to drive qualified traffic to your website.

Web Design & Development

Our skilled designers and developers create user-friendly, responsive websites that reflect your brand identity.

Relation & Awards

Ready to elevate your digital presence? We’re here to help!

Get Ready To Take Your Digital Marketing Efforts in The Right Direction Escape the queue and get started with the right and essential things to do by partnering with us. Choose us to take your business to the next level, right where it deserves to be.

Let’s talk

First Name
Email
Message
The form has been submitted successfully!
There has been some error while submitting the form. Please verify all form fields again.