Skip to content
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 failing tests - account for the morph function now returning a promise #2528

Merged
merged 2 commits into from Mar 1, 2022

Conversation

VicGUTT
Copy link
Contributor

@VicGUTT VicGUTT commented Dec 25, 2021

The morph tests do not account for the morph function now being asynchronous. This PR is an attempt to remedy that.
That said, this PR seemed to have revealed a false positive in the test non-keyed elements are replaced instead of moved. I'll try and figure out what's going on at a later date.


expect(dom.querySelector('span').is_me).toBeTruthy()
})

test('non-keyed elements are replaced instead of moved', () => {
test('non-keyed elements are replaced instead of moved', async () => {
Copy link
Contributor Author

@VicGUTT VicGUTT Dec 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Fix this test

  • Figure out the intent
  • Figure out what went wrong where

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is to demostrate that the first list item does not move. The test sets a custom property on the li tag then it triggers a mutation where the text content of the first list item changes and a second list item is added. Note, the new dom element looks like the first one before the mutation but it's actually a brand new node as the custom property is still set on the first item. If the node was keyed, the mutation would move the first node to position due and prepend a new node so the custom property would be on the second list item.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no I did get what the code was doing, my question was more like "Why is this the expected behavior in the first place". But I admit my phrasing wasn't the best, and thanks for the thorough answer ✌️.

Now I figured this behavior is wanted when the lookahead option is set to false, otherwise the expected behavior is the opposite, meaning : "non-keyed elements are moved instead of replaced".

So my question now would go to @calebporzio directly because I'm confused as to what the default boolean value for the lookahead option should be.

The docs sais it should be false but it was changed to true in #d07aeee.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I feel confident in thinking the default lookahead value is false, therefore I've pushed my latest changes ✌️

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it's already reverted to false on the main branch. 👍

@@ -319,6 +319,8 @@ function addNodeTo(node, parent) {

return clone
}

return parent;
Copy link
Collaborator

@SimoTod SimoTod Dec 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it should return parent since that one is not an added node and it would make the debugger print thr wrong statement. It should probably return null or another falsy value and the caller should handle it properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed, good catch. I've returned null from the function instead of parent and made the following changes to line 198 :

- let added = addNodeTo(currentTo, from)
+ let added = addNodeTo(currentTo, from) || {}

The variable added is only used for the debugger; and I'm assuming having a message of Add element: undefined is tolerable.

@VicGUTT
Copy link
Contributor Author

VicGUTT commented Feb 8, 2022

@SimoTod Thanks for the feedback. I have definitely not forgotten my PRs. This new year started with lot of life changing events on my end. That said, I should be back on this somewhere this week or at most early next week ✌️

@calebporzio
Copy link
Collaborator

Thanks @VicGUTT! And thanks for the feedback on this @SimoTod

@calebporzio calebporzio merged commit 9430be3 into alpinejs:main Mar 1, 2022
@calebporzio
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants