Skip to content

Commit

Permalink
fix(jest-matchers): message should be function and added test cases f…
Browse files Browse the repository at this point in the history
…or the coverage as well (#32)
  • Loading branch information
antsmartian authored and Kent C. Dodds committed Mar 30, 2018
1 parent 6f01eeb commit fd2df8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ test('using jest helpers to assert element states', () => {
expect(() =>
expect(queryByTestId('count-value2')).toHaveTextContent('2'),
).toThrowError()

// negative test cases wrapped in throwError assertions for coverage.
expect(() =>
expect(queryByTestId('count-value')).not.toBeInTheDOM(),
).toThrowError()
expect(() =>
expect(queryByTestId('count-value1')).toBeInTheDOM(),
).toThrowError()
expect(() =>
expect(queryByTestId('count-value')).toHaveTextContent('3'),
).toThrowError()
expect(() =>
expect(queryByTestId('count-value')).not.toHaveTextContent('2'),
).toThrowError()
})

/* eslint jsx-a11y/label-has-for:0 */
30 changes: 16 additions & 14 deletions src/jest-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const extensions = {
getDisplayName(received)
if (received) {
return {
message:
message: () =>
`${matcherHint(
'.not.toBeInTheDOM',
'received',
Expand All @@ -29,7 +29,7 @@ const extensions = {
}
} else {
return {
message:
message: () =>
`${matcherHint(
'.toBeInTheDOM',
'received',
Expand All @@ -53,22 +53,24 @@ const extensions = {
const pass = matches(textContent, htmlElement, checkWith)
if (pass) {
return {
message: assertMessage(
'.not.toHaveTextContent',
'Expected value not equals to',
htmlElement,
checkWith,
),
message: () =>
assertMessage(
'.not.toHaveTextContent',
'Expected value not equals to',
htmlElement,
checkWith,
),
pass: true,
}
} else {
return {
message: assertMessage(
'.toHaveTextContent',
'Expected value equals to',
htmlElement,
checkWith,
),
message: () =>
assertMessage(
'.toHaveTextContent',
'Expected value equals to',
htmlElement,
checkWith,
),
pass: false,
}
}
Expand Down

0 comments on commit fd2df8d

Please sign in to comment.