-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improving api #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kentcdodds
merged 15 commits into
testing-library:master
from
antsmartian:improving-api
Mar 28, 2018
Merged
Improving api #13
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5a2c05f
Improving API's for testing.
dd727d0
Improving Apis
485e8fb
Adding all contributions
96a1a9e
Fixing wrong url
cc2a1c3
Fixing review comments & making colorful assertions :)
3931a69
Rebasing with latest code and moving the new assertions to element-qu…
3ae81f6
Removing unwanted changes
987c4f3
Fixing review comments
57fd424
removing unwanted comments
d1157a2
Adding test cases for the coverage
0cdb02b
Adding in documentation for API's
74d8205
removing commented code and making few changes to the contribution file
8348852
Updating the readme
492645b
Making line break changes
e222206
Update README.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./dist/extend-expect') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import expect from 'expect' //eslint-disable-line import/no-extraneous-dependencies | ||
import extensions from './jest-extensions' | ||
|
||
const {toBeInTheDOM, toHaveTextContent} = extensions | ||
expect.extend({toBeInTheDOM, toHaveTextContent}) | ||
|
||
export default expect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import {matcherHint, printReceived, printExpected} from 'jest-matcher-utils' //eslint-disable-line import/no-extraneous-dependencies | ||
import {matches} from './utils' | ||
|
||
function getDisplayName(subject) { | ||
if (subject && subject.constructor) { | ||
return subject.constructor.name | ||
} else { | ||
return typeof subject | ||
} | ||
} | ||
|
||
const assertMessage = (assertionName, message, received, expected) => | ||
`${matcherHint(`${assertionName}`, 'received', '')} \n${message}: ` + | ||
`${printExpected(expected)} \nReceived: ${printReceived(received)}` | ||
|
||
const extensions = { | ||
toBeInTheDOM(received) { | ||
getDisplayName(received) | ||
if (received) { | ||
return { | ||
message: | ||
`${matcherHint( | ||
'.not.toBeInTheDOM', | ||
'received', | ||
'', | ||
)} Expected the element not to be present` + | ||
`\nReceived : ${printReceived(received)}`, | ||
pass: true, | ||
} | ||
} else { | ||
return { | ||
message: | ||
`${matcherHint( | ||
'.toBeInTheDOM', | ||
'received', | ||
'', | ||
)} Expected the element to be present` + | ||
`\nReceived : ${printReceived(received)}`, | ||
pass: false, | ||
} | ||
} | ||
}, | ||
|
||
toHaveTextContent(htmlElement, checkWith) { | ||
if (!(htmlElement instanceof HTMLElement)) | ||
throw new Error( | ||
`The given subject is a ${getDisplayName( | ||
htmlElement, | ||
)}, not an HTMLElement`, | ||
) | ||
|
||
const textContent = htmlElement.textContent | ||
const pass = matches(textContent, htmlElement, checkWith) | ||
if (pass) { | ||
return { | ||
message: assertMessage( | ||
'.not.toHaveTextContent', | ||
'Expected value not equals to', | ||
htmlElement, | ||
checkWith, | ||
), | ||
pass: true, | ||
} | ||
} else { | ||
return { | ||
message: assertMessage( | ||
'.toHaveTextContent', | ||
'Expected value equals to', | ||
htmlElement, | ||
checkWith, | ||
), | ||
pass: false, | ||
} | ||
} | ||
}, | ||
} | ||
|
||
export default extensions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//eslint-disable-next-line import/prefer-default-export | ||
export function matches(textToMatch, node, matcher) { | ||
if (typeof matcher === 'string') { | ||
return textToMatch.toLowerCase().includes(matcher.toLowerCase()) | ||
} else if (typeof matcher === 'function') { | ||
return matcher(textToMatch, node) | ||
} else { | ||
return matcher.test(textToMatch) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect