|
1 | 1 | 'use strict'; |
2 | | - |
3 | | -// import main from './main.component'; |
4 | | -// import {MainController} from './main.component'; |
| 2 | +import { |
| 3 | + async, |
| 4 | + ComponentFixture, |
| 5 | + inject, |
| 6 | + TestBed, |
| 7 | +} from '@angular/core/testing'; |
| 8 | +import { |
| 9 | + BaseRequestOptions, |
| 10 | + ConnectionBackend, |
| 11 | + Http, |
| 12 | + HttpModule, |
| 13 | + Response, |
| 14 | + ResponseOptions, |
| 15 | +} from '@angular/http'; |
| 16 | +import { MockBackend } from '@angular/http/testing'; |
| 17 | +<%_ if(filters.mocha && filters.expect) { -%> |
| 18 | +import { expect } from 'chai';<% } %><% if(filters.uibootstrap) { %> |
| 19 | +import { TooltipModule } from 'ngx-bootstrap';<% } %> |
| 20 | +import { FormsModule } from '@angular/forms'; |
| 21 | +import { SocketService } from '../../components/socket/socket.service'; |
| 22 | +import { SocketServiceStub } from '../../components/socket/socket.mock'; |
| 23 | +import { MainComponent } from './main.component'; |
5 | 24 |
|
6 | 25 | describe('Component: MainComponent', function() { |
7 | | - it('should attach a list of things to the controller', function() {}); |
| 26 | + let comp: MainComponent; |
| 27 | + let fixture: ComponentFixture<MainComponent>; |
| 28 | + |
| 29 | + beforeEach(async(() => { |
| 30 | + TestBed.configureTestingModule({ |
| 31 | + imports: [ |
| 32 | + FormsModule,<% if(filters.uibootstrap) { %> |
| 33 | + TooltipModule.forRoot(),<% } %> |
| 34 | + HttpModule, |
| 35 | + ], |
| 36 | + declarations: [ MainComponent ], // declare the test component |
| 37 | + providers: [ |
| 38 | + BaseRequestOptions, |
| 39 | + MockBackend, |
| 40 | + { |
| 41 | + provide: Http, |
| 42 | + useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => { |
| 43 | + return new Http(backend, defaultOptions); |
| 44 | + },<%_ if(filters.ws) { %> |
| 45 | + deps: [MockBackend, BaseRequestOptions]<% } %> |
| 46 | + }, |
| 47 | + { provide: SocketService, useClass: SocketServiceStub }, |
| 48 | + ], |
| 49 | + }).compileComponents(); |
| 50 | + })); |
| 51 | + <%_ if(filters.ws) { %> |
| 52 | + beforeEach(async(inject([MockBackend], (mockBackend) => { |
| 53 | + mockBackend.connections.subscribe(conn => { |
| 54 | + conn.mockRespond(new Response(new ResponseOptions({ |
| 55 | + body: JSON.stringify(['HTML5 Boilerplate', 'AngularJS', 'Karma', 'Express']) |
| 56 | + }))); |
| 57 | + }); |
| 58 | + })));<% } %> |
| 59 | + |
| 60 | + beforeEach(async(() => { |
| 61 | + fixture = TestBed.createComponent(MainComponent); |
| 62 | + // MainComponent test instance |
| 63 | + comp = fixture.componentInstance; |
| 64 | + |
| 65 | + /** |
| 66 | + * Trigger initial data binding. |
| 67 | + */ |
| 68 | + fixture.detectChanges(); |
| 69 | + })); |
| 70 | + |
| 71 | + it('should attach a list of things to the controller', () => {<% if(filters.jasmine) { %> |
| 72 | + expect(comp.awesomeThings.length).toEqual(4);<% } else if(filters.mocha) { -%> |
| 73 | + <%= expect() %>comp.awesomeThings.length<%= to() %>.equal(4);<% } %> |
| 74 | + }); |
8 | 75 | }); |
0 commit comments