parent
fd8e15b15d
commit
169ed82900
|
@ -135,6 +135,11 @@ export class TestBed implements Injector {
|
|||
return TestBed;
|
||||
}
|
||||
|
||||
static overrideTemplate(component: Type<any>, template: string): typeof TestBed {
|
||||
getTestBed().overrideComponent(component, {set: {template, templateUrl: null}});
|
||||
return TestBed;
|
||||
}
|
||||
|
||||
static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) {
|
||||
return getTestBed().get(token, notFoundValue);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import {CompilerConfig, ResourceLoader} from '@angular/compiler';
|
||||
import {CUSTOM_ELEMENTS_SCHEMA, Component, Directive, Injectable, Input, NgModule, Pipe} from '@angular/core';
|
||||
import {TestBed, async, fakeAsync, inject, tick, withModule} from '@angular/core/testing';
|
||||
import {TestBed, async, fakeAsync, getTestBed, inject, tick, withModule} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {stringify} from '../src/facade/lang';
|
||||
|
@ -356,6 +356,21 @@ export function main() {
|
|||
expect(compFixture.nativeElement).toHaveText('transformed hello');
|
||||
});
|
||||
});
|
||||
|
||||
describe('template', () => {
|
||||
let testBedSpy: any;
|
||||
beforeEach(() => {
|
||||
testBedSpy = spyOn(getTestBed(), 'overrideComponent').and.callThrough();
|
||||
TestBed.overrideTemplate(SomeComponent, 'newText');
|
||||
});
|
||||
it(`should override component's template`, () => {
|
||||
const fixture = TestBed.createComponent(SomeComponent);
|
||||
expect(fixture.nativeElement).toHaveText('newText');
|
||||
expect(testBedSpy).toHaveBeenCalledWith(SomeComponent, {
|
||||
set: {template: 'newText', templateUrl: null}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('setting up the compiler', () => {
|
||||
|
|
|
@ -89,6 +89,7 @@ export declare class TestBed implements Injector {
|
|||
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBed;
|
||||
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed;
|
||||
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBed;
|
||||
static overrideTemplate(component: Type<any>, template: string): typeof TestBed;
|
||||
/** @experimental */ static resetTestEnvironment(): void;
|
||||
static resetTestingModule(): typeof TestBed;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue