0

jasmine 테스트 사양을 통해 크롬 브라우저에 viewport을 설정하려면 karma viewport npm 패키지를 사용하고 있습니다. 위에 제공된 링크의 지침을 따르고 있습니다. 그것은 아주 간단하지만 어쨌든 나는 그것을 얻을 수 없습니다.'뷰포트'이름을 찾을 수 없습니다

여기 내 karma.conf.js입니다. 나는 뷰포트를 컴파일러에 의해 표시

it('In mobile view, there should be three separate tabs to show daily, monthly and yearly savings', fakeAsync(() => { 

     component.scrollToCalc(); 
     // approximate time required to load the calculator with animation 
     tick(1000); 
     fixture.detectChanges(); 
     viewport.set(200, 300);  // viewport variable throws error 
     fixture.detectChanges(); 
    })); 

오류를 설정하려고

module.exports = function (config) { 
    config.set({ 
     basePath: '', 
     frameworks: ['jasmine', '@angular/cli', 'viewport'], 
     plugins: [ 
      require('karma-jasmine'), 
      require('karma-chrome-launcher'), 
      require('karma-remap-istanbul'), 
      require('@angular/cli/plugins/karma'), 
      require('karma-viewport') 
     ], 
     files: [ 
      { pattern: './src/test.ts', watched: false } 
     ], 
     preprocessors: { 
      './src/test.ts': ['@angular/cli'] 
     }, 
     mime: { 
      'text/x-typescript': ['ts','tsx'] 
     }, 
     remapIstanbulReporter: { 
      reports: { 
       html: 'coverage', 
       lcovonly: './coverage/coverage.lcov' 
      } 
     }, 
     angularCli: { 
      config: './angular-cli.json', 
      environment: 'dev' 
     }, 
     reporters: config.angularCli && config.angularCli.codeCoverage 
      ? ['progress', 'karma-remap-istanbul'] 
      : ['progress'], 

     htmlReporter: { 
      outputFile: 'unit_test/report.html', 

      //Optional 
      pageTitle: 'Unit Tests', 
      subPageTitle: 'This file includes all unit test cases segmented according to their suites.', 
      groupSuites: true 
     }, 

     port: 9876, 
     colors: true, 
     logLevel: config.LOG_INFO, 
     autoWatch: true, 
     browsers: ['Chrome'], 
     singleRun: false 
    }); 
}; 

테스트 사양.

'뷰포트'라는 이름을 찾을 수 없습니다.

이 작업을 수행하려면 TestBed 구성 내에서 추가 변경을 수행 할 필요가 없습니다. 어떤 viewport 변수가 내 spec 파일에 노출되지 않습니다.

답변

0

귀하의 karma.conf가 좋아 보이는군요 - 귀하의 플러그인에 요구 사항이 &으로 표시되어 있습니다. 당신 사양의 시작 부분에 뷰포트를 선언하십시오 :

declare const viewport; 
describe('My Test',() => { 
... 
}); 

내가 카르마 - 뷰포트 프레임 워크는 순수 자바 스크립트로 작성하고, 타이프 스크립트 컴파일러가에 대한 지식을 가지고 있지 않기 때문에이 문제가 발생하는 이유는 믿습니다. spec 파일의 상단에 선언함으로써 본질적으로 typescript 컴파일러에게 "저를 믿으십시오, this exists and available"라고 말하고 있습니다.

관련 문제