Sush
Sush

Reputation: 317

How to print log during karma Testing

I am a beginner for Angular, recently I started working on Angular. I have written some unit testing code, as follows.

it('fetch data should be correct',
inject(
  [HttpTestingController, Service2Service],
  (
    httpMock: HttpTestingController,
    dataService: Service2Service
  ) =>{
        dataService.getData().subscribe((event: HttpEvent<any>) => {
          console.info("HttpEventType.Response",HttpEventType.Response);
          switch (event.type) {
            case HttpEventType.Response:{
              console.log("body",event.body);
              expect(event.body.length).toEqual(110);
            }
          }
        });
      }
  )

);

I am trying to print using console.log but it not printing on console. Kindly suggest another way to print log.

Thanks in advance.

Upvotes: 6

Views: 11524

Answers (1)

Pardeep Jain
Pardeep Jain

Reputation: 86730

Try by putting captureConsole to property client in karma.conf.js:

client: {
      captureConsole: true,
      mocha: {
        bail: true
      }
    }

For more info refer -

Upvotes: 7

Related Questions