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

Split up and expressions #217

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

guidobouman
Copy link

@guidobouman guidobouman commented Jun 9, 2021

Work in progress

Fixes #171

@guidobouman
Copy link
Author

guidobouman commented Jun 9, 2021

@skovhus I'm having a little trouble with insertAfter. Any quick tips?

The callExpressions are now all nested. 😅

- Expected  - 3
+ Received  + 1-         expect(true).toBe(true);
-         expect(true).not.toBe(false);
-         expect(true).not.toBe(1);
+         expect(expect(expect(true).to.be.true).not.toBe(false)).not.toBe(1);```

Copy link
Owner

@skovhus skovhus left a comment

Choose a reason for hiding this comment

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

This is a tricky one! Thanks for trying to fix it. What helps a lot is using astexplorer to play around with the tree interactively.

In your case, I suggest you to to make splitAndExpressions turn expect(true).to.be.true.and.to.not.be.false.and.to.not.equal(1); into:

expect(true).to.be.true;
expect(true).to.not.be.false;
expect(true).to.not.equal(1);

Then the other transformers should be able to handle the rest.

@guidobouman
Copy link
Author

Thanks for pointing me towards astexplorer! Yes, it was my goal to only do the splitting, and let the other transform methods take care of the rest.

@guidobouman
Copy link
Author

So I have just the topmost call expression by going down the tree. But I have a hard time inserting a new line before or after. I have the feeling that I should approach this based on the expression statements, and then check if an .and member expression can be found. Instead of diving into the member expressions directly.

https://astexplorer.net/#/gist/94bb17954e956f7553a9ab05e016912d/600b4deb0d92a5489fece6ce70dcd71219b3edb5

Do you think that would be a better approach?

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.

Chai-expect conversion failing for and method
2 participants