Guest User

Untitled

a guest
Nov 13th, 2017
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. Error: Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?, ?).
  2.  
  3. import 'rxjs/add/operator/map';
  4. import { Http, BaseRequestOptions, Response, ResponseOptions,ConnectionBackend } from '@angular/http';
  5. import { MockBackend, MockConnection } from '@angular/http/testing';
  6. import { GlobalUtils } from './global.utils';
  7. import { Router} from '@angular/router';
  8.  
  9. import { TestBed, inject } from '@angular/core/testing';
  10.  
  11.  
  12.  
  13. describe('Global Utils : Meta urls API', () => {
  14. let emptyMetaUrl = {};
  15.  
  16. let metaUrl = {
  17. LOGIN: '/operator/login',
  18. META_API: '/meta-api'
  19. };
  20.  
  21. beforeEach(()=>TestBed.configureTestingModule({
  22.  
  23. providers: [
  24. Router,
  25. GlobalUtils,
  26. BaseRequestOptions,
  27. MockBackend,
  28. {
  29. provide: Http,
  30. useFactory: function (backend:ConnectionBackend, defaultOptions:BaseRequestOptions) {
  31. return new Http(backend, defaultOptions);
  32. },
  33. deps: [MockBackend, BaseRequestOptions]
  34. },
  35.  
  36. ]
  37. }));
  38.  
  39.  
  40. let subject:GlobalUtils = null;
  41. let backend:MockBackend = null;
  42. let http:Http = null;
  43.  
  44. beforeEach(inject([GlobalUtils, MockBackend, Http], (_globalUtils:GlobalUtils, mockBackend:MockBackend,_http:Http) => {
  45. subject = _globalUtils;
  46. backend = mockBackend;
  47. http = _http;
  48. }));
  49.  
  50. it('Should have get Meta urls', (done) => {
  51.  
  52. backend.connections.subscribe((connection:MockConnection)=> {
  53. let options = new ResponseOptions({
  54. body: JSON.stringify(metaUrl)
  55. });
  56. connection.mockRespond(new Response(options));
  57. });
  58.  
  59. http
  60. .get(subject.metaUrl)
  61. .subscribe((response) => {
  62.  
  63. subject.getMetaUrls(); // in this routing is use
  64.  
  65. expect(GlobalUtils.saveUrl).toEqual(metaUrl);
  66. done();
  67. });
  68.  
  69. });
  70.  
  71. });
  72.  
  73. import {Injectable} from '@angular/core';
  74. import { Router} from '@angular/router';
  75. import {Http, Headers,Response} from '@angular/http';
  76. import 'rxjs/add/operator/map';
  77. import 'rxjs/add/operator/catch';
  78.  
  79. @Injectable()
  80. export class GlobalUtils {
  81. static saveUrl = { };
  82.  
  83. head:Headers = new Headers();
  84. hostUrl:string = 'http://192.168.0.103:8000/';
  85. metaUrl:string = 'urls-metadata/';
  86.  
  87. // constructor declare
  88. constructor(public _http:Http,public _router:Router) {
  89. this.head.append('Content-Type', 'application/json');
  90. }
  91.  
  92. /*
  93. * this function is used for Http GET Request
  94. * */
  95. urlGet(url:string) {
  96. let headers = this.head;
  97. return this._http.get(this.hostUrl + url, {headers: headers})
  98. .map(res => res.json())
  99. .map((res) => {
  100. return res;
  101. });
  102. }
  103.  
  104. /*
  105. * this function is used to GET all API url
  106. * */
  107. getMetaUrls():any{
  108. let url = this.metaUrl;
  109. this.urlGet(url).subscribe(
  110. (result) => {
  111. console.log('result = '+JSON.stringify(result));
  112. if (result) {
  113. GlobalUtils.saveUrl = result;
  114. console.log('get Meta urls response = '+ result.status)
  115. }
  116. },
  117.  
  118. (error)=> {
  119. this._router.navigate(['page-error']);
  120. console.log('get Meta urls error = '+ error.status + " data =" +JSON.stringify(error))
  121. },
  122.  
  123. ()=>{console.log('get Meta url is successfully')}
  124.  
  125. );
  126. }
  127.  
  128.  
  129.  
  130. }
  131.  
  132. ✖ Should have get Meta urls
  133. Chrome 52.0.2743 (Linux 0.0.0)
  134. Error: Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?, ?).
  135. at CompileMetadataResolver.getDependenciesMetadata (webpack:///~/@angular/compiler/bundles/compiler.umd.js:14404:0 <- config/spec-bundle.js:53297:22)
  136. at CompileMetadataResolver.getTypeMetadata (webpack:///~/@angular/compiler/bundles/compiler.umd.js:14301:0 <- config/spec-bundle.js:53194:29)
  137. at webpack:///~/@angular/compiler/bundles/compiler.umd.js:14448:0 <- config/spec-bundle.js:53341:44
  138. at Array.forEach (native)
  139. at CompileMetadataResolver.getProvidersMetadata (webpack:///~/@angular/compiler/bundles/compiler.umd.js:14428:0 <- config/spec-bundle.js:53321:22)
  140. at CompileMetadataResolver.getNgModuleMetadata (webpack:///~/@angular/compiler/bundles/compiler.umd.js:14181:0 <- config/spec-bundle.js:53074:61)
  141. at RuntimeCompiler._compileComponents (webpack:///~/@angular/compiler/bundles/compiler.umd.js:16803:0 <- config/spec-bundle.js:55696:50)
  142. at RuntimeCompiler._compileModuleAndAllComponents (webpack:///~/@angular/compiler/bundles/compiler.umd.js:16747:0 <- config/spec-bundle.js:55640:40)
  143. at RuntimeCompiler.compileModuleAndAllComponentsSync (webpack:///~/@angular/compiler/bundles/compiler.umd.js:16735:0 <- config/spec-bundle.js:55628:24)
  144. at TestingCompilerImpl.compileModuleAndAllComponentsSync (webpack:///~/@angular/compiler/bundles/compiler-testing.umd.js:758:0 <- config/spec-bundle.js:38833:36)
  145.  
  146. let mockRouter = {
  147. navigate: jasmine.createSpy('navigate')
  148. }
  149.  
  150. TestBed.configureTestingModule({
  151. providers: [
  152. { provide: Router, useValue: mockRouter }
  153. ]
  154. })
  155.  
  156. expect(mockRouter.navigate).toHaveBeenCalledWith(['/router']);
  157.  
  158. import { RouterTestingModule } from '@angular/router/testing';
  159.  
  160. TestBed.configureTestingModule({
  161. imports: [
  162. RouterTestingModule.withRoutes([{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])
  163. ]
  164. })
Add Comment
Please, Sign In to add comment