Angular 2 RC6: 'pattern-list' is not a known element

后端 未结 3 1467
长发绾君心
长发绾君心 2021-01-05 17:56

Simply running the application I get no error and it works just fine, but when I run my tests I get the following error:

\'pattern-list\' is not a known elem         


        
相关标签:
3条回答
  • 2021-01-05 18:11

    I think you need

    TestBed.configureTestingModule({imports: [AppModule]});
    
    0 讨论(0)
  • 2021-01-05 18:18

    The current approach to avoid these errors when testing components is to make their tests shallow. As per the official docs:

    Add NO_ERRORS_SCHEMA to the testing module's schemas metadata to tell the compiler to ignore unrecognized elements and attributes. You no longer have to declare irrelevant components and directives.

    So you can simply import NO_ERRORS_SCHEMA and add it to your testing module config:

    import { NO_ERRORS_SCHEMA } from '@angular/core';
    
    TestBed.configureTestingModule({
      schemas: [ NO_ERRORS_SCHEMA ]
    })
    

    But be aware of:

    Shallow component tests with NO_ERRORS_SCHEMA greatly simplify unit testing of complex templates. However, the compiler no longer alerts you to mistakes such as misspelled or misused components and directives.

    0 讨论(0)
  • 2021-01-05 18:27

    As micronyks mentined in his answer I need to add my other dependencies in the declarations of configureTestingModule. So if I modify my module configuration in the test like this:

    TestBed.configureTestingModule({declarations: [AppComponent,PatternListComponent]});
    

    it'll work. It seems you need to add every dependency in the configureTestingModule declaration.

    0 讨论(0)
提交回复
热议问题