本文整理汇总了TypeScript中@angular/core/testing.describe函数的典型用法代码示例。如果您正苦于以下问题:TypeScript describe函数的具体用法?TypeScript describe怎么用?TypeScript describe使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了describe函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
/* tslint:disable:no-unused-variable */
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import {
beforeEach, beforeEachProviders,
describe, xdescribe,
expect, it, xit,
async, inject
} from '@angular/core/testing';
import { EventListComponent } from './event-list.component';
import { EventService } from './../event.service';
describe('Component: EventList', () => {
it('should create an instance', () => {
let component = new EventListComponent(new EventService());
expect(component).toBeTruthy();
});
});
示例2: describe
describe('user service', () => {
beforeEachProviders(() => [LoginService, UserService]);
it('should validate pins', inject([UserService], (service) => {
service.pin = 12345;
expect(service.isValidPin()).toBe(false);
service.pin = 0;
expect(service.isValidPin()).toBe(true);
service.pin = 9999;
expect(service.isValidPin()).toBe(true);
service.pin = -50;
expect(service.isValidPin()).toBe(false);
}));
it('should greet when pin is wrong', async(inject([UserService], (service) => {
service.pin = 9999;
service.getGreeting().then((greeting) => {
expect(greeting).toEqual('Login failure!');
});
})), 3000);
it('should greet when pin is right', async(inject([UserService], (service) => {
service.pin = 2015;
service.getGreeting().then((greeting) => {
expect(greeting).toEqual('Welcome!');
});
})), 3000);
});
示例3: describe
/* tslint:disable:no-unused-variable */
import {
beforeEach, beforeEachProviders,
describe, xdescribe,
expect, it, xit,
async, inject
} from '@angular/core/testing';
import { WishlistService } from './wishlist.service';
describe('Wishlist Service', () => {
beforeEachProviders(() => [WishlistService]);
it('should ...',
inject([WishlistService], (service: WishlistService) => {
expect(service).toBeTruthy();
}));
});
示例4: describe
// #docregion
import { describe, beforeEachProviders, it, inject } from '@angular/core/testing';
import OrderByPipe from '../../app/js/phone_list/order_by.pipe';
describe('OrderByPipe', () => {
let input:any[] = [
{name: 'Nexus S', snippet: 'The Nexus S Phone', images: []},
{name: 'Motorola DROID', snippet: 'An Android-for-business smartphone', images: []}
];
beforeEachProviders(() => [OrderByPipe]);
it('should order by the given property', inject([OrderByPipe], (orderByPipe) => {
expect(orderByPipe.transform(input, 'name')).toEqual([input[1], input[0]]);
}));
});
示例5: describe
describe('UserService Service', () => {
beforeEachProviders(() => [API_PROVIDERS]);
it('should contain authentication methods',
inject([UserApi], (service: UserApi) => {
expect(service).toBeTruthy();
expect(service.login).toBeTruthy();
expect(service.logout).toBeTruthy();
expect(service.getAccessTokens).toBeTruthy();
expect(service.getCurrent).toBeTruthy();
expect(service.getCurrentId).toBeTruthy();
})
);
it('should create a new instance',
inject([UserApi], (userApi: UserApi) => {
let user: User = new User();
user.email = Date.now() + '@test.com';
user.password = 'test';
return userApi.create(user)
.subscribe((user: User) => expect(user.id).toBeTruthy());
})
);
it('should login the user',
inject([UserApi], (userApi: UserApi) => {
let user: User = new User();
user.email = Date.now() + '@test.com';
user.password = 'test';
return userApi.create(user)
.subscribe((instance: User) => userApi.login(user)
.subscribe((token: TokenInterface) => {
expect(token.id).toBeTruthy();
expect(token.userId).toBe(instance.id);
}));
})
);
it('should logout the user',
inject([UserApi], (userApi: UserApi) => {
let user: User = new User();
user.email = Date.now() + '@test.com';
user.password = 'test';
return userApi.create(user)
.subscribe((instance: User) => userApi.login(user)
.subscribe((token: TokenInterface) => {
expect(token.id).toBeTruthy();
expect(token.userId).toBe(instance.id);
userApi.logout().subscribe((res: boolean) => {
expect(res).toBe(true);
});
}));
})
);
it('should fail login the user',
inject([UserApi], (userApi: UserApi) => {
return userApi.login({ email: 'not@existing.com', password: 'duh' })
.subscribe((res) => { }, err => expect(err.status).toEqual(401));
})
);
it('should get current user',
inject([UserApi], (userApi: UserApi) => {
let user: User = new User();
user.email = Date.now() + '@test.com';
user.password = 'test';
return userApi.create(user)
.subscribe((instance: User) => userApi.login(user)
.subscribe((token: TokenInterface) => userApi.getCurrent()
.subscribe((user: User) => expect(user.id).toBe(instance.id)
)));
}));
});
示例6: describe
/* tslint:disable:no-unused-variable */
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import {
beforeEach, beforeEachProviders,
describe, xdescribe,
expect, it, xit,
async, inject
} from '@angular/core/testing';
import { ProcessComponent } from './process.component';
describe('Component: Process', () => {
it('should create an instance', () => {
let component = new ProcessComponent();
expect(component).toBeTruthy();
});
});
示例7: describe
describe('`NglPopoverBehavior`', () => {
it('should change visibility based on mouse', testAsync((fixture: ComponentFixture<TestComponent>) => {
fixture.detectChanges();
const triggerEl = fixture.nativeElement.firstElementChild;
triggerEl.dispatchEvent(new Event('mouseenter'));
setTimeout(() => {
expect(getPopoverElement(fixture.nativeElement)).toBeTruthy();
triggerEl.dispatchEvent(new Event('mouseleave'));
expect(getPopoverElement(fixture.nativeElement)).toBeFalsy();
});
}));
it('should change visibility based on focus', testAsync((fixture: ComponentFixture<TestComponent>) => {
fixture.detectChanges();
const triggerEl = fixture.nativeElement.firstElementChild;
triggerEl.dispatchEvent(new Event('focus'));
setTimeout(() => {
expect(getPopoverElement(fixture.nativeElement)).toBeTruthy();
triggerEl.dispatchEvent(new Event('blur'));
expect(getPopoverElement(fixture.nativeElement)).toBeFalsy();
});
}));
it('should create more than one instances', testAsync((fixture: ComponentFixture<TestComponent>) => {
fixture.detectChanges();
const triggerEl = fixture.nativeElement.firstElementChild;
triggerEl.dispatchEvent(new Event('focus'));
setTimeout(() => {
triggerEl.dispatchEvent(new Event('mouseenter'));
expect(fixture.nativeElement.querySelectorAll('ngl-popover').length).toBe(1);
});
}));
});
示例8: describe
import {
beforeEachProviders,
it,
describe,
expect,
inject
} from '@angular/core/testing';
import { PmProductSrv } from './pm-services.service';
describe('PmServices Service', () => {
beforeEachProviders(() => [PmProductSrv]);
it('should ...',
inject([PmProductSrv], (service: PmProductSrv) => {
expect(service).toBeTruthy();
}));
});
示例9: describe
/* tslint:disable:no-unused-variable */
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import {
beforeEach, beforeEachProviders,
describe, xdescribe,
expect, it, xit,
async, inject
} from '@angular/core/testing';
import { ImageCarouselComponent } from './image-carousel.component';
describe('Component: ImageCarousel', () => {
it('should create an instance', () => {
// let component = new ImageCarouselComponent();
// expect(component).toBeTruthy();
});
});
示例10: describe
describe('LocalStorageTaskService', () => {
beforeEach(() => {
spyOn(localStorage, 'getItem').and.callFake(function (key) {
return localStore[key];
});
spyOn(localStorage, 'setItem').and.callFake(function (key, value) {
return localStore[key] = value + '';
});
spyOn(localStorage, 'clear').and.callFake(function () {
localStore = {};
});
});
beforeEachProviders(() => [LocalStorageTaskService]);
it('can list all tasks', inject([LocalStorageTaskService], (service) => {
let tasks = service.list();
expect(tasks.every(task => task instanceof Task)).toBe(true);
expect(tasks.length).toBe(2);
expect(tasks[0].title).toBe('Task 1');
expect(tasks[1].title).toBe('Task 2');
}));
it('can add a task to the repository', inject([LocalStorageTaskService], (service) => {
let len = service.add({ title: 'Task 3', notes: 'Task 3 notes' });
let tasks = service.list();
expect(len).toBe(3);
expect(tasks[2].title).toBe('Task 3');
expect(tasks[2].notes).toBe('Task 3 notes');
}));
it('can remove the specified task from the repository', inject([LocalStorageTaskService], (service) => {
let tasks = service.list();
let taskToBeRemoved = tasks[0];
let removedTasks = service.remove(taskToBeRemoved);
expect(removedTasks.length).toBe(1);
expect(removedTasks[0].title).toBe('Task 1');
}));
it('can update details of the specified task', inject([LocalStorageTaskService], (service) => {
const NEW_TITLE = 'Task 1 (edited)';
let tasks = service.list();
let taskToUpdate = tasks[0];
taskToUpdate.title = NEW_TITLE;
let updatedTask = service.update(taskToUpdate);
expect(tasks[0].title).toBe(NEW_TITLE);
expect(updatedTask.title).toBe(NEW_TITLE);
}));
});