当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript testing.beforeEachProviders函数代码示例

本文整理汇总了TypeScript中angular2/testing.beforeEachProviders函数的典型用法代码示例。如果您正苦于以下问题:TypeScript beforeEachProviders函数的具体用法?TypeScript beforeEachProviders怎么用?TypeScript beforeEachProviders使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了beforeEachProviders函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

describe('UserService', () => {

	beforeEachProviders(() => [
		UserService,
		StorageService,
		SessionService,
		HttpService,
		BaseRequestOptions,
		MockBackend,
		provide(Http, {
			useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
				return new Http(backend, defaultOptions);
			},
			deps: [MockBackend, BaseRequestOptions]
		})
	]);

	// beforeEach(inject([MockBackend], (backend: MockBackend) => {
	// 	const baseResponse = new Response(new ResponseOptions({ body: { id: 1, email: 'a@a.com', username: 'a@a.com', password: 'a@a.com' } }));
	// 	backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
	// }));

	it('should return token when authenticate worked',
		inject([UserService, MockBackend], (userService: UserService, backend: MockBackend) => {
			let token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJzZXJ2ZXIiLCJlbWFpbCI6ImFAYS5jb20iLCJwYXNzd29yZCI6ImFAYS5jb20iLCJpYXQiOjE0NTk0NDc4ODAsImV4cCI6MTQ1OTUzNDI4MH0.b260_KHB1FBBNlu2avblbi9VzqSER9hnzzCzdf6cGA4';
			let baseResponse = new Response(new ResponseOptions({ body: { success: true, message: 'Enjoy your token!', token: token } }));
			backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
			User.setNextId(0);
			userService.authenticate('a@a.com', 'a@a.com', false).subscribe((res: any) => {
				expect(res.token).toBe(token);
			});
		})
	);

	it('should return user when authenticate worked',
		inject([UserService, MockBackend], (userService: UserService, backend: MockBackend) => {
			let token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJzZXJ2ZXIiLCJlbWFpbCI6ImFAYS5jb20iLCJwYXNzd29yZCI6ImFAYS5jb20iLCJpYXQiOjE0NTk0NDc4ODAsImV4cCI6MTQ1OTUzNDI4MH0.b260_KHB1FBBNlu2avblbi9VzqSER9hnzzCzdf6cGA4';
			let baseResponse = new Response(new ResponseOptions({ body: { success: true, message: 'Enjoy your token!', token: token } }));
			backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
			User.setNextId(0);
			userService.authenticate('a@a.com', 'a@a.com', false).subscribe((res: any) => {
				expect(res.user.id).toBe(1);
				expect(res.user.username).toBe('server');
				expect(res.user.email).toBe('a@a.com');
			});
		})
	);

	it('should return a user without password when authenticate worked',
		inject([UserService, MockBackend], (userService: UserService, backend: MockBackend) => {
			let token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJzZXJ2ZXIiLCJlbWFpbCI6ImFAYS5jb20iLCJwYXNzd29yZCI6ImFAYS5jb20iLCJpYXQiOjE0NTk0NDc4ODAsImV4cCI6MTQ1OTUzNDI4MH0.b260_KHB1FBBNlu2avblbi9VzqSER9hnzzCzdf6cGA4';
			let baseResponse = new Response(new ResponseOptions({ body: { success: true, message: 'Enjoy your token!', token: token } }));
			backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
			User.setNextId(0);
			userService.authenticate('a@a.com', 'a@a.com', false).subscribe((res: any) => {
				console.log('HERE', res);
				expect(res.user.password).toBe(undefined);
			});
		})
	);


});
开发者ID:shryme,项目名称:Angular2,代码行数:63,代码来源:user.spec.ts

示例2: describe

describe('Blog Service', () => {

  // All heed this block - it is required so that the test injector
  // is properly set up. Without doing this, you won't get the
  // fake backend injected into Http.

  // Also, you need to inject MockBackend as a provider before you wire
  // it to replace XHRBackend with the provide function!  So this is all
  // extremely important to set up right.
  beforeEachProviders(() => {
    return [
      HTTP_PROVIDERS,
      provide(XHRBackend, {useClass: MockBackend}),
      BlogService
    ];
  });


  it('should get blogs', inject([XHRBackend, BlogService], (mockBackend, blogService) => {
    mockBackend.connections.subscribe(
      (connection: MockConnection) => {
        connection.mockRespond(new Response(
          new ResponseOptions({
              body: [
                {
                  id: 26,
                  contentRendered: "<p><b>Hi there</b></p>",
                  contentMarkdown: "*Hi there*"
                }]
            }
          )));
      });

    blogService.getBlogs().subscribe((blogs: BlogEntry[]) => {
      expect(blogs.length).toBe(1);
      expect(blogs[0].id).toBe(26);
    });

  }));



  it('should get blogs async', injectAsync([XHRBackend, BlogService], (mockBackend, blogService) => {
    return new Promise((pass, fail) => {
      mockBackend.connections.subscribe(
        (connection: MockConnection) => {
          connection.mockRespond(new Response(
            new ResponseOptions({
                body: [
                  {
                    id: 26,
                    contentRendered: "<p><b>Hi there</b></p>",
                    contentMarkdown: "*Hi there*"
                  }]
              }
            )));
        });

      blogService.getBlogs().subscribe(
        (data) => {
          expect(data.length).toBe(1);
          expect(data[0].id).toBe(26);
          expect(data[0].contentMarkdown).toBe('*Hi there*');
        });
    });
  }), 3000);

  it('should save updates to an existing blog entry',
    injectAsync([XHRBackend, BlogService], (mockBackend, blogService) => {
    return new Promise((resolve, reject) => {
      mockBackend.connections.subscribe(connection => {
        connection.mockRespond(new ResponseOptions({status: 200}));
      });

      let data: BlogEntry = new BlogEntry("Blog Entry", "<p><b>Hi</b></p>", "*Hi*", 10);
      blogService.saveBlog(data).subscribe(
        (successResult) => {
          expect(successResult).toBeDefined(  );
          expect(successResult.status).toBe(200);
        });
    });
  }), 300);
});
开发者ID:liuyijie,项目名称:angular2-webpack-demo-routing-and-http,代码行数:83,代码来源:blog-service.spec.ts

示例3: describe

describe('DemoFormWithEvents', () => {
  var _console;
  var fakeConsole;
  var el, input, form;

  beforeEach(() => {
    // declare a fake console to track all the logs
    fakeConsole = {};
    fakeConsole._logs = [];
    fakeConsole.log = (...theArgs) => fakeConsole._logs.push(theArgs.join(' '));

    // replace the real console with our fake version
    _console = window.console;
    window.console = fakeConsole;
  });

  // restores the real console
  afterAll(() => window.console = _console);

  beforeEachProviders(() => {
    return [FormBuilder];
  });

  function createComponent(tcb: TestComponentBuilder): Promise<ComponentFixture> {
    return tcb.createAsync(DemoFormWithEvents).then((fixture) => {
      el = fixture.debugElement.nativeElement;
      input = fixture.debugElement.query(By.css("input")).nativeElement;
      form = fixture.debugElement.query(By.css("form")).nativeElement;
      fixture.detectChanges();

      return fixture;
    });
  }

  it('displays errors with no sku', injectAsync([TestComponentBuilder], (tcb) => {
    return createComponent(tcb).then((fixture) => {
      input.value = '';
      dispatchEvent(input, 'input');
      fixture.detectChanges();

      // no value on sku field, all error messages are displayed
      let msgs = el.querySelectorAll('.ui.error.message');
      expect(msgs[0]).toHaveText('SKU is invalid');
      expect(msgs[1]).toHaveText('SKU is required');
    });
  }));

  it('displays no errors when sku has a value', injectAsync([TestComponentBuilder], (tcb) => {
    return createComponent(tcb).then((fixture) => {
      input.value = 'XYZ';
      dispatchEvent(input, 'input');
      fixture.detectChanges();

      let msgs = el.querySelectorAll('.ui.error.message');
      expect(msgs.length).toEqual(0);
    });
  }));

  it('handles sku value changes', inject([TestComponentBuilder],
    fakeAsync((tcb) => {
      createComponent(tcb).then((fixture) => {
        input.value = 'XYZ';
        dispatchEvent(input, 'input');
        tick();

        expect(fakeConsole._logs).toContain('sku changed to: XYZ');
      });
    })
  ));

  it('handles form changes', inject([TestComponentBuilder],
    fakeAsync((tcb) => {
      createComponent(tcb).then((fixture) => {
        input.value = 'XYZ';
        dispatchEvent(input, 'input');
        tick();

        expect(fakeConsole._logs).toContain('form changed to: [object Object]');
      });
    })
  ));

  it('handles form submission', inject([TestComponentBuilder],
    fakeAsync((tcb) => {
      createComponent(tcb).then((fixture) => {
        input.value = 'ABC';
        dispatchEvent(input, 'input');
        tick();

        fixture.detectChanges();
        dispatchEvent(form, 'submit');
        tick();

        expect(fakeConsole._logs).toContain('you submitted value: ABC');
      });
    })
  ));

});
开发者ID:Gitjerryzhong,项目名称:angular2,代码行数:99,代码来源:demo_form_with_events.spec.ts

示例4: beforeEachProviders

import { describe, it, expect, beforeEachProviders, inject } from 'angular2/testing'
import { ChatApp } from '../app/chatapp'

beforeEachProviders(() => [ChatApp]);

describe('ChatApp: Chatapp', () => {

});
开发者ID:jaruesink,项目名称:ExampleApp,代码行数:8,代码来源:chatapp.spec.ts

示例5: beforeEachProviders

import {describe, it, expect, beforeEachProviders, inject} from 'angular2/testing';
import {AppComponent} from './app.ts';

beforeEachProviders(() => [AppComponent]);

describe('Houston App', () => {

  it('should initiate the data service upon bootstrap',
     inject([AppComponent], (app: AppComponent) => {
       expect(app['_dataService'].developers$).toBeDefined();
     }));

});
开发者ID:Brocco,项目名称:houston,代码行数:13,代码来源:app.spec.ts

示例6: describe

describe('MarkPipes Pipe', () => {

  beforeEachProviders(() => [MarkPipe]);


});
开发者ID:AlexManga,项目名称:angular2-codelab,代码行数:6,代码来源:mark-pipe.spec.ts

示例7: describe

describe('RestService', () => {

	beforeEachProviders(() => [
		HTTP_PROVIDERS,
		provide(XHRBackend, { useClass: MockBackend }),
		RestService
	]);

	describe('Travel', () => {
		it('get()', inject([RestService, XHRBackend], (rest: RestService, mockBackend: MockBackend) => {
			mockBackend.connections.subscribe(c => {
				if (c.request.url === `${BASE_API_URL}/api/explore/partyTypes` && c.request.method === 0) {
					let res = new Response(
						new ResponseOptions(
							{
								body: {
									"results": [{
										"category_id": "123",
										"question_id": "123",
										"image_url": "http://test",
										"description": "I am a banana",
										"goodFor": "Me",
										"suggestions": "Good for you",
										"self": "http://another-link",
										"text": "This is all me"
									}]
								},
								status: 200
							}
						)
					);
					c.mockRespond(res);
				}
			})

			rest.traveling.get((err, response: Array<Travel>) => {
				expect(response.length).toBe(1);
				expect(response[0].category_id).toBeDefined();
				expect(response[0].category_id).toBe("123");
			});
		}));
	});

	describe('Questions', () => {
		var rest: RestService;
		var mockBackend: MockBackend;

		let before = (_rest, _mockBackend, cb) => {
			rest = _rest;
			mockBackend = _mockBackend;

			mockBackend.connections.subscribe(c => {
				let testPayload = {
					"category_id": "123",
					"question_id": "234",
					"image_url": "test234",
					"description": "this is a test",
					"goodFor": "everyone",
					"suggestions": "awesome stuff",
					"self": "http://test",
					"text": "this is some text"
				};

				if (c.request.url === `${BASE_API_URL}/api/explore/categories/123/questions` && c.request.method === 0) {
					send200({
						"results": [
							testPayload
						]
					}, c);
					return;
				}

				testPayload.question_id = "345";

				if (c.request.url === `${BASE_API_URL}/api/explore/questions/345` && c.request.method === 0) {
					send200({
						"results": [
							testPayload
						]
					}, c);
					return;
				}
			});

			cb();
		}

		it('get()', beforeHack(before, () => {
			rest.questions.get(123, (err, questions: Array<Question>) => {
				expect(questions.length).toBe(1);
				expect(questions[0].question_id).toBe("234");
			});
		}));

		it('getById()', beforeHack(before, () => {
			rest.questions.get(345, (err, question: Question) => {
				expect(question.question_id).toBe("345");
			});
		}));
	});
//.........这里部分代码省略.........
开发者ID:saikonda,项目名称:cruise-pas-public,代码行数:101,代码来源:rest.service.spec.ts

示例8: beforeEachProviders

import {describe, it, expect, beforeEachProviders, inject} from 'angular2/testing';
import {GestaoLivreApp} from '../app/gestaolivre';

beforeEachProviders(() => [GestaoLivreApp]);

/*
describe('App: Gestaolivre', () => {
  it('should have the `defaultMeaning` as 42', inject([GestaoLivreApp], (app: GestaoLivreApp) => {
    expect(app.defaultMeaning).toBe(42);
  }));

  describe('#meaningOfLife', () => {
    it('should get the meaning of life', inject([GestaoLivreApp], (app: GestaoLivreApp) => {
      expect(app.meaningOfLife()).toBe('The meaning of life is 42');
      expect(app.meaningOfLife(22)).toBe('The meaning of life is 22');
    }));
  });
});
*/
开发者ID:adrianobalani,项目名称:gestaolivre-frontend,代码行数:19,代码来源:gestaolivre.spec.ts

示例9: beforeEachProviders

import {describe, it, expect, beforeEachProviders, inject} from 'angular2/testing';
import {MainApp} from '../app/main';

beforeEachProviders(() => [MainApp]);
开发者ID:luiscajl,项目名称:practicaDAW,代码行数:4,代码来源:main.spec.ts

示例10: beforeEachProviders

import {describe, it, expect, beforeEachProviders, inject} from 'angular2/testing';
import {TourApp} from '../app/tour';

beforeEachProviders(() => [TourApp]);

describe('App: Tour', () => {
  it('should have the `defaultMeaning` as 42', inject([TourApp], (app) => {
    expect(app.defaultMeaning).toBe(42);
  }));

  describe('#meaningOfLife', () => {
    it('should get the meaning of life', inject([TourApp], (app) => {
      expect(app.meaningOfLife()).toBe('The meaning of life is 42');
      expect(app.meaningOfLife(22)).toBe('The meaning of life is 22');
    }));
  });
});

开发者ID:beligh-hamdi,项目名称:tourOfHeroes,代码行数:17,代码来源:tour.spec.ts


注:本文中的angular2/testing.beforeEachProviders函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。