0

I have the following component

<app-modal-default #confirmDelete>
<span class="title">Delete Confirmation</span>
<span class="modal-body-content">Do you want to delete all the data related to shipping, distribution and storage?
</span>
<div class="modal-actions">
    <button class="btn btn-danger" (click)="confirmDeleteOk()">Delete</button>&nbsp;
    <button class="btn-default btn" (click)="close(confirmDelete)">
        Cancel
    </button>
</div>

I have a view child declared in .ts file

@ViewChild('confirmDelete') confirmDelete: ModalDefaultComponent;

This view child iam closing in this function

confirmDeleteOk(): void {
 this.hTstore$.dispatch(new fromHTAction.DeleteWMS());
 this.close(this.confirmDelete);
}

This is my test file

it('Calling WMS delete through dispatch Action Should work as expected', fakeAsync((done) => {
 component.confirmDeleteOk();
 storeSpy.dispatch(new DeleteWMS());
 expect(storeSpy.dispatch).toHaveBeenCalledWith(new DeleteWMS()); }));

iam getting an test error

TypeError: element.close is not a function

how to write test for view child for my element.close , how i can define element ?

Shabeer M
  • 160
  • 3
  • 9
  • Do you have `app-modal-default` added to `declarations` array? – AliF50 Jun 01 '21 at 14:49
  • No, How can i do that this is my spec file before each `code` beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [DeleteDataComponent], imports: [ToastrModule.forRoot({})], providers: [ToastrService, provideMockStore({ selectors: [ { selector: selectWMSDeleterror, value: null }, { selector: selectWMSDeleteCompleted, value: null } ], }) ], }) .compileComponents(); }); – Shabeer M Jun 02 '21 at 07:20
  • In the `declarations` array, add `ModalComponent` or whatever the class name is. – AliF50 Jun 02 '21 at 12:35

0 Answers0