Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda