
committed by
Miško Hevery

parent
00c110b055
commit
809e8f742e
@ -217,7 +217,7 @@ function factoryFn(a: any){}
|
||||
const injector = Injector.create([CarWithOptionalEngine.PROVIDER]);
|
||||
|
||||
const car = injector.get<CarWithOptionalEngine>(CarWithOptionalEngine);
|
||||
expect(car.engine).toEqual(null);
|
||||
expect(car.engine).toBeNull();
|
||||
});
|
||||
|
||||
it('should flatten passed-in providers', () => {
|
||||
@ -288,8 +288,8 @@ function factoryFn(a: any){}
|
||||
Injector.create([CarWithDashboard.PROVIDER, Engine.PROVIDER, Dashboard.PROVIDER]);
|
||||
expect(() => injector.get(CarWithDashboard))
|
||||
.toThrowError(
|
||||
`StaticInjectorError[${stringify(CarWithDashboard)} -> ${stringify(Dashboard)} -> DashboardSoftware]:
|
||||
NullInjectorError: No provider for DashboardSoftware!`);
|
||||
`StaticInjectorError[${stringify(CarWithDashboard)} -> ${stringify(Dashboard)} -> DashboardSoftware]: \n` +
|
||||
' NullInjectorError: No provider for DashboardSoftware!');
|
||||
});
|
||||
|
||||
it('should throw when trying to instantiate a cyclic dependency', () => {
|
||||
@ -415,8 +415,9 @@ function factoryFn(a: any){}
|
||||
parent);
|
||||
|
||||
expect(() => child.get(Car))
|
||||
.toThrowError(`StaticInjectorError[${stringify(Car)} -> ${stringify(Engine)}]:
|
||||
NullInjectorError: No provider for Engine!`);
|
||||
.toThrowError(
|
||||
`StaticInjectorError[${stringify(Car)} -> ${stringify(Engine)}]: \n` +
|
||||
' NullInjectorError: No provider for Engine!');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -343,7 +343,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const tc = fixture.debugElement.children[0];
|
||||
expect(tc.injector.get(EventDir)).not.toBe(null);
|
||||
expect(tc.injector.get(EventDir)).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should read directives metadata from their binding token', () => {
|
||||
@ -1237,7 +1237,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
const needsAttribute = tc.injector.get(NeedsAttribute);
|
||||
expect(needsAttribute.typeAttribute).toEqual('text');
|
||||
expect(needsAttribute.staticAttribute).toEqual('');
|
||||
expect(needsAttribute.fooAttribute).toEqual(null);
|
||||
expect(needsAttribute.fooAttribute).toBeNull();
|
||||
});
|
||||
|
||||
it('should support custom interpolation', () => {
|
||||
|
@ -33,37 +33,27 @@ class TurboEngine extends Engine {}
|
||||
const CARS = new InjectionToken<Car[]>('Cars');
|
||||
@Injectable()
|
||||
class Car {
|
||||
engine: Engine;
|
||||
constructor(engine: Engine) { this.engine = engine; }
|
||||
constructor(public engine: Engine) {}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class CarWithOptionalEngine {
|
||||
engine: Engine;
|
||||
constructor(@Optional() engine: Engine) { this.engine = engine; }
|
||||
constructor(@Optional() public engine: Engine) {}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class CarWithDashboard {
|
||||
engine: Engine;
|
||||
dashboard: Dashboard;
|
||||
constructor(engine: Engine, dashboard: Dashboard) {
|
||||
this.engine = engine;
|
||||
this.dashboard = dashboard;
|
||||
}
|
||||
constructor(public engine: Engine, public dashboard: Dashboard) {}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class SportsCar extends Car {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
engine !: Engine;
|
||||
constructor(engine: Engine) { super(engine); }
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class CarWithInject {
|
||||
engine: Engine;
|
||||
constructor(@Inject(TurboEngine) engine: Engine) { this.engine = engine; }
|
||||
constructor(@Inject(TurboEngine) public engine: Engine) {}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@ -747,7 +737,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
const injector = createInjector([CarWithOptionalEngine]);
|
||||
|
||||
const car = injector.get(CarWithOptionalEngine);
|
||||
expect(car.engine).toEqual(null);
|
||||
expect(car.engine).toBeNull();
|
||||
});
|
||||
|
||||
it('should flatten passed-in providers', () => {
|
||||
|
@ -659,7 +659,7 @@ class TestComp {
|
||||
TestBed.configureTestingModule({declarations: [OptionallyNeedsDirective]});
|
||||
const el = createComponent('<div optionallyNeedsDirective></div>');
|
||||
const d = el.children[0].injector.get(OptionallyNeedsDirective);
|
||||
expect(d.dependency).toEqual(null);
|
||||
expect(d.dependency).toBeNull();
|
||||
});
|
||||
|
||||
it('should instantiate directives that depends on the host component', () => {
|
||||
|
Reference in New Issue
Block a user