diff --git a/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts b/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts index eee9a5a30a..15d935bb7c 100644 --- a/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts +++ b/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts @@ -164,15 +164,18 @@ const addTaxesForBasketItemTestCase = [ const nonEmptyResponseTestCases = Object.entries(testMap) as Array< [NonEmptyResponseMutations, Argument] > -// Most test cases only apply to non-delete test cases, some (error handling) can include deleteBasket -const allTestCases = [ - ...nonEmptyResponseTestCases, + +// Endpoints returning void response on success +const emptyResponseTestCases = [ deleteTestCase, addPriceBooksToBasketTestCase, addTaxesForBasketTestCase, addTaxesForBasketItemTestCase ] +// Most test cases only apply to non-empty response test cases, some (error handling) can include deleteBasket +const allTestCases = [...nonEmptyResponseTestCases, ...emptyResponseTestCases] + describe('ShopperBaskets mutations', () => { const storedCustomerIdKey = `${DEFAULT_TEST_CONFIG.siteId}_customer_id` beforeAll(() => { @@ -254,23 +257,20 @@ describe('ShopperBaskets mutations', () => { assertUpdateQuery(result.current.customerBaskets, oldCustomerBaskets) } ) - test.each([ - deleteTestCase, - addPriceBooksToBasketTestCase, - addTaxesForBasketTestCase, - addTaxesForBasketItemTestCase - ])('`%s` returns void on success', async () => { - // Almost the standard 'returns data' test, just a different return type - const [mutationName, options] = deleteTestCase - mockMutationEndpoints(basketsEndpoint, oldBasket) - const {result, waitForValueToChange: wait} = renderHookWithProviders(() => { - return useShopperBasketsMutation(mutationName) - }) - expect(result.current.data).toBeUndefined() - act(() => result.current.mutate(options)) - await waitAndExpectSuccess(wait, () => result.current) - expect(result.current.data).toBeUndefined() - }) + test.each(emptyResponseTestCases)( + '`%s` returns void on success', + async (mutationName, options) => { + // Almost the standard 'returns data' test, just a different return type + mockMutationEndpoints(basketsEndpoint, oldBasket) + const {result, waitForValueToChange: wait} = renderHookWithProviders(() => { + return useShopperBasketsMutation(mutationName) + }) + expect(result.current.data).toBeUndefined() + act(() => result.current.mutate(options)) + await waitAndExpectSuccess(wait, () => result.current) + expect(result.current.data).toBeUndefined() + } + ) test('`deleteBasket` removes the basket from the cache on success', async () => { // Almost the standard 'updates cache' test, but the cache changes are different const [mutationName, options] = deleteTestCase