ember-cli / ember-cli/eslint-plugin-ember

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

Open
#2,080 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
263
Forks
214
Avg merge
30m
Merged PRs (30d)
5

Description

I've seen some code that does:
```js
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
```js
class Replacement extends Foo {
get foo() {
assert.step('ran foo');
// optionally
return super.foo;
}
}
this.owner.register('service:foo', Replacement);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.