2

Hi I am writing unit test case for my angular code in Jasmine. I have modal in my popup. On button click I am opening modal.

Below is my component code.

//declaration
    @ViewChild('editorModal')
    editorModal: ModalDirective;
//button click
     addScope() {
        this.formResetToggle = false;
        setTimeout(() => {
            this.formResetToggle = true;
            this.scopeEdit = new Scope();
            this.scopeEdit.scopevalue = '';
            this.editorModal.show();
        });
    }

Below is my html code.

  <div class="modal fade" bsModal #editorModal="bs-modal" tabindex="-1" id="myModal" role="dialog" aria-labelledby="myModalLabel">
  </div>

Below is my unit test.

 it('open popup to add scope', () => {
        component.addScope();
        expect(component.editorModal.show).toHaveBeenCalled(); //error
 });

I am trying to write assert statements to make sure my modal has been opened. can someone help me to make above code work? Any help would be appreciated. Thank you

Protozoid
  • 1,207
  • 1
  • 8
  • 16
Niranjan
  • 537
  • 2
  • 14
  • 31

0 Answers0