Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Mocking external library with callbacks in Jasmine

I have an Angular component which uses the AWS connect-streams library. However I am having problems trying to mock this library for unit test purposes.

In my component.ts file I have the following:

public ngOnInit() {    
  connect.core.initCCP(el, {
    ccpUrl: this.ccpUrl,
    loginPopup: false,
    loginPopupAutoClose: true,
  });
  connect.contact((contactSessionObj) => {
    contactSessionObj.onIncoming((_evt) => {
      this.onIncomingHandler(_evt, contactSessionObj);
    });
    contactSessionObj.onConnected((_evt: any) => {
      this.onConnectedHandler(_evt, contactSessionObj);
    });
  });

private onIncomingHandler(_evt, _contact) {
  if (this.isClosed) {
    this.toggleWindow();
  }
}
   
private onConnectedHandler(_evt, contact) {
  const contactAttributes = contact.getAttributes();
  const phoneNumber = contactAttributes.phoneNumber.value;
}

I am trying to mock the connect object but cannot work out the structure that would enable me to test that this.onIncomingHandler() and this.onConnectedHandler() are called when the onIncoming and onConnected callbacks are invoked. This is where I'm at but I realise this approach doesnt quite line up:

window['connect'] = {
  core: {
    initCCP: () => { },
  },
  contact: () => {
    const contactObj = {};
    contactObj['onIncoming'] = (cb) => { cb(); };
    contactObj['onConnected'] = (cb) => { cb(); };
    return contactObj;
  }
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!