Custom matcher for testing jest
yarn add -D @djforth/jest-matchers
In your jest config add the following:
{
"setupTestFrameworkScriptFile": "@djforth/jest-matchers",
}
This includes Jasmine-matchers (which work with jest), see https://github.com/JamieMason/Jasmine-Matchers for details of 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()); |
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')})); |
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'); |
Matcher | Example |
---|---|
toBeElement | expect(document.createElement('div')).toBeElement(); |
hasKey | expect({foo: 'bar'}).hasKey('foo'); |