3

I am new to Karma with Angular 8. I have few queries and I am not getting correct result.

My queries are:

1) I have karma conf file where I have configured for code Coverage to view in HTML coverage directory was created but I am not seeing statement percentage and etc in the HTML page.

Here is my karma-config code

 config.set({
  basePath: '',
  frameworks: ['jasmine', '@angular-devkit/build-angular'],
  plugins: [
    require('karma-jasmine'),
    require('karma-chrome-launcher'),
    require('karma-jasmine-html-reporter'),
    require('karma-coverage-istanbul-reporter'),
    require('@angular-devkit/build-angular/plugins/karma')
  ],
  client: {
    clearContext: false // leave Jasmine Spec Runner output visible in browser
  },
  coverageIstanbulReporter: {
    dir: require('path').join(__dirname, '../coverage/my-app'),
    reports: ['html', 'lcovonly', 'text-summary'],
    fixWebpackSourcePaths: true
  },
  reporters: ['progress', 'kjhtml'],
  port: 9876,
  colors: true,
  logLevel: config.LOG_INFO,
  autoWatch: true,
  browsers: ['Chrome'],
  singleRun: false
});

enter image description here

2) As I am new to unit testing I want to understand how to do unit testing for the below method

navigateToStudy(row){
 this.favoriteUserId = row.id;
 this.router.navigate(['studydetails', row.id]);
}

Here is what I am trying for this code.

My Spec

describe('navigatetoStudy', () => {
   it('should navigate', () =>{
    const navigate  = navigateToStudy();
    expect(navigate).toBe
   });
});

I am getting error at navigatetoStudy.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mr.M
  • 1,472
  • 3
  • 29
  • 76
  • I presume `navigateToStudy()` is a method on a component, but in your test you're just calling it as a standalone function. You need to create the component in your test. – Collierre Jan 12 '20 at 15:34
  • @Collierre thanks for the reply can you please let me know how to do because I am new to Jasmine – Mr.M Jan 12 '20 at 15:38
  • @Mahadevan For a start, you should take a look at the documentation for how to test your app: https://angular.io/guide/testing – Edric Jan 12 '20 at 15:45
  • @Edric thanks for the reply will check the documentation. is that possible can you please let me know why I am not getting statements and other value please let me know – Mr.M Jan 12 '20 at 15:47

0 Answers0