Angular test fails because Component is part of the declarations of 2 modules : <p>I am creating some tests in Angular 4. I have a component that is using PrettyJsonCompont in order to show well formatted json to the user. </p>

<p>When I run ng test several of my component tests fail with the same message. </p>

<blockquote>
  <p>Failed: Type PrettyJsonComponent is part of the declarations of 2
  modules: PrettyJsonModule and DynamicTestModule! Please consider
  moving PrettyJsonComponent to a higher module that imports
  PrettyJsonModule and DynamicTestModule. You can also create a new
  NgModule that exports and includes PrettyJsonComponent then import
  that NgModule in PrettyJsonModule and DynamicTestModule.</p>
</blockquote>

<p>Here is what my test looks like. </p>

<pre><code>import {async, ComponentFixture, TestBed} from '@angular/core/testing';

import {ContentItemModalComponent} from './content-item-modal.component';
import {DialogService} from 'ng2-bootstrap-modal';
import {ContentItemService} from '../services/content-item.service';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {FroalaEditorModule, FroalaViewModule} from 'angular-froala-wysiwyg';
import {HttpModule} from '@angular/http';
import {MainModel} from '../models/main-model';
import {PrettyJsonComponent, PrettyJsonModule} from 'angular2-prettyjson';

describe('ContentItemModalComponent', () =&gt; {
  let component: ContentItemModalComponent;
  let fixture: ComponentFixture&lt;ContentItemModalComponent&gt;;

  beforeEach(async(() =&gt; {
    TestBed.configureTestingModule({
      imports: [
        ReactiveFormsModule,
        FormsModule,
        FroalaEditorModule.forRoot(),
        FroalaViewModule.forRoot(),
        HttpModule,
        PrettyJsonModule
      ],
      declarations: [ContentItemModalComponent, PrettyJsonComponent],
      providers: [
        DialogService,
        ContentItemService,
        MainModel
      ],
    })
      .compileComponents();
  }));

  beforeEach(() =&gt; {
    fixture = TestBed.createComponent(ContentItemModalComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should be created', () =&gt; {
    expect(component).toBeTruthy();
  });
});
</code></pre>
