Тест кармы не будет запущен, несмотря на то, что определен файл .spe c .ts - PullRequest
0 голосов
/ 05 февраля 2020

Я пытаюсь запустить тесты кармы в моем приложении Ng. Я просматриваю это видео: https://www.youtube.com/watch?v=BumgayeUC08

У меня есть файл spe c, определенный ниже, в нескольких подпапках моей папки sr c src/app/pages/class-grid/class-grid.component.spec.ts

import 'jasmine';
import {TestBed, getTestBed, ComponentFixture, async} from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';

import { ClassGridComponent } from './class-grid.component';
import {DebugElement} from '@angular/core';

describe('ClassGridComponent', () => {
  let component: ClassGridComponent;
  let fixture: ComponentFixture<ClassGridComponent>;
  let de: DebugElement;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ClassGridComponent]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ClassGridComponent);
    component = fixture.componentInstance;
    de = fixture.debugElement;

    fixture.detectChanges();
  });

  it('should created', () => {
    expect(true).toBeTruthy();
  });
});

Мой файл karma.conf. js содержит все значения по умолчанию

// Файл конфигурации Karma, см. Ссылку для получения дополнительной информации // https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  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'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

Аналогично test.ts

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

Когда я запускаю ng test, это вывод, который я получаю

ERROR in src/app/services/auth/auth.service.ts(8,23): error TS2503: Cannot find namespace 'gapi'.
src/app/services/auth/auth.service.ts(9,21): error TS2503: Cannot find namespace 'gapi'.
src/app/services/auth/auth.service.ts(10,21): error TS2503: Cannot find namespace 'gapi'.
src/app/services/auth/auth.service.ts(56,7): error TS2304: Cannot find name 'gapi'.
src/app/services/auth/auth.service.ts(58,9): error TS2304: Cannot find name 'gapi'.

05 02 2020 15:01:45.222:INFO [Chrome 79.0.3945 (Windows 10 0.0.0)]: Connected on socket pWJmMw8qYTosCufeAAAA with id 42341007
Chrome 79.0.3945 (Windows 10 0.0.0): Executed 0 of 0 ERROR (0.014 secs / 0 secs)

Я не уверен Если Cannot find name 'gapi' является проблемой, приложение работает должным образом, когда я использую ng serve, а gapi вообще не упоминается, пока я не запускаю ng test.

Я пробежал npm i, это ничего не изменило.

...