Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 没有用于TestingCompilerFactory的提供程序_Javascript_Angular_Typescript_Angular Test - Fatal编程技术网

Javascript 没有用于TestingCompilerFactory的提供程序

Javascript 没有用于TestingCompilerFactory的提供程序,javascript,angular,typescript,angular-test,Javascript,Angular,Typescript,Angular Test,这是我的测试文件,我正在尝试识别阻止我运行成功测试的错误: import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Component, Directive, Input, OnInit } from '@angular/core'; import { TestComponent } from './test.component'; import { NgbDropdownMod

这是我的测试文件,我正在尝试识别阻止我运行成功测试的错误:

    import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Directive, Input, OnInit } from '@angular/core';
import { TestComponent } from './test.component';
import { NgbDropdownModule, NgbCollapse } from '@ng-bootstrap/ng-bootstrap';
import { CommonModule } from '@angular/common';
import { Routes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';

import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';


let comp: TestComponent;
let fixture: ComponentFixture<MyComponent>;

describe('TestComponent', () => {
   beforeEach(() =>  {
      TestBed.configureTestingModule({
        declarations: [ TestComponent ],
        providers: [
           // DECLARE PROVIDERS HERE
          { provide: TestingCompilerFactory }
        ]
      }).compileComponents()
      .then(() => {
        fixture = TestBed.createComponent(TestComponent);
        comp    = fixture.componentInstance;
      });
    }));
    it('should be created', () => {
      expect(TestComponent).toBeTruthy();
    });
但我也有

No provider for TestingCompilerFactory

首先修复语法错误1,2

现在,我们来看一个值得注意的错误

提供者可以采取两种形式

第一个是一个值,它既是提供的值,也是注册它的密钥。这通常采用类的形式,如下例所示

const Dependency = class {};

@NgModule({
  providers: [Dependency]
}) export default class {}
第二个是具有
provide
属性的对象,该属性指定提供程序注册的密钥,以及一个或多个附加属性,指定所提供的值。一个简单的例子是

const dependencyKey = 'some key';
const Dependency = class {};

@NgModule({
  providers: [
    {
      provide: dependencyKey,
      useClass: Dependency
    }
  ]
}) export default class {}
从上面可以推断,您未能指定键
TestingCompilerFactory
下提供的实际值

要解决此问题,请编写

TestBed.configureTestingModule({
  declarations: [TestComponent],
  providers: [
      {
        provide: TestingCompilerFactory,
        useClass: TestingCompilerFactory
      }
    ]
})
这是多余的,可以用

TestBed.configureTestingModule({
  declarations: [TestComponent],
  providers: [TestingCompilerFactory]
})
如上所述

注释

  • 以后不要发布包含如此明显错误的问题,而是自己修复

  • 不要把两个问题放在一起


  • 我认为这样的语法会阻止您的代码编译,所以完全不清楚您在问什么。您认为语法有什么错误?
    TestBed.configureTestingModule({
      declarations: [TestComponent],
      providers: [
          {
            provide: TestingCompilerFactory,
            useClass: TestingCompilerFactory
          }
        ]
    })
    
    TestBed.configureTestingModule({
      declarations: [TestComponent],
      providers: [TestingCompilerFactory]
    })