本文整理汇总了TypeScript中@angular/core/testing.TestBed.initTestEnvironment方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TestBed.initTestEnvironment方法的具体用法?TypeScript TestBed.initTestEnvironment怎么用?TypeScript TestBed.initTestEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/core/testing.TestBed
的用法示例。
在下文中一共展示了TestBed.initTestEnvironment方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: platformBrowserDynamicTesting
const testModuleConfig = () => {
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting())
.configureTestingModule({
imports: [
RouterTestingModule,
StoreModule.forFeature('i18n', reducers),
EffectsModule.forFeature([LanguageEffects]),
CoreModule.forRoot([
{
provide: ConfigLoader,
useFactory: configFactory,
deps: [
PLATFORM_ID,
HttpClient
]
}
]),
CoreTestingModule,
NgrxTestingModule,
AnalyticsModule,
I18NTestingModule
],
providers: [
LanguageEffects
]
});
};
示例2: describe
describe('FeedsListComponent', () => {
TestBed.initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
beforeEach(() => {
TestBed.configureTestingModule({
imports: [MockRoutes],
declarations: [FeedsListComponent, FeedsComponent, EllipsisAfterPipe, RouterTestingComponent],
providers: [
{ provide: FeedsService, useClass: MockFeedsService }
]
});
});
it('can fetch the feeds list', async(() => {
return TestBed
.compileComponents().then(() => {
let componentFixture = TestBed.createComponent(FeedsListComponent);
let element = componentFixture.nativeElement;
componentFixture.detectChanges();
expect(componentFixture.componentInstance.feeds.length).toBe(1);
expect(componentFixture.componentInstance.feeds[0].title).toBe('Post 1');
});
}));
});
示例3: describe
describe('EllipsisAfterPipe', () => {
let ellipsisAfterPipe: EllipsisAfterPipe;
TestBed.initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [EllipsisAfterPipe]
});
});
beforeEach(() => {
ellipsisAfterPipe = new EllipsisAfterPipe();
});
it('should create the EllipsisAfterPipe', () => {
expect(ellipsisAfterPipe).toBeTruthy();
});
it('can obtain same string incase its length is less than the limit', () => {
expect(ellipsisAfterPipe.transform('abc', 10)).toEqual('abc');
});
it('can add ellipsis after the specified limit', () => {
expect(ellipsisAfterPipe.transform('abcdefghijklmnopqrstuvwxyz', 10)).toEqual('abcdefghij ...');
});
});
示例4: platformBrowserDynamicTesting
export function setup<T>(moduleType: Type<T>, options: { storedValue?: any } = {}) {
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
const bootstrap: BootstrapModuleFn<T> = () =>
getTestBed().platform.bootstrapModule(moduleType);
const storedValue = options.storedValue;
const storageValue = options.storedValue ? JSON.stringify(storedValue) : '';
sessionStorage.setItem(NGXS_HMR_SNAPSHOT_KEY, storageValue);
MockState.clear();
return { bootstrap };
}
示例5: analyzeAppProvidersForDeprecatedConfiguration
[(appProviders: any[]) => {
const deprecatedConfiguration = analyzeAppProvidersForDeprecatedConfiguration(appProviders);
const platformRef = createPlatformFactory(platformServerTesting, 'serverTestingDeprecated', [{
provide: COMPILER_OPTIONS,
useValue: deprecatedConfiguration.compilerOptions,
multi: true
}])();
@NgModule({
exports: [ServerTestingModule],
declarations: [deprecatedConfiguration.moduleDeclarations]
})
class DynamicTestModule {
}
const testInjector = TestBed.initTestEnvironment(DynamicTestModule, platformRef);
const console: Console = testInjector.get(Console);
deprecatedConfiguration.deprecationMessages.forEach((msg) => console.warn(msg));
}];
示例6: platformBrowserDynamicTesting
const testModuleConfig = () => {
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting())
.configureTestingModule({
imports: [
CoreModule.forRoot([
{
provide: ConfigLoader,
useFactory: configFactory,
deps: [
PLATFORM_ID,
HttpClient
]
}
]),
CoreTestingModule
]
});
};
示例7: task
task('test:ssr', [':test:build'], (done: () => void) => {
const baseUrl = join(projectDir, 'dist', 'packages', 'flex-layout');
const paths = {
'@angular/flex-layout/*': ['./*']
};
register({baseUrl, paths});
const jasmine = new (require('jasmine'))({projectBaseDir: projectDir});
require('zone.js');
require('zone.js/dist/zone-testing');
const {TestBed} = require('@angular/core/testing');
const {ServerTestingModule, platformServerTesting} = require('@angular/platform-server/testing');
let testBed = TestBed.initTestEnvironment(
ServerTestingModule,
platformServerTesting()
);
patchTestBed(testBed);
jasmine.loadConfigFile('test/jasmine-ssr.json');
jasmine.execute();
done();
});
示例8: describe
describe('ContactComponent', () => {
TestBed.initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ContactComponent]
});
});
it('should create the component and display a message', async(() => {
return TestBed
.compileComponents().then(() => {
let componentFixture = TestBed.createComponent(ContactComponent);
let element = componentFixture.nativeElement;
let componentInstance = componentFixture.componentInstance;
componentFixture.detectChanges();
expect(element).toBeTruthy();
expect(componentInstance.message).toEqual('Contact me on chnvrm@gmail.com');
});
}));
});
示例9: describe
describe('FeedsService', () => {
TestBed.initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
BaseRequestOptions,
MockBackend,
FeedsService,
{
provide: Http, useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backend, defaultOptions);
}, deps: [MockBackend, BaseRequestOptions]
},
]
});
});
it('can retrive feeds', inject([FeedsService, MockBackend],
fakeAsync((feedsService: FeedsService, mockBackend: MockBackend) => {
let result: IFeed[];
mockBackend.connections.subscribe((connection: any) => {
expect(connection.request.url).toBe('./data/feeds.json');
let response = new ResponseOptions({
body: [{
'id': 'fid1',
'title': 'Post 1',
'description': 'Post Description 1'
}]
});
connection.mockRespond(new Response(response));
});
feedsService.getFeeds().subscribe((response) => {
result = response;
});
tick();
expect(result[0].id).toBe('fid1');
expect(result[0].title).toBe('Post 1');
expect(result[0].description).toBe('Post Description 1');
})
));
it('can retrive the feed using feed id', inject([FeedsService, MockBackend],
fakeAsync((feedsService: FeedsService, mockBackend: MockBackend) => {
let result: IFeed;
mockBackend.connections.subscribe((connection: any) => {
expect(connection.request.url).toBe('./data/feeds.json');
let response = new ResponseOptions({
body: [{
'id': 'fid1',
'title': 'Post 1',
'description': 'Post Description 1'
}, {
'id': 'fid2',
'title': 'Post 2',
'description': 'Post Description 2'
}]
});
connection.mockRespond(new Response(response));
});
feedsService.getFeed('fid2').subscribe((response) => {
result = response;
});
tick();
expect(result.id).toBe('fid2');
expect(result.title).toBe('Post 2');
expect(result.description).toBe('Post Description 2');
})
));
});
示例10: require
* This software is released under MIT license.
* The full license information can be found in LICENSE in the root directory of this project.
*/
import "core-js";
import "core-js/es7/reflect";
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/async-test";
import "zone.js/dist/fake-async-test";
import "zone.js/dist/sync-test";
import "zone.js/dist/proxy";
import "zone.js/dist/jasmine-patch";
import JasmineExpect from "jasmine-expect";
/* tslint:disable no-var-requires no-require-imports */
const browserTesting = require("@angular/platform-browser-dynamic/testing");
const coreTesting = require("@angular/core/testing");
// include every .spec.ts file inside src, except for those in ks-app folder
const context = (require as any).context("../src/", true, /^((?![\\/]ks-app[\\/]).)*\.spec\.ts$/);
/* tslint:enable no-var-requires no-require-imports*/
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
coreTesting.TestBed.resetTestEnvironment();
coreTesting.TestBed.initTestEnvironment(browserTesting.BrowserDynamicTestingModule,
browserTesting.platformBrowserDynamicTesting());
context.keys().forEach(context);