@lodgify/enzyme-jest-expect-helpers

1.0.1 • Public • Published

Enzyme and Jest expect helpers

Simple expect helpers for unit testing with Jest and Enzyme

Usage examples

import React from 'react';
import { shallow, mount } from 'enzyme';
import {
  expectComponentToBe,
  expectComponentToHaveChildren,
  expectComponentToHaveProps,
  expectComponentToHaveDisplayName,
  } from '@lodgify/enzyme-jest-expect-helpers';
import { Button as LodgifyButton } from '@lodgify/ui';

import { PrimaryButton } from './PrimaryButton';

const getButton = props => shallow(<Button {...props}>Press me</Button>);

describe('<PrimaryButton />', () => {
  it('should render a single `LodgifyButton` component', () => {
    const wrapper = getButton();
    expectComponentToBe(wrapper, LodgifyButton);
  });

  it('should have the the right props', () => {
    const wrapper = getButton();
    expectComponentToHaveProps(wrapper, {
      isLoading: false,
      isRounded: true,
    });
  });

  it('should render the right children', () => {
    const wrapper = getButton();
    expectComponentToHaveChildren(wrapper, 'Press me');
  });

  it('should have `displayName` PrimaryButton', () => {
    expectComponentToHaveDisplayName(PrimaryButton, 'PrimaryButton')
  });
});

Contributing

Avoid wasting time in PRs by creating this pre-commit git hook...

# .git/hooks/pre-commit
npm run pre-commit

Readme

Keywords

none

Package Sidebar

Install

npm i @lodgify/enzyme-jest-expect-helpers

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

6.84 kB

Total Files

8

Last publish

Collaborators

  • lodgify-ci