简体   繁体   中英

How can I create a spy on a third party library with nested object - Excel.Workbook.xlsx.WriteFile()

I am using a third party npm library - exceljs to generate excel reports. The library has a function to write the generated file to disk.

Here is some code snippet

const workbook: Excel.Workbook = new Excel.Workbook();
// code to generate the report - not an issue

workbook.xlsx.writeFile(path).then(...).catch(...)

My question is how can I spy on writeFile() using jasmine?

The solution turns out that I need to create a spy object on the constructor Excel.Workbook(). This should give me the object to spy on the methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM