How to use the react-redux.useDispatch.mockReturnValue function in react-redux

To help you get started, we’ve selected a few react-redux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NERC-CEH / datalab / code / workspaces / web-app / src / containers / projectInfo / ProjectInfoContainer.spec.js View on Github external
jest.mock('react-redux');

const testProj = {
  key: 'testproj',
  name: 'Test Project',
  description: 'A description about Test Project.',
  collaborationLink: 'https://testlab.test-datalabs.nerc.ac.uk',
};

const currentProject = { fetching: false, value: testProj };
const projectUsers = { fetching: false, value: [{ userId: 'user1', name: 'user1@test', role: 'user' }] };
const dispatchMock = jest.fn().mockName('dispatch');

useCurrentProject.mockReturnValue(currentProject);
useProjectUsers.mockReturnValue(projectUsers);
useDispatch.mockReturnValue(dispatchMock);

describe('ProjectInfoContainer', () => {
  it('renders correctly passing correct props to children', () => {
    expect(shallow()).toMatchSnapshot();
  });
});

describe('PureProjectInfoContainer', () => {
  describe('renders correctly to match snapshot', () => {
    it('when there is a collaboration link', () => {
      expect(
        shallow(),
      ).toMatchSnapshot();
    });

    it('when there is not a collaboration link', () => {
github NERC-CEH / datalab / code / workspaces / web-app / src / components / settings / AddUserPermissions.spec.js View on Github external
describe('AddUserPermissions', () => {
  let shallow;

  const dispatchMock = jest.fn().mockName('dispatch');
  useDispatch.mockReturnValue(dispatchMock);

  useUsers.mockReturnValue('users');
  useCurrentUserId.mockReturnValue('current-user-id');
  useCurrentUserSystemAdmin.mockReturnValue('current-user-system-admin');
  useCurrentProjectKey.mockReturnValue({ value: 'testproj' });

  beforeEach(() => {
    shallow = createShallow({ dive: true });
  });

  it('renders pure component with correct props', () => {
    expect(shallow()).toMatchSnapshot();
  });
});
github NERC-CEH / datalab / code / workspaces / web-app / src / components / app / ProjectSwitcher.spec.js View on Github external
describe('ProjectSwitcher', () => {
  const dispatchMock = jest.fn().mockName('dispatch');
  useDispatch.mockReturnValue(dispatchMock);

  useCurrentProject.mockReturnValue(state.currentProject);
  useProjectsArray.mockReturnValue(state.projects);

  beforeEach(() => {
    jest.clearAllMocks();
  });

  it('renders to match snapshot passing correct parameters to children', () => {
    expect(shallow().dive()).toMatchSnapshot();
  });
});
github NERC-CEH / datalab / code / workspaces / web-app / src / components / settings / UserPermissionsTable.spec.js View on Github external
describe('UserPermissionsTable', () => {
  let shallow;

  const dispatchMock = jest.fn().mockName('dispatch');
  useDispatch.mockReturnValue(dispatchMock);

  useProjectUsers.mockReturnValue('users');
  useCurrentUserId.mockReturnValue('current-user-id');
  useCurrentUserSystemAdmin.mockReturnValue('current-user-system-admin');
  useCurrentProjectKey.mockReturnValue({ value: 'testproj' });

  beforeEach(() => {
    shallow = createShallow({ dive: true });
  });

  it('renders pure component with correct props', () => {
    expect(shallow()).toMatchSnapshot();
  });
});
github NERC-CEH / datalab / code / workspaces / web-app / src / components / app / RequireAuth.spec.js View on Github external
jest.mock('../../auth/auth');
jest.mock('../../hooks/authHooks');
jest.mock('../../actions/authActions');

const isAuthenticated = jest.fn();
const getCurrentSession = jest.fn();
getAuth.mockImplementation(() => ({
  isAuthenticated,
  getCurrentSession,
}));

useCurrentUserPermissions.mockReturnValue({ fetching: false, value: ['permission'] });
useCurrentUserTokens.mockReturnValue({ token: 'expectedUserToken' });

const mockDispatch = jest.fn().mockName('dispatch');
useDispatch.mockReturnValue(mockDispatch);

describe('RequireAuth', () => {
  let shallow;

  beforeEach(() => {
    shallow = createShallow();
  });

  const shallowRender = (props = {}) => {
    const defaultProps = {
      PrivateComponent: jest.fn().mockName('privateComponent'),
      PublicComponent: jest.fn().mockName('publicComponent'),
      path: '/path',
      exact: true,
      strict: true,
    };