本文整理汇总了TypeScript中angular2/testing.setBaseTestProviders函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setBaseTestProviders函数的具体用法?TypeScript setBaseTestProviders怎么用?TypeScript setBaseTestProviders使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setBaseTestProviders函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('LoadingService', () => {
let tcb;
beforeEach(inject([TestComponentBuilder], _tcb => {
tcb = _tcb
}));
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
it('should generate a template for loading spinner', done => {
return tcb.createAsync(LoadingIndicator).then(fixture => {
let element = fixture.nativeElement;
fixture.detectChanges(); //trigger change detection
expect(element.querySelector('div')).not.toBeNull();
expect(element.querySelector('div').className).toBe('loading');
expect(element.querySelector('div').querySelector('div')).not.toBeNull();
expect(element.querySelector('div').querySelector('div').className).toBe('loading-message');
expect(element.querySelector('div').querySelector('div').querySelector('paper-spinner')).not.toBeNull();
removeLoading();
done();
})
.catch(e => done.fail(e));
});
});
开发者ID:shryme,项目名称:Angular2,代码行数:30,代码来源:loading.spec.ts
示例2: initialSetup
initialSetup(){
if(BasicTestSetup.isInitialized){
return;
}
BasicTestSetup.isInitialized = true;
// reflector.reflectionCapabilities = new ReflectionCapabilities();
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
// beforeEach configuration:
// - clear the bindings before each test,
// - collect the bindings before each test, see beforeEachProviders(),
// - create the test injector to be used in beforeEach() and it()
// gns.beforeEach(() {
// _testInjector.reset();
// _currentTestFuture = null;
// });
// var completerProvider = bind(AsyncTestCompleter).toFactory(() {
// // Mark the test as async when an AsyncTestCompleter is injected in an it(),
// if (!_inIt) throw 'AsyncTestCompleter can only be injected in an "it()"';
// _isCurrentTestAsync = true;
// return new AsyncTestCompleter();
// });
// gns.beforeEach(() {
// _isCurrentTestAsync = false;
// _testInjector.addProviders([completerProvider]);
// });
}
开发者ID:brajendraSwain,项目名称:angular2-shopingApp,代码行数:29,代码来源:basic_test_setup.ts
示例3: describe
describe('MyList Tests', () => {
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
beforeEachProviders(() => {
return [
HTTP_PROVIDERS,
provide(XHRBackend, {useClass: MockBackend}),
MyService
]
});
it('Should create a component MyList',
injectAsync([XHRBackend, MyService, TestComponentBuilder], (backend, service, tcb) => {
backend.connections.subscribe(
(connection:MockConnection) => {
var options = new ResponseOptions({
body: [
{
"login": "mojombo",
"id": 1,
"avatar_url": "https://avatars.githubusercontent.com/u/1?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/mojombo",
"html_url": "https://github.com/mojombo",
"followers_url": "https://api.github.com/users/mojombo/followers",
"following_url": "https://api.github.com/users/mojombo/following{/other_user}",
"gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mojombo/subscriptions",
"organizations_url": "https://api.github.com/users/mojombo/orgs",
"repos_url": "https://api.github.com/users/mojombo/repos",
"events_url": "https://api.github.com/users/mojombo/events{/privacy}",
"received_events_url": "https://api.github.com/users/mojombo/received_events",
"type": "User",
"site_admin": false
}
]
});
var response = new Response(options);
connection.mockRespond(response);
}
);
return tcb
.createAsync(TestMyList)
.then((fixture) => {
fixture.detectChanges();
var compiled = fixture.debugElement.nativeElement;
expect(compiled.innerHTML).toContain('Mojombo');
});
})
);
});
开发者ID:Erbolking,项目名称:angular2-testing,代码行数:56,代码来源:my-list.spec.ts
示例4: describe
describe('Employee Detail Tests', () => {
resetBaseTestProviders();
setBaseTestProviders(
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS
);
beforeEachProviders(() => {
return [
ROUTER_DIRECTIVES,
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
EmployeeDetailServiceComponent,
EmployeeDeleteServiceComponent,
provide(XHRBackend, {useClass: MockBackend}),
provide(APP_BASE_HREF, {useValue: '/'}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
provide(ApplicationRef, {useClass: MockApplicationRef}),
RouteRegistry,
provide(Location, {useClass: SpyLocation}),
provide(Router, {useClass: RootRouter}),
provide(RouteParams, { useValue: new RouteParams({ id: '1' }) })
]
});
it('Should display the list of employees',
injectAsync([XHRBackend, TestComponentBuilder], (backend, tcb) => {
backend.connections.subscribe(
(connection:MockConnection) => {
var options = new ResponseOptions({
body: {
"id": 1,
"name": "Roshan Shrestha"
}
});
var response = new Response(options);
connection.mockRespond(response);
}
);
return tcb
.createAsync(TestMyDetail)
.then((fixture) => {
fixture.detectChanges();
var compiled = fixture.nativeElement;
expect(compiled.innerHTML).toContain('Roshan Shrestha');
var src = (new BrowserDomAdapter()).getProperty(compiled.querySelector('a'), 'href');
// Employee link expectation
expect(src).toBe('http://localhost:9876/employee/1/edit');
});
})
);
});
开发者ID:abhinavmsra,项目名称:angular2,代码行数:56,代码来源:employee-detail.component.spec.ts
示例5: describe
describe('todo_component', () => {
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
beforeEachProviders(() => [provide(TodoService, {useClass: MockTodoService})]);
describe('creation', () => {
it('should create the component correctly', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TodoCmp).then((fixture) => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
expect(compiled).toBeDefined();
});
}));
it('should inicialize the cmp correctly', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TodoCmp).then((fixture) => {
let instance = fixture.debugElement.componentInstance;
spyOn(instance, '_getAll').and.callFake(() => {});
fixture.detectChanges();
expect(instance._getAll).toHaveBeenCalled();
});
}));
it('should call add correctly', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TodoCmp).then((fixture) => {
fixture.detectChanges();
let instance = fixture.debugElement.componentInstance;
let _todoMsg = 'yo';
instance.add(_todoMsg);
});
}));
it('should call remove correctly', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(TodoCmp).then((fixture) => {
fixture.detectChanges();
let instance = fixture.debugElement.componentInstance;
let _id = 'abc123';
instance.remove(_id);
});
}));
});
});
开发者ID:Kablex,项目名称:generator-ng-fullstack,代码行数:53,代码来源:todo-cmp_test.ts
示例6: describe
describe('Employee Edit Form Tests', () => {
resetBaseTestProviders();
setBaseTestProviders(
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS
);
beforeEachProviders(() => {
return [
ROUTER_DIRECTIVES,
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
EmployeeEditFormComponent,
EmployeeDetailServiceComponent,
EmployeeEditFormServiceComponent,
provide(XHRBackend, {useClass: MockBackend}),
provide(APP_BASE_HREF, {useValue: '/'}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
provide(ApplicationRef, {useClass: MockApplicationRef}),
RouteRegistry,
provide(Location, {useClass: SpyLocation}),
provide(Router, {useClass: RootRouter}),
provide(RouteParams, { useValue: new RouteParams({ id: '1' }) })
]
});
it('Should display the edit form of employees',
injectAsync([XHRBackend, TestComponentBuilder], (backend, tcb) => {
backend.connections.subscribe(
(connection:MockConnection) => {
var options = new ResponseOptions({
body: {
"id": 1,
"name": "Roshan Shrestha"
}
});
var response = new Response(options);
connection.mockRespond(response);
}
);
return tcb
.createAsync(TestMyEditForm)
.then((fixture) => {
fixture.detectChanges();
var compiled = fixture.nativeElement;
expect(compiled.innerHTML).toContain('Employee Edit Form');
});
})
);
});
开发者ID:abhinavmsra,项目名称:angular2,代码行数:52,代码来源:employee-edit-form.component.spec.ts
示例7: describe
describe('Threads page test', () => {
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
let component: ThreadListComponent;
var mockService: any;
var response: any;
beforeEach((done: Function) => {
response = jasmine.createSpyObj("response", ["json"]);
mockService = jasmine.createSpyObj("mockService", ["getService"]);
var json = { "_embedded": { "threads": [{ "id": 1, "countOfPosts": 1, "title": "Spring MVC form Validation: How to remove these lines from getting displayed", "_links": { "self": { "href": "http://localhost:8080/forum-spring-angular/rest/thread/1" } } }, { "id": 2, "countOfPosts": 1, "title": "Spring Data JPA aggregation group by period of time", "_links": { "self": { "href": "http://localhost:8080/forum-spring-angular/rest/thread/2" } } }, { "id": 3, "countOfPosts": 1, "title": "How to find all revisions for an entity using spring data envers?", "_links": { "self": { "href": "http://localhost:8080/forum-spring-angular/rest/thread/3" } } }] }, "_links": { "self": { "href": "http://localhost:8080/forum-spring-angular/rest/thread" } }, "page": { "size": 20, "totalElements": 5, "totalPages": 1, "number": 0 } };
response.json.and.returnValue(json);
mockService.getService.and.callFake(function(param: string) {
return new Promise(function(resolve, reject) { if (true) { resolve(response); } });
});
done();
});
beforeEachProviders(() => [
provide(RouteParams, { useValue: mockService }),
provide(RestService, { useValue: mockService })
]);
it('should be able to test', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(ThreadListComponent).then((fixture) => {
fixture.detectChanges();
expect(mockService.getService).toHaveBeenCalled();
return fixture;
}).then(fixture => {
expect(response.json).toHaveBeenCalled();
fixture.detectChanges();
var results = fixture.debugElement.nativeElement.querySelectorAll("div.wrap-ut");
expect(results.length).toBe(3);
expect(results[0].querySelector('link-to a').innerHTML).toBe('Spring MVC form Validation: How to remove these lines from getting displayed');
});
}));
it('Should capitalize all words in a string', () => {
var result = 'Golden Retriever';
expect(result).toEqual('Golden Retriever');
});
});
开发者ID:christos-karalis,项目名称:spring-angular2,代码行数:43,代码来源:app.directive.spec.ts
示例8: setBaseTestProviders
import { TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS} from 'angular2/platform/testing/browser';
import { setBaseTestProviders } from 'angular2/testing';
import { IonicApp, Platform, MenuController } from 'ionic-angular';
import { MyApp } from './app';
// this needs doing _once_ for the entire test suite, hence it's here
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
let redditApp : MyApp = null;
function getComponentStub(name: string): any {
'use strict';
let component: Object = {
setRoot: function(): boolean { return true; },
close: function(root: any): boolean { return true; },
};
return component;
}
export function main(): void {
'use strict';
describe('MyApp', () => {
beforeEach(() => {
let ionicApp: IonicApp = new IonicApp(null, null, null);
let platform: Platform = new Platform();
let menuController: MenuController = new MenuController();
redditApp = new MyApp(ionicApp, platform, menuController);
});
开发者ID:JDonadio,项目名称:recovery-tool-ionic2,代码行数:31,代码来源:app.spec.ts
示例9: setBaseTestProviders
import 'es6-shim';
import 'zone.js';
import 'reflect-metadata';
import {setBaseTestProviders} from 'angular2/testing';
import {TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS} from 'angular2/platform/testing/browser';
import {UrlResolver} from 'angular2/compiler';
import {provide} from 'angular2/core';
setBaseTestProviders(
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS.concat([
provide(UrlResolver, {useFactory: () => new FakeUrlResolver()})
])
);
class FakeUrlResolver extends UrlResolver {
constructor() {
super();
}
resolve(baseUrl: string, url: string): string {
// We do not attempt to load any CSS,
// as it is irrelevant during unit tests.
if (url.substr(-4) === '.css') {
return '';
}
return super.resolve(baseUrl, url);
}
}
开发者ID:virajs,项目名称:ng2-lab,代码行数:31,代码来源:setup.ts
示例10: beforeAll
beforeAll(() => {
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
});
开发者ID:jepetko,项目名称:mytunes,代码行数:3,代码来源:forRange.dir.spec.ts
注:本文中的angular2/testing.setBaseTestProviders函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论