Advertisement
Guest User

Untitled

a guest
Oct 8th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. Error: Uncaught (in promise): Error: Template parse errors:
  2. 'header-section' is not a known element:
  3. 1. If 'header-section' is an Angular component, then verify that it is part of this module.
  4. 2. If 'header-section' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
  5. [ERROR ->]<header-section></header-section>
  6. <router-outlet></router-outlet>
  7. <footer-section></footer-sectio"): AppComponent@1:2
  8. 'router-outlet' is not a known element:
  9. 1. If 'router-outlet' is an Angular component, then verify that it is part of this module.
  10. 2. If 'router-outlet' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
  11. <header-section></header-section>
  12. [ERROR ->]<router-outlet></router-outlet>
  13. <footer-section></footer-section>"): AppComponent@2:2
  14. 'footer-section' is not a known element:
  15. 1. If 'footer-section' is an Angular component, then verify that it is part of this module.
  16. 2. If 'footer-section' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
  17. <header-section></header-section>
  18. <router-outlet></router-outlet>
  19. [ERROR ->]<footer-section></footer-section>"): AppComponent@3:2
  20.  
  21. import { Component, OnInit } from '@angular/core';
  22.  
  23. @Component({
  24. selector: 'my-app',
  25. moduleId: module.id,
  26. template: `
  27. <header-section></header-section>
  28. <router-outlet></router-outlet>
  29. <footer-section></footer-section>`
  30. })
  31.  
  32. export class AppComponent {
  33.  
  34. constructor() {}
  35.  
  36. test(): string {
  37. return 'this is a test';
  38. }
  39. }
  40.  
  41. import { Http, Request, RequestOptionsArgs, Response, XHRBackend, RequestOptions, ConnectionBackend, Headers } from '@angular/http';
  42. import { HttpIntercept } from '../../services/auth/auth.service';
  43.  
  44.  
  45. import { BrowserModule } from '@angular/platform-browser';
  46. import { HttpModule, JsonpModule } from '@angular/http';
  47. import { FormsModule } from '@angular/forms';
  48.  
  49. import { RouterTestingModule } from "@angular/router/testing";
  50. import { appRoutes } from '../../routes';
  51.  
  52. import { Cookie } from 'ng2-cookies/ng2-cookies';
  53.  
  54. import { AppComponent } from '../app/app.component';
  55. import { HeaderComponent } from './header.component';
  56. import { FooterComponent } from '../footer/footer.component';
  57. import { HomeComponent } from '../home/home.component';
  58. import { Four0FourComponent } from '../404/four0four.component';
  59. import { UserProfileComponent } from '../user-profile/user-profile.component';
  60.  
  61. import { UserService } from '../../services/user/user.service';
  62. import { ClockService } from '../../services/clock/clock.service';
  63. import { Observable } from 'rxjs/Observable';
  64.  
  65. import { TestBed, async, fakeAsync, tick } from '@angular/core/testing';
  66. import { By } from '@angular/platform-browser';
  67.  
  68. import { User } from '../../models/user/user.model';
  69.  
  70. class MockRouter { public navigate() { }; }
  71.  
  72. describe('HeaderComponent Test', () => {
  73. let fixture;
  74. let comp;
  75. let userService;
  76. let spy;
  77.  
  78. let user = new User({
  79. _id: 123456,
  80. userName: 'testName',
  81. firstName: 'testFirst',
  82. lastName: 'testLast',
  83. email: 'test@email.com',
  84. create: 'now',
  85. role: 'user'
  86. });
  87.  
  88. beforeEach(() => {
  89. TestBed.configureTestingModule({
  90. imports: [
  91. BrowserModule,
  92. HttpModule,
  93. FormsModule,
  94. JsonpModule,
  95. RouterTestingModule.withRoutes(appRoutes)
  96. ],
  97. declarations: [
  98. HomeComponent,
  99. UserProfileComponent,
  100. Four0FourComponent,
  101. FooterComponent,
  102. HeaderComponent,
  103. AppComponent
  104. ],
  105. providers: [
  106. {
  107. provide: Http,
  108. useFactory: (
  109. backend: XHRBackend,
  110. defaultOptions: RequestOptions) =>
  111. new HttpIntercept(backend, defaultOptions),
  112. deps: [XHRBackend, RequestOptions]
  113. },
  114. Cookie
  115. ]
  116. });
  117.  
  118. fixture = TestBed.createComponent(HeaderComponent);
  119. comp = fixture.componentInstance;
  120.  
  121. userService = fixture.debugElement.injector.get(UserService);
  122.  
  123. spy = spyOn(userService, 'getMe')
  124. .and.returnValue(Observable.of(user));
  125.  
  126. });
  127.  
  128. it('should instantiate component', () => {
  129. expect(fixture.componentInstance instanceof HeaderComponent).toBe(true);
  130. });
  131.  
  132. it('should not show currentUser before OnInit', () => {
  133. expect(spy.calls.any()).toBe(false, 'getMe not yet called');
  134. });
  135.  
  136. it('should still not show currentUser after component initialized', () => {
  137. // Set cookie token, for the getMe to call
  138. Cookie.set('token', 'test_token_alpha');
  139.  
  140. fixture.detectChanges();
  141. expect(spy.calls.any()).toBe(true, 'getMe called');
  142. });
  143.  
  144. //The problem test is bellow
  145. it('should show currentUser after getMe promise', fakeAsync(() => {
  146. fixture.detectChanges();
  147. tick();
  148. fixture.detectChanges();
  149. expect(comp.currentUser).toEqual(user);
  150. }));
  151. });
  152.  
  153. import { Component } from '@angular/core';
  154. import { Cookie } from 'ng2-cookies/ng2-cookies';
  155. import { Observable } from 'rxjs/Observable';
  156. import 'rxjs/add/observable/interval';
  157.  
  158. import { UserService } from '../../services/user/user.service';
  159. import { ClockService } from '../../services/clock/clock.service';
  160.  
  161. import { User } from '../../models/user/user.model';
  162.  
  163. @Component({
  164. selector: 'header-section',
  165. providers: [
  166. UserService,
  167. ClockService
  168. ],
  169. moduleId: module.id,
  170. template: `
  171. <style>
  172. header{
  173. background: rgb(55, 129, 215);
  174. position: relative;
  175. }
  176. .user-sign{
  177. position: absolute;
  178. top:0;
  179. right:0;
  180. margin: 23px 5%;
  181. }
  182. .app-title{
  183. font-family: cursive;
  184. padding: 15px;
  185. text-align: center;
  186. font-size: 36px;
  187. color: white;
  188. }
  189. .user-sign button:hover{
  190. cursor: pointer;
  191. }
  192. .active{
  193. color: orange;
  194. }
  195. </style>
  196. <header>
  197. <a routerLink='/' routerLinkActive='active'>Home</a>
  198. <a routerLink='/profile' routerLinkActive='active'>Profile</a>
  199. <a routerLink='/yoloswaq69420blazeitfgt' routerLinkActive='active'>404</a>
  200. <div class='user-sign'>
  201. <h3 *ngIf='currentUser'>Welcome, {{currentUser.userName}}</h3>
  202. <button *ngIf='!currentUser' type='button' (click)='testRegisterUser()'>Sign up</button>
  203. <button *ngIf='!currentUser' type='button' (click)='testUser()'>Sign in</button>
  204. <button type='button' (click)='logout()'>Sign out</button>
  205. </div>
  206. <h1 class='app-title'>MEA2N Fullstack</h1>
  207. </header>`
  208. })
  209.  
  210. export class HeaderComponent {
  211. errorMessage: string;
  212. public currentUser: User;
  213. clock = this.clockService.currentTime;
  214.  
  215. constructor(private userService: UserService, private clockService: ClockService) { }
  216.  
  217. ngOnInit() {
  218. let token = Cookie.get('token');
  219. if (token)
  220. this.userService.getMe().subscribe(user => this.currentUser = user);
  221. }
  222.  
  223. login(email: string, password: string) {
  224. this.userService.login(email, password)
  225. .subscribe(() => {
  226. return this.userService.getMe()
  227. .subscribe(user => {
  228. this.currentUser = user;
  229. })
  230. });
  231. }
  232.  
  233. logout() {
  234. this.userService.logout();
  235. this.currentUser = null;
  236. }
  237.  
  238. registerUser(username: string, email: string, password: string) {
  239. this.userService.signup(username, email, password)
  240. .subscribe(() => {
  241. return this.userService.getMe()
  242. .subscribe(user => {
  243. this.currentUser = user;
  244. })
  245. });
  246. }
  247.  
  248. testUser() {
  249. this.login('jc.thomas4214@gmail.com', 'flight1855');
  250. }
  251.  
  252. testRegisterUser() {
  253. this.registerUser('Jason', 'jc.thomas4214@gmail.com', 'flight1855');
  254. }
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement