-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
fix(startup error): update @testing-library/dom to update pretty-format #522
fix(startup error): update @testing-library/dom to update pretty-format #522
Conversation
@benelliott what do you think? |
Will take a look |
@johncrim These changes look good to me, but while you're there, do you think it would be worth adding support for the If we keep the code similar to I was trying to decide if this would be a breaking change since we are exposing the type of |
Thanks @benelliott - that sounds good. I wasn't aware of how the RE possible breaking change, in export type MatcherFunction = (
content: string,
element: Element | null,
) => boolean But export type Match = (
textToMatch: string,
node: HTMLElement | null,
matcher: Matcher,
options?: MatcherOptions,
) => boolean I haven't dug in enough to determine if this node type is incorrect (would a node be returned of type |
Actually due to covariance/contravariance I think the widening of the parameter type of the |
@benelliott - agreed, I was thinking about it backwards - thanks. I think we're in a compatibility pickle then, since existing users have a dependency on @testing-library/dom So, the question is whether to:
I'm thinking the best thing to do right now is to kick the can down the road, and update Revised PR coming right up... |
Crap - I can't figure out a way to update transitive dependencies in a way that is reliable across generally used versions of yarn and npm. Yarn has So, updating I will add some tests for the number matcher. |
I removed the "throw error on number Matcher" and added support for number matchers in Presumably the other methods that take matchers can also take number matchers - this should be handled automatically by I think the breaking change to |
I will merge after @benelliott approval. Thanks. |
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.
Thanks @johncrim for the effort with this - once you remove that outdated comment I think this looks good!
Not sure if @NetanelBasal has any thoughts on the minor breaking change.
textContentMatcher = (_, elem) => matcher(getTextContent(elem), elem); | ||
} else { | ||
// number Matcher not supported |
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.
Outdated comment
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.
@benelliott I'm not familiar with this library.
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.
We could bump to a major release if you guys think this is a breaking change. @benelliott @johncrim
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 is technically a breaking change due to the change to MatcherFunction
described above, but it's a fairly small breaking change at that.
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 it'll break someone app it should be a major release
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.
I agree, though the change was breaking it was not a major release for @testing-library/dom. I wish they hadn't made that change.
As long as it's not big deal to you, I think the major release is correct. This change does make a major version change to the @testing-library/dom dependency, which is part of the spectator API.
Thanks @benelliott and @NetanelBasal - comment removed. |
Thanks! |
@johncrim, Can you please update the commit message to include the breaking change so that the standard version package understands it? |
fixes: ngneat#519 BREAKING CHANGE: This change will result in a compile error for any `MatcherFunction` that uses `HTMLElement` properties or functions. `MatcherFunction` in `@testing-library/dom` now receives a parameter of type `Element`, where it previously was `HTMLElement` - so users will have to test/cast to `HTMLElement` if they need `HTMLElement` properties or methods in their matcher function.
Number matchers behave the same as if number.toString() were used as the matcher. Eg 8 and '8' will return the same matcher results.
64966d9
to
0657886
Compare
@NetanelBasal I rebased to fix the commit message - also improved the wording of the feat(number matcher) commit, and squashed the last commit. So, same file changes, hopefully improved commit wording. |
…at (#522) BREAKING CHANGE: This change will result in a compile error for any `MatcherFunction` that uses `HTMLElement` properties or functions. `MatcherFunction` in `@testing-library/dom` now receives a parameter of type `Element`, where it previously was `HTMLElement` - so users will have to test/cast to `HTMLElement` if they need `HTMLElement` properties or methods in their matcher function.
API change while updating to new @testing-library/dom
fixes: #519
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #519
What is the new behavior?
Karma tests run without failure.
And: Matchers can now be numbers - a number matcher just matches number text, so the behavior is the same as if the matcher were
numberMatcher.toString()
. Because the change to theMatcher
signature comes along with the dependency update required by this fix, the bug fix and exciting new feature come together.Does this PR introduce a breaking change?
The breaking change will occur due to the change to
MatcherFunction
in@testing-library/dom
- the MatcherFunction now passes in anElement
, where it previously wasHTMLElement
- so users will have to test/cast toHTMLElement
if they needHTMLElement
-specific properties in their matcher function.It's unfortunate that this change was added in a minor version of
@testing-library/dom
. Since spectator depends on this external interface that changed, there's no way (that I can find) to fix this major issue without taking the API change.Other information
The @testing-library/dom API changed a little, so I had to update
byTextContent()
to fix some typing errors - no issue there, the new API is less strict, so there should be no change to the spectator API.The issue I found is that type
Matcher
can be anumber
, and if it is anumber
it would have thrown with the previous code. I added a check to prevent that error (also needed to compile), but I'm not sure what the correct behavior is for anumber
matcher, so I'm throwing an exception. If you'd like I can add tests to verify that an exception is thrown, but it's also possible that different behavior is expected if anumber
matcher is passed in. Please clarify what the correct behavior is.edit: I removed the "throw error on number Matcher" and added support for number matchers in
byTextContent()
.