2

while writing jasmine unit test case for one of my angular 2 component, if I add CookieService in provider list then all remaining other component unit test cases are failing. If I remove CookieService from provider list then test cases are working fine. You can check this at plunker cookiservice unit test.my component spec file code:

import {setBaseTestProviders} from 'angular2/testing';
import {beforeEachProviders,beforeEach,describe,expect,it} from 'angular2/testing';
import {MyComponent} from '../src/my.component';
import {CookieService} from 'angular2-cookie/core';

describe('MyComponent', () => {  
  beforeEach(() => {
    setBaseTestProviders(CookieService);
})  
it('sample test', () => {
       expect('test').toEqual('test');
});    
});
  • At a guess, CookieService requires the rest of its module to work correctly. Why not inject a test double of it instead, `{ provide: CookieService, useValue: ... }`? Also your setup seems a bit weird, what's with the wrapper functions and why set up the test bed in two separate places? – jonrsharpe Sep 05 '17 at 06:33
  • even I tried stub value like { provide: CookieService, userValue: cookieserviceStub }, but still same issue. For readability called TestBed two times. – Srikanth Pallerla Sep 05 '17 at 06:56
  • ...and what *is* that issue? Give a [mcve] including the failure/error. And FWIW the unconventional structure, especially with inconsistent indentation, makes it much *less* readable to me. – jonrsharpe Sep 05 '17 at 07:05
  • I added minimal code. you can try this spec file. if you remove CookieService from provider, test case will success. if CookieService is there then test case will fail. – Srikanth Pallerla Sep 06 '17 at 09:18

0 Answers0