本文整理汇总了TypeScript中app/testing.TestContext类的典型用法代码示例。如果您正苦于以下问题:TypeScript TestContext类的具体用法?TypeScript TestContext怎么用?TypeScript TestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: xdescribe
xdescribe('UserEditPage', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
var routeParams:RouteParams;
beforeEachProviders(() => {
routeParams = jasmine.createSpyObj('routeParams', ['get']);
return [
APP_TEST_PROVIDERS,
provide(RouteParams, {useValue: routeParams}),
]
});
beforeEach(createTestContext(_ => ctx = _));
beforeEach(done => {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(UserEditPage));
}, console.error);
});
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
});
});
示例2: describe
describe('SecurityRouterOutlet', () => {
var ctx:TestContext;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: TestCmp}),
]);
beforeEach(createTestContext(_ => ctx = _));
describe('when not signed in', () => {
beforeEach(done => {
ctx.init(TestCmp)
.finally(done)
.subscribe();
});
it('allows the access to public page', (done) => {
ctx.router.navigate(['/PublicCmp']).then(() => {
expect(ctx.location.path()).toEqual('/public');
done();
});
});
it('force redirect to login page when accessed to private page', (done) => {
ctx.router.navigate(['/PrivateCmp']).then(() => {
ctx.router.subscribe(() => {
expect(ctx.location.path()).toEqual('/login');
done();
});
});
});
}); // when not signed in
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
});
示例3: describe
describe('Gravatar', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(createTestContext(_ => ctx = _));
beforeEach(done => {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(Gravatar));
});
});
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
const cmp:Gravatar = cmpDebugElement.componentInstance;
expect(cmp.email).toEqual('test@test.com');
expect(cmp.alt).toEqual('test-alt');
expect(cmp.size).toEqual('1');
const el = cmpDebugElement.nativeElement;
expect(DOM.querySelector(el, 'img').getAttribute('src'))
.toEqual('https://secure.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=1');
});
});
示例4: describe
describe('HomePage', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
var userStatsDebugElement:DebugElement;
var micropostNewDebugElement:DebugElement;
var feedDebugElement:DebugElement;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(createTestContext(_ => ctx = _));
function createCmp(done) {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(HomePage));
if (!cmpDebugElement) return;
userStatsDebugElement = cmpDebugElement.query(By.directive(UserStats));
micropostNewDebugElement = cmpDebugElement.query(By.directive(MicropostNew));
feedDebugElement = cmpDebugElement.query(By.directive(Feed));
});
}
beforeEach(createCmp);
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
expect(userStatsDebugElement).toBeTruthy();
expect(userStatsDebugElement.componentInstance.userId).toEqual('me');
expect(micropostNewDebugElement).toBeTruthy();
expect(feedDebugElement).toBeTruthy();
});
it('reload user stats when created new micropost', () => {
const userStats:UserStats = userStatsDebugElement.componentInstance;
spyOn(userStats, 'ngOnChanges');
micropostNewDebugElement.triggerEventHandler('created', null);
expect(userStats.ngOnChanges).toHaveBeenCalled();
});
it('reload feed when created new micropost', () => {
const feed:Feed = feedDebugElement.componentInstance;
spyOn(feed, 'list');
micropostNewDebugElement.triggerEventHandler('created', null);
expect(feed.list).toHaveBeenCalled();
});
it('reload user stats when deleted a micropost', () => {
const userStats:UserStats = userStatsDebugElement.componentInstance;
spyOn(userStats, 'ngOnChanges');
feedDebugElement.triggerEventHandler('deleted', null);
expect(userStats.ngOnChanges).toHaveBeenCalled();
});
});
示例5: createCmp
function createCmp(done) {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(UserList));
});
}
示例6: beforeEach
beforeEach((done) => {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(HelpPage));
});
});
示例7: beforeEach
beforeEach(done => {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(UserEditPage));
}, console.error);
});
示例8: beforeEach
beforeEach(done => {
ctx.backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
});
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(FollowBtn));
});
});
示例9: createCmp
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));
});
}
示例10: createCmp
function createCmp(done) {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(HomePage));
if (!cmpDebugElement) return;
userStatsDebugElement = cmpDebugElement.query(By.directive(UserStats));
micropostNewDebugElement = cmpDebugElement.query(By.directive(MicropostNew));
feedDebugElement = cmpDebugElement.query(By.directive(Feed));
});
}