Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Jul 26, 2021
1 parent dee47a1 commit bd3db85
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 293 deletions.
290 changes: 1 addition & 289 deletions packages/@ember/-internals/runtime/tests/system/object/create_test.js
Expand Up @@ -51,301 +51,13 @@ moduleFor(
let result;
expectDeprecation(
() => (result = obj.foo),
`A value was injected implicitly on the 'foo' property of an instance of ${inspect(
obj
)}. Implicit injection is now deprecated, please add an explicit injection for this value. If the injected value is a service, consider using the @service decorator.`
/owner.inject has been deprecated and will be removed in v5.0.0. Please refactor to explicitly instantiate _viewRegistry on renderer./
);

assert.equal(result.bar, 'foo');
assert.equal(obj.foo.bar, 'foo');
}

['@test implicit injections raises deprecation for old style EmberObject'](assert) {
let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
let FooObject = EmberObject.extend();
owner.register('service:foo', FooService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:foo');

let obj = owner.lookup('foo:main');
let result;
expectDeprecation(
() => (result = obj.foo),
`A value was injected implicitly on the 'foo' property of an instance of ${inspect(
obj
)}. Implicit injection is now deprecated, please add an explicit injection for this value. If the injected value is a service, consider using the @service decorator.`
);

assert.equal(result.bar, 'foo');
assert.equal(obj.foo.bar, 'foo');
}

['@test implicit injections does not raise a deprecation if explicit injection present'](
assert
) {
expectNoDeprecation();

let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class FooObject extends EmberObject {
@service foo;
}
owner.register('service:foo', FooService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:foo');

let obj = owner.lookup('foo:main');
assert.equal(obj.foo.bar, 'foo');
}

['@test raises deprecation if explicit injection is not the same as the implicit injection'](
assert
) {
let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
@service foo;
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:bar');

let result;
expectDeprecation(
() => (result = owner.lookup('foo:main')),
/You have explicitly defined a service injection for the 'foo' property on <.*>. However, a different service or value was injected via implicit injections which overrode your explicit injection. Implicit injections have been deprecated, and will be removed in the near future. In order to prevent breakage, you should inject the same value explicitly that is currently being injected implicitly./
);
assert.equal(result.foo.bar, 'bar');
}

['@test does not raise deprecation if descriptor is a value and equal to the implicit deprecation'](
assert
) {
expectNoDeprecation();

let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
foo = getOwner(this).lookup('service:foo');
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:foo');

let result = owner.lookup('foo:main');
assert.equal(result.foo.bar, 'foo');
}

['@test does raise deprecation if descriptor is a value and not equal to the implicit deprecation'](
assert
) {
let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
foo = getOwner(this).lookup('service:foo');
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:bar');

expectDeprecation(() => {
let result = owner.lookup('foo:main');
assert.equal(result.foo.bar, 'bar');
}, /A value was injected implicitly on the 'foo' property of an instance of <.*>, overwriting the original value which was <.*>. Implicit injection is now deprecated, please add an explicit injection for this value/);
}

['@test does not raise deprecation if descriptor is a tracked property and equal to the implicit deprecation'](
assert
) {
expectNoDeprecation();

let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
@tracked foo = getOwner(this).lookup('service:foo');
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:foo');

let result = owner.lookup('foo:main');
assert.equal(result.foo.bar, 'foo');
}

['@test does raise deprecation if descriptor is a tracked property and not equal to the implicit deprecation'](
assert
) {
let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
@tracked foo = getOwner(this).lookup('service:foo');
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:bar');

expectDeprecation(() => {
let result = owner.lookup('foo:main');
assert.equal(result.foo.bar, 'bar');
}, /A value was injected implicitly on the 'foo' tracked property of an instance of <.*>, overwriting the original value which was <.*>. Implicit injection is now deprecated, please add an explicit injection for this value/);
}

['@test does not raise deprecation if descriptor is a computed property with a setter'](
assert
) {
expectNoDeprecation();

let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
@computed
get foo() {
return getOwner(this).lookup('service:foo');
}

set foo(val) {}
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:foo');

let result = owner.lookup('foo:main');
assert.equal(result.foo.bar, 'foo');
}

['@test does raise assertion if descriptor is a computed property without a setter']() {
let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
@computed
get foo() {
return getOwner(this).lookup('service:foo');
}
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:bar');

expectAssertion(() => {
expectDeprecation(
/A value was injected implicitly on the 'foo' computed property of an instance of <.*>. Implicit injection is now deprecated, please add an explicit injection for this value/
);
owner.lookup('foo:main');
}, /Cannot override the computed property `foo` on <.*>./);
}

['@test does not raise deprecation if descriptor is a getter and equal to the implicit deprecation'](
assert
) {
expectNoDeprecation();

let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
get foo() {
return getOwner(this).lookup('service:foo');
}

set foo(_) {}
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:foo');

let result = owner.lookup('foo:main');
assert.equal(result.foo.bar, 'foo');
}

['@test does not raise deprecation if descriptor is a getter and not equal to the implicit deprecation'](
assert
) {
let owner = buildOwner();

class FooService extends Service {
bar = 'foo';
}
class BarService extends Service {
bar = 'bar';
}
class FooObject extends EmberObject {
get foo() {
return getOwner(this).lookup('service:foo');
}

set foo(_) {}
}
owner.register('service:foo', FooService);
owner.register('service:bar', BarService);
owner.register('foo:main', FooObject);
owner.inject('foo:main', 'foo', 'service:bar');

let result = owner.lookup('foo:main');
assert.equal(result.foo.bar, 'foo');
}

['@test calls computed property setters'](assert) {
let MyClass = EmberObject.extend({
foo: computed({
Expand Down
Expand Up @@ -73,10 +73,6 @@ moduleFor(
}

['@test injections'](assert) {
expectDeprecation(
/A value was injected implicitly on the 'fruit' property of an instance of <.*>. Implicit injection is now deprecated, please add an explicit injection for this value/
);

application.inject('model', 'fruit', 'fruit:favorite');
application.inject('model:user', 'communication', 'communication:main');

Expand Down

0 comments on commit bd3db85

Please sign in to comment.