mardi 3 novembre 2020

Jasmine: Is there a way to moch a locally used service?

I am fairly new to Angular and Jasmine testing, so I am trying to check if this method works correctly, but I need to mock XmlReaderService, it is used only locally, how could I mock this? I would expect something with spyOn but cannot get my head around it...

  private getElementSettings() {
    const xmlReader = new XmlReaderService(this.logger)
    xmlReader.requestXml(this.xmlServiceUrl + this.settingsFileName).then(() => {
      this.elementSettings = xmlReader.xmlJsoned['element_settings']
      this.getElementTypes()
      this.getElementList()
      this.getMonitors()
    }).catch((reason) => {
      this.logger.error('XML Request failed in getElementSettings()!')
      this.logger.info(reason, '[' + this.constructor.name + ']')
      this.delegate.errorCallback(650, 'XML Request failed - could not get smart home element definitions (ElementSettings.xml)', reason)
    })
  }

Aucun commentaire:

Enregistrer un commentaire