本文整理汇总了TypeScript中app/testing.signin函数的典型用法代码示例。如果您正苦于以下问题:TypeScript signin函数的具体用法?TypeScript signin怎么用?TypeScript signin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了signin函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('when signed in', () => {
beforeEach(signin());
beforeEach(done => {
ctx.init(TestCmp)
.finally(done)
.subscribe();
});
it('allows the access to private page', (done) => {
ctx.router.navigate(['/PrivateCmp']).then(() => {
expect(ctx.location.path()).toEqual('/private');
done();
});
});
it('force redirect to specified page when accessed to a page like login page', (done) => {
ctx.router.navigate(['/Login']).then(() => {
ctx.router.subscribe(() => {
expect(ctx.location.path()).toEqual('/public');
done();
});
});
});
}); // when signed in
示例2: describe
describe('when signed in', () => {
let loginService:LoginService;
beforeEach(inject([LoginService], _ => {
loginService = _;
}));
beforeEach(signin({id: 1, email: 'test@test.com'}));
beforeEach(createCmp);
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
});
it('shows a nav link to home', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.home>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/home');
expect(link.parentElement.classList).toContain('active');
done();
});
});
it('does not show a nav link to top', () => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.top>a');
expect(link).toBeNull();
});
it('shows a nav link to users', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.users>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/users');
expect(link.parentElement.classList).toContain('active');
done();
});
});
it('shows a nav link to help', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.help>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/help');
expect(link.parentElement.classList).toContain('active');
done();
});
});
it('shows a nav link to profile', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.profile>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/users/me');
done();
});
});
describe('navigate to settings', () => {
beforeEach(inject([UserService], userService => {
spyOn(userService, 'get').and.returnValue(Observable.of({}));
}));
it('shows a nav link to settings', (done) => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.settings>a');
expect(link).toBeTruthy();
link.click();
ctx.router.subscribe(() => {
ctx.fixture.detectChanges();
expect(ctx.location.path()).toEqual('/users/me/edit');
done();
});
});
});
it('shows a nav link to logout', () => {
const link = DOM.querySelector(cmpDebugElement.nativeElement, '#navbar li.logout>a');
expect(link).toBeTruthy();
spyOn(loginService, 'logout');
link.click();
expect(loginService.logout).toHaveBeenCalled();
});
}); // when signed in
示例3: describe
describe('Feed', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
var micropostService:MicropostService;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(createTestContext(_ => ctx = _));
beforeEach(inject([MicropostService], _ => {micropostService = _}));
beforeEach(signin({id: 1, email: 'test1@test.com'}));
beforeEach(() => jasmine.clock().mockDate(new Date(24 * 60 * 60 * 1000)));
function createCmp(done) {
ctx.backend.connections.subscribe(conn => {
conn.mockRespond(dummyResponse);
});
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(Feed));
});
}
beforeEach(createCmp);
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
});
it('can show feed', () => {
const cmp:Feed = cmpDebugElement.componentInstance;
expect(cmp.feed.length).toEqual(2);
const el = cmpDebugElement.nativeElement;
expect(DOM.querySelectorAll(el, 'li .content').length).toEqual(2);
const avatarLink = DOM.querySelector(el, 'li>a');
expect(avatarLink.getAttribute('href')).toEqual('/users/1');
const gravatarDebugElement = cmpDebugElement.query(By.directive(Gravatar));
expect(gravatarDebugElement).toBeTruthy();
expect(gravatarDebugElement.componentInstance.email).toEqual('test1@test.com');
expect(gravatarDebugElement.componentInstance.alt).toEqual('test user1');
const userLink = DOM.querySelector(el, '.user>a');
expect(userLink).toHaveText('test user1');
expect(userLink.getAttribute('href')).toEqual('/users/1');
const content = DOM.querySelector(el, '.content');
expect(content).toHaveText('content1');
const timestamp = DOM.querySelector(el, '.timestamp');
expect(timestamp.innerText).toMatch(/1 day ago/);
const deleteLinks = DOM.querySelectorAll(el, '.delete');
expect(deleteLinks[0]).toBeTruthy();
expect(deleteLinks[1]).toBeFalsy();
});
it('does not delete micropost when not confirmed', () => {
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(false);
spyOn(micropostService, 'delete');
deleteLink.click();
expect(micropostService.delete).not.toHaveBeenCalled();
});
it('deletes micropost when confirmed', done => {
const cmp:Feed = cmpDebugElement.componentInstance;
const testCmp:TestCmp = ctx.fixture.debugElement.componentInstance;
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(true);
spyOn(cmp, 'list');
spyOn(testCmp, 'listenDeleted');
ObservableWrapper.subscribe(cmp.deleted, () => {
expect(cmp.list).toHaveBeenCalled();
expect(testCmp.listenDeleted).toHaveBeenCalled();
done();
});
deleteLink.click();
});
})
示例4: describe
describe('MicropostList', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
var micropostService:MicropostService;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(createTestContext(_ => ctx = _));
beforeEach(inject([MicropostService], _ => {
micropostService = _
}));
beforeEach(() => jasmine.clock().mockDate(new Date(24 * 60 * 60 * 1000)));
beforeEach(signin({id: 1, email: "test@test.com"}));
function createCmp(done) {
ctx.backend.connections.subscribe(conn => {
conn.mockRespond(dummyResponse);
});
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(MicropostList));
ctx.fixture.detectChanges();
});
}
beforeEach(createCmp);
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
});
it('can show list of posts', () => {
const cmp:MicropostList = cmpDebugElement.componentInstance;
expect(cmp.posts.length).toEqual(2);
const el = cmpDebugElement.nativeElement;
expect(DOM.querySelectorAll(el, 'li>.content').length).toEqual(2);
const content = DOM.querySelector(el, '.content');
expect(content).toHaveText('content1');
const timestamp = DOM.querySelector(el, '.timestamp');
expect(timestamp.innerText).toMatch(/1 day ago/);
const deleteLinks = DOM.querySelectorAll(el, '.delete');
expect(deleteLinks[0]).toBeTruthy();
expect(deleteLinks[1]).toBeFalsy();
});
it('can load more', () => {
const cmp:MicropostList = cmpDebugElement.componentInstance;
const moreBtn = DOM.querySelector(cmpDebugElement.nativeElement, '.moreBtn');
moreBtn.click();
expect(cmp.posts.length).toEqual(4);
});
it('does not delete micropost when not confirmed', () => {
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(false);
spyOn(micropostService, 'delete');
deleteLink.click();
expect(micropostService.delete).not.toHaveBeenCalled();
});
it('deletes micropost when confirmed', () => {
const cmp:MicropostList = cmpDebugElement.componentInstance;
const deleteLink = DOM.querySelector(cmpDebugElement.nativeElement, '.delete');
spyOn(window, 'confirm').and.returnValue(true);
deleteLink.click();
expect(cmp.posts.length).toEqual(1);
});
});