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

New rule: prevent assignment of existing properties on a service (important for tests) #2080

Open
NullVoxPopuli opened this issue Jan 31, 2024 · 0 comments

Comments

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Jan 31, 2024

I've seen some code that does:

let service = this.owner.lookup('service:foo');

service.setProperties({ 
  replacement properties and methods
});
// or
service.foo = replacement
// or
Ember.set(service, 'foo', replacement)

we should lint against this, because it can cause sutle bugs.

Additionally, you end up testing your replacements, rather than the service itself.

If someone wants to

  • override network stuff
    • use MSW or similar (let the fetch happen)
  • override some method that uses an external library
    • couple options:
      • let it happen, assert your full integration of the tools
      • extend the service
        class Replacement extends Foo {
          get foo() {
            assert.step('ran foo');
            // optionally
            return super.foo;
          }
        }
        this.owner.register('service:foo', Replacement);
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