Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move cart creation out of trigger #2572

Merged
merged 8 commits into from
Jul 27, 2020
Prev Previous commit
Next Next commit
Fix cart context tests
Signed-off-by: sirugh <[email protected]>
  • Loading branch information
sirugh committed Jul 22, 2020
commit d66c329b0a89b100f0e05f3a1f19c11fc2ff4b6a
16 changes: 12 additions & 4 deletions packages/peregrine/lib/context/__tests__/cart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React, { useEffect } from 'react';
import { createTestInstance } from '@magento/peregrine';

import CartContextProvider, { useCartContext } from '../cart';
jest.mock('@apollo/react-hooks', () => ({
useApolloClient: jest.fn(),
useMutation: jest.fn(() => [jest.fn()])
}));

jest.mock('react-redux', () => ({
connect: jest.fn((mapStateToProps, mapDispatchToProps) =>
Expand Down Expand Up @@ -56,9 +60,13 @@ test('mapDispatchToProps maps dispatch to props', () => {

test('renders children', () => {
const { Component } = CartContextProvider;
const props = {
asyncActions: { getCartDetails: jest.fn() }
};

const symbol = Symbol();
const { root } = createTestInstance(
<Component>
<Component {...props}>
<i symbol={symbol} />
</Component>
);
Expand All @@ -71,7 +79,7 @@ test('provides state and actions via context', () => {
const props = {
actions: { one: 'one' },
cartState: { details: {} },
asyncActions: { one: 'one', two: 'two' }
asyncActions: { getCartDetails: jest.fn(), one: 'one', two: 'two' }
};

createTestInstance(
Expand All @@ -96,7 +104,7 @@ test('appends derivedDetails and isEmpty value from state with empty cart', () =
const props = {
actions: { one: 'one' },
cartState: { details: {} },
asyncActions: { one: 'one', two: 'two' }
asyncActions: { getCartDetails: jest.fn(), one: 'one', two: 'two' }
};

createTestInstance(
Expand Down Expand Up @@ -135,7 +143,7 @@ test('calculates derivedDetails and isEmpty from state with cart data', () => {
}
}
},
asyncActions: { one: 'one', two: 'two' }
asyncActions: { getCartDetails: jest.fn(), one: 'one', two: 'two' }
};

createTestInstance(
Expand Down