我有一个使用NgbDropdown
的组件,并且正在为我的组件编写组件测试。我遇到了错误。
Failed: Cannot read property 'placement' of undefined
TypeError: Cannot read property 'placement' of undefined
at new NgbDropdown node_modules/@ng-bootstrap/ng-bootstrap/dropdown/dropdown.js:130:1)
at createClass node_modules/@angular/core/esm5/core.js:12423:1)
at createDirectiveInstance node_modules/@angular/core/esm5/core.js:12266:22)
at createViewNodes node_modules/@angular/core/esm5/core.js:13727:38)
at callViewAction node_modules/@angular/core/esm5/core.js:14161:1)
at execComponentViewsAction node_modules/@angular/core/esm5/core.js:14070:1)
at createViewNodes node_modules/@angular/core/esm5/core.js:13755:1)
at createRootView node_modules/@angular/core/esm5/core.js:13616:1)
at callWithDebugContext node_modules/@angular/core/esm5/core.js:15041:26)
at Object.debugCreateRootView [as createRootView] node_modules/@angular/core/esm5/core.js:14324:1)
这是我的组件规格
describe("SomeComponent", () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
],
imports: [
NgbDropdownModule,
HttpClientTestingModule,
],
providers: [
{provide: Router},
{provide: NgbModal},
{provide: NgbDropdownConfig}
],
// schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
let fixture = TestBed.createComponent(SomeComponent);
let component = fixture.componentInstance;
let httpMock = TestBed.get(HttpTestingController);
}));
it("should create the app", () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});
相关组件html
<div ngbDropdown>
<button ngbDropdownToggle>Choices</button>
<div ngbDropdownMenu>
<a>item choice</a>
</div>
</div>