本文整理汇总了TypeScript中angular2/testing.afterEach函数的典型用法代码示例。如果您正苦于以下问题:TypeScript afterEach函数的具体用法?TypeScript afterEach怎么用?TypeScript afterEach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了afterEach函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('narrative-spec', () => {
var narrative;
beforeEachProviders(() => [
provide(MF_CONFIG, {useValue: CONFIG})
]);
beforeEach(() => {
narrative = new Narrative(CONFIG);
});
it('should be defined after construction from class Narrative', () => {
expect(narrative).toBeDefined();
});
it('should retrieve a reference to the unique CONFIG object', () => {
expect(narrative.getConfig()).toBe(CONFIG);
});
it('should use test mode', () => {
var config = narrative.getConfig();
expect(config['test']).toBe(true);
});
afterEach(() => {
narrative = undefined;
});
}); //describe
开发者ID:josefK128,项目名称:meta-forms-mf2,代码行数:27,代码来源:narrative.spec.ts
示例2: describe
describe('some component', () => {
afterEach((done) => { db.reset().then((_) => done()); });
it('uses the db', () => {
// This test can leave the database in a dirty state.
// The afterEach will ensure it gets reset.
});
});
开发者ID:0oAimZo0,项目名称:Angular2Learning,代码行数:7,代码来源:testing.ts
示例3: describe
describe('LoginService', () => {
var loginService:LoginService;
var backend:MockBackend;
beforeEachProviders(() => [APP_TEST_PROVIDERS]);
beforeEach(inject([LoginService, MockBackend], (..._) => {
[loginService, backend] = _;
}));
afterEach(() => localStorage.clear());
describe('.login', () => {
it('can login', (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
headers: new Headers({'X-AUTH-TOKEN': 'my jwt'}),
})));
expect(conn.request.method).toEqual(RequestMethod.Post);
expect(conn.request.url).toEqual('/api/login');
expect(conn.request.text()).toEqual(JSON.stringify({
email: '[email protected]',
password: 'secret',
}));
});
loginService.login('[email protected]', 'secret').subscribe(() => {
expect(localStorage.getItem('jwt')).toEqual('my jwt');
done();
});
});
}); // .login
describe('.logout', () => {
it('can logout', () => {
localStorage.setItem('jwt', 'my jwt');
loginService.logout();
expect(localStorage.getItem('jwt')).toBeFalsy();
});
}); // .logout
describe('.currentUser', () => {
describe('when not signed in', () => {
it('returns nothing', () => {
expect(loginService.currentUser()).toBeFalsy();
});
});
describe('when signed in', () => {
beforeEach(() => {
localStorage.setItem('jwt', 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0OEB0ZXN0LmNvbSIsInVzZXJJZCI6MTd9.KKUI_-xoLRlouQ4MNYGRn7OkuLM0i8Frmwb5O5gvf1xgXse6sfqG10HiFwber9JSp9ZYh25n3MH_YwUowF9Xzw');
});
it('returns current user', () => {
expect(loginService.currentUser()).toEqual({
id: 17,
email: '[email protected]',
})
});
});
}); // .currentUsr
});
开发者ID:windwang,项目名称:angular2-app,代码行数:60,代码来源:LoginService.spec.ts
示例4: describe
describe('<glyph>', () => {
let backend: MockBackend;
let response;
beforeEachProviders(() => [
BaseRequestOptions,
MockBackend,
provide(Http, {
useFactory: (connectionBackend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
return new Http(connectionBackend, defaultOptions);
},
deps: [
MockBackend,
BaseRequestOptions
]
}),
provide(Icon, {
useFactory: (http: Http) => {
return new Icon(http);
},
deps: [
Http
]
})
]);
beforeEach(inject([MockBackend], (mockBackend) => {
backend = mockBackend;
response = new Response(
new ResponseOptions({body: GLYPH_RESPONSE_BODY})
);
}));
afterEach(() => backend.verifyNoPendingRequests());
it('should append an svg as child of self', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
let ee: any = new EventEmitter();
backend.connections.subscribe((connection: MockConnection) => {
connection.mockRespond(response);
ee.resolve();
});
tcb
.createAsync(GlyphTest)
.then((fixture: ComponentFixture) => {
fixture.detectChanges();
ee.subscribe(null, null, () => {
let logo: Element = fixture.nativeElement.querySelector('glyph');
expect(logo.querySelector('svg')).not.toBe(null);
});
});
}));
});
开发者ID:truongndnnguyen,项目名称:ng2-lab,代码行数:52,代码来源:glyph.spec.ts
示例5: describe
describe('LoginPage', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
var loginService:LoginService;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(inject([LoginService], _ => {
loginService = _
}));
beforeEach(createTestContext(_ => ctx = _));
beforeEach(done => {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(LoginPage));
});
});
afterEach(() => localStorage.clear());
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
});
it('can login', (done) => {
const cmp:LoginPage = cmpDebugElement.componentInstance;
spyOn(loginService, 'login').and.callThrough();
ctx.backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
});
cmp.login('[email protected]', 'secret');
expect(loginService.login).toHaveBeenCalledWith('[email protected]', 'secret');
ctx.router.subscribe(() => {
expect(ctx.location.path()).toEqual('/home');
done();
});
});
it('can navigate to signup page', (done) => {
const el = cmpDebugElement.nativeElement;
DOM.querySelector(el, 'a').click();
ctx.router.subscribe(() => {
expect(ctx.location.path()).toEqual('/signup');
done();
});
});
});
开发者ID:windwang,项目名称:angular2-app,代码行数:51,代码来源:LoginPage.spec.ts
示例6: describe
describe('producer-component-spec', () => {
beforeEachProviders(() => [
]);
beforeEach(() => {
// diagnostics
console.log('\n\n %*%%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%');
console.log(`producer.spec: CONFIG.test = ${CONFIG.test}`);
console.log(`producer.spec: G = ${G}`);
console.log('\n\n %*%%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%');
});
it('should be defined after construction from class Producer', () => {
expect(producer).toBeDefined();
});
it('should correctly g-process axiom1', (done) => {
producer.emitG(axiom1).then((o) => {
expect(o.genotype).toEqual(expect_genotype1);
done();
});
});
it('should correctly g-process axiom2', (done) => {
producer.emitG(axiom2).then((o) => {
expect(o.genotype).toEqual(expect_genotype2);
done();
});
});
it('should correctly p-process genotype1', (done) => {
producer.emitG(genotype1).then((o) => {
expect(o.phenotype).toEqual(expect_phenotype1);
done();
});
});
it('should correctly p-process genotype2', (done) => {
producer.emitG(genotype2).then((o) => {
expect(o.phenotype).toEqual(expect_phenotype2);
done();
});
});
afterEach(() => {
axiom1 = axiom1;
});
}); //describe
开发者ID:josefK128,项目名称:meta-forms-mf2,代码行数:49,代码来源:producer-component.spec.ts
示例7: describe
describe('Ng2Notify', () => {
let notifyDirective: Ng2Notify;
let notifyService: Ng2NotifyService = new Ng2NotifyService();
let originalTimeout;
beforeEach(() => {
notifyDirective = new Ng2Notify(notifyService);
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
});
afterEach(() => {
jasmine.clock().uninstall();
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
// TODO: Test subscribe
it('should have a empty Array var "notifications"', () => {
expect(notifyDirective.notifications).toEqual([]);
});
it('should have a null string "corner"', () => {
expect(notifyDirective.corner).toBeNull(true);
});
it('notifyService should be a instance of Ng2NotifyService', () => {
expect(notifyDirective.notifyService instanceof Ng2NotifyService).toBe(true);
});
it('if set a new notify, notifications.length should be 1', () => {
notifyDirective.setNotify({
'type': 'default',
'message': 'Default notification.',
'corner': 'right-top',
'delay': 5000
});
expect(notifyDirective.notifications.length).toBe(1);
});
it('if set some notify\'s, notifications.length should be like notify\'s entered', () => {
notifyDirective.setNotify({
'type': 'default',
'message': 'Default notification #1.',
'corner': 'right-top',
'delay': 5000
});
notifyDirective.setNotify({
'type': 'default',
'message': 'Default notification #2.',
'corner': 'right-top',
'delay': 5000
});
expect(notifyDirective.notifications.length).toBe(2);
});
it('when set a new notify, corner has new position', () => {
notifyDirective.setNotify({
'type': 'default',
'message': 'Default notification #1.',
'corner': 'right-top',
'delay': 2000
});
expect(notifyDirective.corner).toBe('right-top');
});
it('delay seconds after set notify, should been has removed from array', (done) => {
jasmine.clock().uninstall();
jasmine.clock().install();
notifyDirective.setNotify({
'type': 'default',
'message': 'Default notification #1.',
'corner': 'right-top',
'delay': 1000
});
expect(notifyDirective.notifications.length).toBe(1);
expect(notifyDirective.notifications[0].notify).toBe(true);
jasmine.clock().tick(1500);
expect(notifyDirective.notifications.length).toBe(0);
done();
});
});
开发者ID:clamstew,项目名称:ng2-notify,代码行数:88,代码来源:ng2-notify.spec.ts
示例8: describe
describe('UserService', () => {
var userService:UserService;
var backend:MockBackend;
beforeEachProviders(() => [APP_TEST_PROVIDERS]);
beforeEach(inject([UserService, MockBackend], (..._) => {
[userService, backend] = _;
}));
afterEach(() => localStorage.clear());
describe('.list', () => {
it("list users", (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(dummyListJson),
})));
expect(conn.request.method).toEqual(RequestMethod.Get);
expect(conn.request.url).toEqual('/api/users?page=1&size=5');
});
userService.list().subscribe(res => {
expect(res).toEqual(dummyListJson);
done();
});
});
}); // .list
describe('.get', () => {
it("get user", (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(dummyGetJson),
})));
expect(conn.request.method).toEqual(RequestMethod.Get);
expect(conn.request.url).toEqual('/api/users/1');
});
userService.get(1).subscribe(res => {
expect(res).toEqual(dummyGetJson);
done();
});
});
}); // .get
describe('.create', () => {
it("create user", (done) => {
const params:UserParams = {
email: '[email protected]',
password: 'secret',
name: 'test1',
};
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
expect(conn.request.method).toEqual(RequestMethod.Post);
expect(conn.request.url).toEqual('/api/users');
expect(conn.request.text()).toEqual(JSON.stringify(params));
});
userService.create(params).subscribe(() => {
done();
});
});
}); // .create
describe('.updateMe', () => {
it("update me", (done) => {
const params:UserParams = {
email: '[email protected]',
password: 'secret',
name: 'test1',
};
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
expect(conn.request.method).toEqual(RequestMethod.Patch);
expect(conn.request.url).toEqual('/api/users/me');
expect(conn.request.text()).toEqual(JSON.stringify(params));
});
userService.updateMe(params).subscribe(() => {
done();
});
});
}); // .updateMe
describe('.listFollowings', () => {
it("list followings", (done) => {
backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(dummyListJson),
})));
expect(conn.request.method).toEqual(RequestMethod.Get);
expect(conn.request.url).toEqual('/api/users/1/followings?maxId=2&count=3');
});
userService.listFollowings('1', {maxId: 2, count: 3}).subscribe(res => {
expect(res).toEqual(dummyListJson);
done();
});
});
}); // .listFollowings
describe('.listFollowers', () => {
it("list followers", (done) => {
backend.connections.subscribe(conn => {
//.........这里部分代码省略.........
开发者ID:windwang,项目名称:angular2-app,代码行数:101,代码来源:UserService.spec.ts
示例9: describe
describe('SignupPage', () => {
var ctx:TestContext;
var cmpDebugElement:DebugElement;
var loginService:LoginService;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(createTestContext(_ => ctx = _));
beforeEach(inject([LoginService], _ => {
loginService = _
}));
beforeEach(done => {
ctx.init(TestCmp)
.finally(done)
.subscribe(() => {
cmpDebugElement = ctx.fixture.debugElement.query(By.directive(SignupPage));
});
});
afterEach(() => localStorage.clear());
it('can be shown', () => {
expect(cmpDebugElement).toBeTruthy();
});
it('can validate inputs', () => {
const page:SignupPage = cmpDebugElement.componentInstance;
page.name.updateValue('a', {});
page.email.updateValue('b', {});
page.password.updateValue('c', {});
page.passwordConfirmation.updateValue('d', {});
expect(page.myForm.valid).toBeFalsy();
page.name.updateValue('akira', {});
page.email.updateValue('[email protected]', {});
page.password.updateValue('secret123', {});
page.passwordConfirmation.updateValue('secret123', {});
expect(page.myForm.valid).toBeTruthy();
});
it('can signup', (done) => {
const page:SignupPage = cmpDebugElement.componentInstance;
spyOn(loginService, 'login').and.callThrough();
spyOn(loginService, 'currentUser').and.returnValue({
id: 1, email: '[email protected]',
});
ctx.backend.connections.subscribe(conn => {
conn.mockRespond(new Response(new BaseResponseOptions()));
});
page.onSubmit({
email: '[email protected]',
password: 'secret',
name: 'akira',
});
expect(loginService.login).toHaveBeenCalledWith('[email protected]', 'secret');
ctx.router.subscribe(() => {
expect(ctx.location.path()).toEqual('/home');
done()
});
});
});
开发者ID:windwang,项目名称:angular2-app,代码行数:65,代码来源:SignupPage.spec.ts
示例10: describe
describe('Icon', () => {
let injector: Injector;
let store: Icon;
let backend: MockBackend;
let glyph: Node;
let response;
beforeEach(() => {
injector = Injector.resolveAndCreate([
BaseRequestOptions,
MockBackend,
provide(Http, {
useFactory: (connectionBackend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
return new Http(connectionBackend, defaultOptions);
},
deps: [
MockBackend,
BaseRequestOptions
]
}),
provide(Icon, {
useFactory: (http: Http) => {
return new Icon(http);
},
deps: [
Http
]
})
]);
backend = injector.get(MockBackend);
store = injector.get(Icon);
response = new Response(
new ResponseOptions({body: SVG_GLYPH_HTML})
);
glyph = createGlyphNode();
});
afterEach(() => backend.verifyNoPendingRequests());
describe('.get()', () => {
it('return value should be an SVG element', (done: () => void) => {
backend.connections.subscribe((connection: MockConnection) => connection.mockRespond(response));
store.get(FAKE_URL).then((svg) => {
expect(svg.isEqualNode(glyph)).toBe(true);
done();
});
});
it('should only fire one request for the same path and resolve from cache', (done: () => void) => {
let url = `ofor/${FAKE_URL}`;
let spy = jasmine.createSpy('onEstablish');
let bc = {
onEstablish: spy
};
backend.connections.subscribe((connection: MockConnection) => {
bc.onEstablish();
connection.mockRespond(response);
});
store.get(url).then(() => {
store.get(url).then(() => {
expect(bc.onEstablish.calls.count()).toEqual(1);
done();
});
});
});
});
});
开发者ID:virajs,项目名称:ng2-lab,代码行数:66,代码来源:icon.spec.ts
注:本文中的angular2/testing.afterEach函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论