本文整理匯總了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);
}));
});