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
Refactor test helpers #1336
Merged
Merged
Refactor test helpers #1336
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b3dcf40
Refactor test helpers
ylemkimon 6cdff3c
Update helpers.js
ylemkimon d751297
Merge branch 'master' into jest-test-helpers
ylemkimon 4250d06
Remove toBeTruthy checks
ylemkimon 7343e48
Merge branch 'master' into jest-test-helpers
ylemkimon 0c96b20
Merge branch 'master' into jest-test-helpers
ylemkimon 6e1773b
Merge branch 'jest-test-helpers' of https://github.com/ylemkimon/KaTe…
ylemkimon 17ca384
Used tagged literals
ylemkimon 721f62f
Use .toHaveLength
ylemkimon a8c91eb
Use tagged literals
ylemkimon 96cdfa0
Use to{Build,Parse}Like where possible
ylemkimon 4ad8dfd
Use snapshot where possible
ylemkimon aeb5350
Join into one line where <88 chars
ylemkimon 4e84e93
Revert console.warn() to throw an error
ylemkimon 4e387b8
Remove call to console.warn from stack traces
ylemkimon 6f6865d
Merge branch 'master' into jest-test-helpers
ylemkimon d89600c
Merge branch 'master' into jest-test-helpers
ylemkimon 527c5b3
Merge branch 'master' into jest-test-helpers
ylemkimon 92f13b1
Merge branch 'master' into jest-test-helpers
ylemkimon a49c067
Fix merge errors
ylemkimon 6572122
Merge branch 'master' into jest-test-helpers
ylemkimon f783eb8
Remove `getTree`
ylemkimon fc47230
Extract `expected` string construction into `printExpectedResult`
ylemkimon b557735
Merge branch 'master' into jest-test-helpers
ylemkimon c64ef13
Merge branch 'master' into jest-test-helpers
kevinbarabash File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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
Oops, something went wrong.
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.
This looks a little strange to me b/c I'm not used to template strings returning things that aren't strings. Maybe we could introduce a
tex
template literal function. It would look like:The
tex
function could be exported for use by other people. Also, it would be easier to understand what's going on. I'm still not sure howexpect
is acting as a template function without us modifying/replacing it with our own implementation.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.
@kevinbarabash I agree that it can be unfamiliar since it's new syntax. However, it's new way to call the function with arguments: an array of strings with
raw
property, an array of raw strings, and expressions in${}
. Asexpect
accepts any object, it just passes the first argument through and we can handle them in the matchers. Maybe we can document them in theCONTRIBUTING.md
?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.
If
expect
passes through only one argument, does that mean this won't work with${interpolated expressions}
?I don't think the new code looks much more confusing than the old code -- the weirdest part is that
expect
just passes on its argument, and the action is in the chained methods afterward -- but that's a general Jest thing. However, until I read the template literal description I didn't really understand what the code was doing.What about
expectTex`1 \over 2 \over 3`
which is equivalent toexpect(tex`1 \over 2 \over 3`)
, i.e., the string gets processed before callingexpect
, instead of requiring all matches to process it? I think the weirdest part is overloadingexpect
in this unintended way (unless Jest suggests doing this?).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.
@edemaine Yes, it will throw an error if there are
${interpolated expressions}
andr
will return the part before the first one.I think we can think of
expect.toParse
asexpect the raw string of the tagged literal to success parsing
.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.
It's not related, but Jest provides a way of creating a table using tagged template literal:
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.
Interesting. I was unaware of jest's use of tagged template literals.
expectTex
seems like a good compromise.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.
@ylemkimon apologies for not raising my concerns about
expect
as a tagged template earlier.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.
@kevinbarabash @edemaine
I don't mind. I think productive discussion is necessary.
I still disagree. The purpose of using tagged template literal is to avoid using escape backslashes and simplify test cases. I think using
expectTeX
defeats this purpose as there is no difference between processing before passing toexpect
and processing in the matchers, when using KaTeX matchers.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.
@ylemkimon There would be a difference if we needed to use Jest's matchers. But I can't actually think of any situation where we'd want to use those on a TeX string.