本文整理匯總了TypeScript中@angular/core/testing.TestBed.resetTestEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TestBed.resetTestEnvironment方法的具體用法?TypeScript TestBed.resetTestEnvironment怎麽用?TypeScript TestBed.resetTestEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/core/testing.TestBed
的用法示例。
在下文中一共展示了TestBed.resetTestEnvironment方法的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: 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 };
}
示例3: platformBrowserDynamicTesting
const testModuleConfig = () => {
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting())
.configureTestingModule({
imports: [
CoreModule.forRoot([
{
provide: ConfigLoader,
useFactory: configFactory,
deps: [
PLATFORM_ID,
HttpClient
]
}
]),
CoreTestingModule
]
});
};
示例4: afterAll
afterAll(() => {
TestBed.resetTestEnvironment();
});
示例5: resetTestEnvironmentWithSummaries
function resetTestEnvironmentWithSummaries(summaries?: () => any[]) {
const {platform, ngModule} = getTestBed();
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(ngModule, platform, summaries);
}
示例6: 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);
示例7: beforeAll
beforeAll( () => {
TestBed.resetTestEnvironment()
TestBed.initTestEnvironment( BrowserDynamicTestingModule, platformBrowserDynamicTesting() )
})
示例8: platformBrowserDynamicTesting
/// <reference path="../../node_modules/@types/jasmine/index.d.ts" />
import { AppComponent } from '../App/app.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
// The following initializes the test environment for Angular 2. This call is required for Angular 2 dependency injection.
// That's new in Angular 2 RC5
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
describe("AppComponent -> ", () => {
let de: DebugElement;
let comp: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
示例9: MockStore
scenarios.forEach((scenario) => {
TestBed.resetTestEnvironment();
describe(scenario.name, () => {
// create a new backing store for each call. Otherwise all tests will share the same backing.
const createBacking = () => {
return new MockStore({
baseKey1: '"value1"',
baseKey2: '"value2"',
'prefix-Key1': '"value3"',
'prefix-Key2': '"value4"'
});
};
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
MockStorage,
{ provide: MockStore, useValue: createBacking() },
{ provide: MockOptions, useValue: scenario.options },
MockSerdes
]
});
mockStorage = TestBed.get(MockStorage);
mockStore = TestBed.get(MockStore);
});
it('should load all keys from storage', () => {
expect(mockStorage.length).toBe(scenario.totalKeys);
});
it('can delete a key with delete keyword', () => {
delete mockStorage[scenario.keyName];
mockStorage.detectChanges();
expect(mockStore[scenario.options.prefix + scenario.keyName]).not.toBeDefined();
});
it('can delete a key with removeItem', () => {
mockStorage.removeItem(scenario.keyName);
mockStorage.detectChanges();
expect(mockStore[scenario.options.prefix + scenario.keyName]).not.toBeDefined();
});
it('can clear all keys', () => {
const totalStored = mockStore.length;
expect(mockStorage.length).toBe(scenario.totalKeys);
mockStorage.clear();
mockStorage.detectChanges();
const found = Object.keys(mockStore).some((key) => key.startsWith(scenario.options.prefix));
expect(found).toBe(false);
expect(mockStore.length).toBe(totalStored - scenario.totalKeys);
});
it('can create a key', () => {
expect(mockStore[scenario.options.prefix + 'brandNewKey']).not.toBeDefined();
mockStorage['brandNewKey'] = { valueType: 'complex' };
mockStorage.detectChanges();
expect(mockStore[scenario.options.prefix + 'brandNewKey']).toBeDefined();
});
it('can create a key with setItem', () => {
expect(mockStore[scenario.options.prefix + 'brandNewKey']).not.toBeDefined();
mockStorage.setItem('brandNewKey', 'simple');
mockStorage.detectChanges();
expect(mockStore[scenario.options.prefix + 'brandNewKey']).toBeDefined();
});
it('will pass-thru pre-stringified objects', () => {
const value = JSON.stringify({ valueType: 'complex' });
mockStorage.setItem('brandNewKey', value);
mockStorage.detectChanges();
expect(mockStore[scenario.options.prefix + 'brandNewKey']).toBe(value);
});
it('can retieve a value', () => {
const expected = JSON.parse(mockStore[scenario.options.prefix + scenario.keyName]);
expect(mockStorage[scenario.keyName]).toBe(expected);
});
it('can retireve a key with getItem', () => {
const expected = JSON.parse(mockStore[scenario.options.prefix + scenario.keyName]);
expect(mockStorage.getItem(scenario.keyName)).toBe(expected);
});
it('can retireve a key', () => {
expect(mockStorage.key(scenario.keyIndex)).toBe(scenario.keyName);
});
it('can update a value', () => {
mockStorage[scenario.keyName] = { valueType: 'complex' };
mockStorage.detectChanges();
expect(mockStore[scenario.options.prefix + scenario.keyName]).toBe(JSON.stringify({ valueType: 'complex' }));
});
it('will sync on storage event', () => {
expect(mockStorage['otherKey']).not.toBeDefined();
mockStore[scenario.options.prefix + 'otherKey'] = '"newValue"';
mockStorage
.createStorageEvent()
.detectChanges();
//.........這裏部分代碼省略.........
示例10: afterEach
afterEach(() => { TestBed.resetTestEnvironment(); });