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

[FEAT] support this in integration tests #3

Open
IgnaceMaes opened this issue Nov 4, 2023 · 0 comments
Open

[FEAT] support this in integration tests #3

IgnaceMaes opened this issue Nov 4, 2023 · 0 comments

Comments

@IgnaceMaes
Copy link
Owner

IgnaceMaes commented Nov 4, 2023

I would like to see... πŸ™‹β€β™€οΈπŸ™‹β€β™‚οΈ

The codemod should support integration tests making use of the this context.

Why and how πŸ’¬

Iterate per test function in the file:

  • If no hbs helper, then skip
    • If a template is defined outside test body it's too hard to not break things as in hbs scope semantics are very different
  • Loop over all this. usages in the hbs template and list them
  • Loop over all this.set usages in the test and list them
  • If at least one property is set:
    • Create a new state object at the top of the test function
    • Before the render function, set initial state for every property
      • state.prop1 = this.prop1; ...
const state = new (class {
    @tracked prop1;
    @tracked prop2;
})();

short, but less readable?
OR bit more verbose, but nicer?

class State {
    @tracked prop1;
    @tracked prop2;
};
const state = new State();

OR, but this complicates the template transform as state.x needs a getter

const state = new TrackedMap();
  • If at least one property is accessed, but not set:
    • Before the render, create const context = this;
    • Or do const { X, Y } = this;
  • Rewrite the template this references to context or state
  • Rewrite the this.set expressions
    • to state.prop1 = ...
    • and await settled();
  • Import settled from @ember/test-helpers if needed

Additional context βž•

If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here.

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

No branches or pull requests

1 participant