Skip to content

djforth/jest-matchers

Repository files navigation

jest-matchers

Build Status

Custom matcher for testing jest

Install

yarn add -D @djforth/jest-matchers

Adding to jest-matcher to jest config

In your jest config add the following:

{
"setupTestFrameworkScriptFile": "@djforth/jest-matchers",
}

Matchers:

This includes Jasmine-matchers (which work with jest), see https://github.com/JamieMason/Jasmine-Matchers for details of matchers

Immutable Matchers

Matchers for Immutable JS

Matcher Example
toBeImmutableMap expect(Immutable.Map()).toBeImmutableMap();
toBeImmutableList expect(Immutable.List()).toBeImmutableList();
toBeImmutableOrderedMap expect(Immutable.OrderedMap()).toBeImmutableOrderedMap();
equalsImmutable expect(Immutable.Map()).equalsImmutable(Immutable.Map());
hasImmutableKey expect(Immutable.Map()).hasImmutableKey(Immutable.Map());

Moment Matchers

Matchers for Moment JS. Based on moments query methods

Matcher Example
toBeMoment expect(moment()).toBeMoment();
equalsMoment expect(moment()).equalsMoment(moment());
toBeAfter expect(moment('28-01-2013')).toBeAfter(moment('27-01-2013'));
toBeBefore expect(moment('28-01-2013')).toBeBefore(moment('29-01-2013'));
toBeSameOrAfter expect(moment('28-01-2013')).toBeSameOrAfter(moment('28-01-2013'));
toBeSameOrBefore expect(moment('28-01-2013')).toBeSameOrBefore(moment('28-01-2013'));
toBeBetween expect(moment('28-01-2013')).toBeBetween({start: moment('27-01-2013'), finish: moment('29-01-2013')}));

Element matchers

Matcher Example
toBeElement expect(document.createElement('div')).toBeElement();
toHaveAttribute expect(document.createElement('div')).toHaveAttribute('aria-hidden', 'false');
toHaveTextContent expect(document.createElement('div')).toHaveTextContent('Some text');
toHaveCssClass expect(document.createElement('div')).toHaveCssClass('some-class');

Other Matchers

Matcher Example
toBeElement expect(document.createElement('div')).toBeElement();
hasKey expect({foo: 'bar'}).hasKey('foo');

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published