Repository navigation
Add additional type checks to adapters - #1701
Conversation
…ValidElementType`
…fNode`, if present
…entType`, if present
| return (typeof node.type === 'function' ? | ||
| functionName(node.type) === type : node.type.name === type) || node.type.displayName === type; | ||
|
|
||
| return typeof node.type === 'function' ? |
There was a problem hiding this comment.
left this since displayNameOfNode returns the display over the ctor name
ljharb
left a comment
There was a problem hiding this comment.
I'm concerned about how to make this not be a breaking change - specifically, with "old enzyme + new adapter" ("new enzyme + old adapter" and "new enzyme + new adapter" should work fine)
| name() { | ||
| return this.single('name', n => displayNameOfNode(n)); | ||
| const adapter = getAdapter(this[OPTIONS]); | ||
| return this.single('name', n => adapter.displayNameOfNode(n)); |
There was a problem hiding this comment.
i think this needs adapter.displayNameOfNode ? adapter.displayNameOfNode(n) : displayNameOfNode(n)
| name() { | ||
| return this.single('name', displayNameOfNode); | ||
| const adapter = getAdapter(this[OPTIONS]); | ||
| return this.single('name', n => adapter.displayNameOfNode(n)); |
There was a problem hiding this comment.
i think this needs adapter.displayNameOfNode ? adapter.displayNameOfNode(n) : displayNameOfNode
| export function nodeHasType(node, type) { | ||
| if (!type || !node) return false; | ||
|
|
||
| const displayName = getAdapter().displayNameOfNode(node); |
There was a problem hiding this comment.
and i think this needs the same treatment
|
|
||
| export function debugNode(node, indentLength = 2, options = {}) { | ||
| if (typeof node === 'string' || typeof node === 'number') return escape(node); | ||
| if (typeof node === 'function') return '[function]'; |
There was a problem hiding this comment.
a) this should probably be [function Foo] where Foo is the functionName
b) could this small change be peeled out into a separate PR with its own tests?
| const booleanValue = Function.bind.call(Function.call, Boolean.prototype.valueOf); | ||
|
|
||
| export function typeName(node) { | ||
| return typeof node.type === 'function' |
There was a problem hiding this comment.
i think all this logic needs to stay as a fallback for when the adapter lacks .displayNameOfNode
| return x => fnsReversed.every(fn => fn(x)); | ||
| } | ||
|
|
||
| export function displayNameOfNode(node) { |
There was a problem hiding this comment.
and i think we may need to keep this as well
| // If the selector is a function, check if the node's constructor matches | ||
| if (typeof selector === 'function') { | ||
| // If the selector is a string, parse it as a simple CSS selector | ||
| if (typeof selector === 'string') { |
There was a problem hiding this comment.
these changes also seem like they could be peeled out into a separate PR?
There was a problem hiding this comment.
They could yeah, I wanted to validate that the apis I was adding were sufficient
| return buildPredicateFromToken(tokens[0]); | ||
| } | ||
| // If the selector is an element type, check if the node's type matches | ||
| if (getAdapter().isValidElementType(selector)) { |
There was a problem hiding this comment.
this needs a fallback for when the adapter lacks .isValidElementType
091fc3e to
d79da18
Compare
ljharb
left a comment
There was a problem hiding this comment.
ok, i rebased this a bit and split up some commits. what this needs now is tests :-)
d79da18 to
8480406
Compare
|
@ljharb I'm hoping to have a moment, i'm pretty swamped with life and work at the moment but may have a second to finish this up in the next few days |
|
@jquense I certainly understand :-) thanks! |
8480406 to
fee9fa5
Compare
fee9fa5 to
e9e63a2
Compare
|
Sorry, this has tests now |
ljharb
left a comment
There was a problem hiding this comment.
Thanks! There’s a few more tweaks needed; if you don’t have a chance to update the PR, I’ll be happy to do it for you.
| })); | ||
| }); | ||
|
|
||
| it.only('should determine valid element types', () => { |
There was a problem hiding this comment.
oops, the only needs to be removed
| class Component extends React.Component { | ||
| render() { return null } | ||
| } | ||
| const ArrowFunction = () => null |
There was a problem hiding this comment.
the arrow function test needs it’s own it, so it can be skipped on React 13
|
|
||
| expect(adapter.isValidElementType('div')).to.equal(true); | ||
| expect(adapter.isValidElementType(Component)).to.equal(true); | ||
| expect(adapter.isValidElementType(ArrowFunction )).to.equal(true); |
| expect(adapter.isValidElementType(Component)).to.equal(true); | ||
| expect(adapter.isValidElementType(ArrowFunction )).to.equal(true); | ||
|
|
||
| if (createPortal) { |
There was a problem hiding this comment.
instead of using if checks, these should be checking the React versions and running conditionslly, as their own it’s
e9e63a2 to
1a6b47b
Compare
|
I've done some rebasing; this PR now has 6 commits, the first 2 of which are (thoroughly) tested. I can pull those into master now, but the last 4 commits still need test coverage. |
b2743d8 to
6824acf
Compare
|
i've added some more tests; now of the 6 commits, |
ee6ce05 to
bdec3d4
Compare
bdec3d4 to
6a47051
Compare
ljharb
left a comment
There was a problem hiding this comment.
k, that should do it. I'll merge in the morning once tests pass.
|
🙇 thanks for the help @ljharb |
6a47051 to
67b9dc0
Compare
- [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [New] Add `displayNameOfNode`, `isValidElementType` (#1701, @jquense) - [New] pass the adapter into `createMountWrapper` (#1592, @jquense) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - update deps - [meta] ensure a license and readme is present in all packages when published
- [New] Add forwardRef support (#1592, @jquense) - [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [New] Add `displayNameOfNode`, `isValidElementType` (#1701, @jquense) - [New] pass the adapter into `createMountWrapper` (#1592, @jquense) - [Fix] preemptively fix compat with React v16.4.3 (#1790, #1778, @gaearon, @aweary) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - update deps - [meta] ensure a license and readme is present in all packages when published
Required for #1592 to work properly, still in progress but i want to make sure the proposed API changes to adapters are ok before i polish up all the tests and what not
cc @ljharb