本文整理匯總了TypeScript中@angular/core/testing.setBaseTestProviders函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript setBaseTestProviders函數的具體用法?TypeScript setBaseTestProviders怎麽用?TypeScript setBaseTestProviders使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了setBaseTestProviders函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('PersonsDetailsComponent', () => {
if( !getTestInjector().platformProviders.length )
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS)
let fixture: ComponentFixture<PersonsDetailsComponent>
beforeEachProviders(() => [
TestComponentBuilder,
provide(Http, {useValue: {}})
])
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PersonsDetailsComponent)
.then(rootFixture => fixture = rootFixture)
}))
it('must be a list of persons list', () => {
let component = fixture.componentInstance
let element = fixture.nativeElement
fixture.detectChanges()
expect(element.querySelectorAll('li').length).toBe(5)
expect(element.querySelector('li').innerText).toBe('Max Smith')
})
})
示例2: describe
describe('GreeterComponent', () => {
if( !getTestInjector().platformProviders.length )
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS)
it('must be "Phone Book App"',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(GreeterComponent)
.then((fixture: ComponentFixture<GreeterComponent>) => {
let element = fixture.nativeElement
fixture.detectChanges()
expect(element.querySelectorAll('h1').length).toBe(1);
expect(element.querySelector('h1').innerText).toBe('Phone Book App');
})
}))
)
})
示例3: describe
describe('Router tests', () => {
if( !getTestInjector().platformProviders.length )
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS)
let router: Router
let spylocation: SpyLocation
//setup
beforeEach(() => {
addProviders([
RouteRegistry,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
provide(Location, {useClass: SpyLocation}),
provide(Router, {useClass: RootRouter}),
])
})
beforeEach(inject([Router, Location], (r, l) => {
router = r
spylocation = l
}))
//specs
it('Should be able to navigate to Home', done => {
router.navigate(['PersonList']).then(() => {
expect(spylocation.path()).toBe('')
done()
}).catch(e => done.fail(e))
})
it('should redirect not registered urls to Home', done => {
router.navigateByUrl('/unknown').then(() => {
expect(spylocation.path()).toBe('')
done()
}).catch(e => done.fail(e))
})
it('Should be able to navigate to About', done => {
router.navigate(['About']).then(() => {
expect(spylocation.path()).toBe('/about')
done()
}).catch(e => done.fail(e))
})
})
示例4: setBaseTestProviders
/**
* Created by najorcruzcruz on 14/7/16.
*/
import { setBaseTestProviders } from "@angular/core/testing";
import {
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS,
TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
} from '@angular/platform-browser-dynamic/testing';
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
declare var ARCGIS_MODULE: any;
beforeAll(() => {
ARCGIS_MODULE.getAddress = () => {
return new Promise((fulfill, reject) => {
fulfill({
address: {
Match_addr: 'Super calle callejon'
},
location: {
latitude: -20.23,
longitude: 12.003
}
});
})
};
});
示例5: resetBaseTestProviders
import {BROWSER_APP_DYNAMIC_PROVIDERS} from "@angular/platform-browser-dynamic";
import {
TEST_BROWSER_STATIC_PLATFORM_PROVIDERS,
ADDITIONAL_TEST_BROWSER_PROVIDERS
} from "@angular/platform-browser/testing";
import {MATERIAL_BROWSER_PROVIDERS} from "../../index";
import {TestUrlResolver} from "./test_url_resolver";
import {UrlResolver} from "@angular/compiler";
import {provide, ApplicationRef} from "@angular/core";
resetBaseTestProviders();
setBaseTestProviders(
TEST_BROWSER_STATIC_PLATFORM_PROVIDERS,
[
...BROWSER_APP_DYNAMIC_PROVIDERS,
...ADDITIONAL_TEST_BROWSER_PROVIDERS,
...MATERIAL_BROWSER_PROVIDERS,
provide(ApplicationRef, {useClass: MockApplicationRef}),
provide(UrlResolver, {useValue: new TestUrlResolver()})
]
);
function onlySpecFiles(path) {
return /_spec\.js$/.test(path);
}
export function load(files: string[]): Promise<any[]> {
console.log('importing test modules: ');
let error = (e: any) => {
console.error(e);
};
var myZone = new Zone();
示例6: setBaseTestProviders
'use strict';
import {setBaseTestProviders} from '@angular/core/testing';
import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter';
import { OptionsService, RedocEventsService, Hash, ScrollService, MenuService } from '../lib/services/index';
import { SpecManager } from '../lib/utils/SpecManager';
import { provide } from '@angular/core';
import {
TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
} from '@angular/platform-browser-dynamic/testing';
setBaseTestProviders(
[
TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
provide(OptionsService, {useClass: OptionsService}),
provide(RedocEventsService, {useClass: RedocEventsService}),
provide(SpecManager, {useClass: SpecManager}),
provide(Hash, {useClass: Hash}),
provide(ScrollService, {useClass: ScrollService}),
provide(MenuService, {useClass: MenuService})
],
[TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS]);
示例7: resetBaseTestProviders
declare var Zone: any;
import {resetBaseTestProviders, setBaseTestProviders} from "@angular/core/testing";
import {BROWSER_APP_COMPILER_PROVIDERS} from "@angular/platform-browser-dynamic";
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from "@angular/platform-browser-dynamic/testing";
import {MATERIAL_BROWSER_PROVIDERS} from "../../index";
import {TestUrlResolver} from "./test_url_resolver";
import {UrlResolver} from "@angular/compiler";
resetBaseTestProviders();
setBaseTestProviders(
TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
[
...BROWSER_APP_COMPILER_PROVIDERS,
...TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS,
...MATERIAL_BROWSER_PROVIDERS,
{provide: UrlResolver, useValue: new TestUrlResolver()}
]
);
function onlySpecFiles(path) {
return /_spec\.js$/.test(path);
}
export function load(files: string[]): Promise<any[]> {
console.log('importing test modules: ');
let error = (e: any) => {
console.error(e);
};
var myZone = new Zone();
示例8: beforeEach
beforeEach(() => {
resetBaseTestProviders();
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
addProviders([ChessService, TestComponentBuilder]);
});
示例9: setBaseTestProviders
/// <reference path="../../../typings/index.d.ts"/>
import 'zone.js/dist/zone';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import {todos, visibility} from './todos';
import * as types from '../constants/ActionTypes';
import * as filters from '../constants/TodoFilters';
import {describe, it, expect, setBaseTestProviders} from '@angular/core/testing';
import {TEST_BROWSER_STATIC_PLATFORM_PROVIDERS, ADDITIONAL_TEST_BROWSER_PROVIDERS} from '@angular/platform-browser/testing';
import {BROWSER_APP_DYNAMIC_PROVIDERS} from '@angular/platform-browser-dynamic';
setBaseTestProviders(
TEST_BROWSER_STATIC_PLATFORM_PROVIDERS,
[
BROWSER_APP_DYNAMIC_PROVIDERS,
ADDITIONAL_TEST_BROWSER_PROVIDERS
]
);
describe('Reducers', () => {
describe('todo reducer', () => {
it('should handle initial state', () => {
expect(todos(undefined, {})).toEqual([
{
text: 'Use ngrx/store',
completed: false,
id: 0
}
]);
});
it('should handle ADD_TODO', () => {
示例10: setBaseTestProviders
@Component({
selector: 'game-board',
template: ''
})
class MockGameBoard {}
@Component({
selector: 'footer',
template: ''
})
class MockFooter {}
setBaseTestProviders(
TEST_BROWSER_STATIC_PLATFORM_PROVIDERS,
[
BROWSER_APP_DYNAMIC_PROVIDERS,
ADDITIONAL_TEST_BROWSER_PROVIDERS,
HTTP_PROVIDERS,
MdIconRegistry,
GameService
]
);
describe('app component', () => {
it('should render the tool-bar, game-board and footer', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb
.overrideDirective(AppComponent, ToolBarComponent, MockToolBar)
.overrideDirective(AppComponent, GameBoardComponent, MockGameBoard)
.overrideDirective(AppComponent, FooterComponent, MockFooter)
.createAsync(AppComponent)
.then(fixture => {
fixture.detectChanges();
const main = fixture.nativeElement;
expect(main.querySelector('ToolBarComponent')).toBeDefined();