Currently, there is no documentation or any model to follow about unit testing and mocking with Office-js. Using standards approaches like Sinon or Jest proves challenging because office-js API needs to be loaded by an HTML file, making the API not available beforehand.
This issue also increases because some test APIs may require the entire object to be mocked, which can have more than 100 properties, making it not feasible.
There is also the issue of making the tests preserve the order of functions load or sync, which are very common to occur in the development and are difficult to test because stateless test APIs do not support easily adding state variables to handle those functions.
Having an easy and common approach, with an explanation of how to use it, would solve these problems, thus making unit testing/mocking office-js a quicker and easier experience.
Related issues:
- Overall Testing Story for Office Add-ins · Issue #584 · OfficeDev/office-js-docs-pr (github.com)
- Would you please provide information about Unit Test ? · Issue #1611 · OfficeDev/office-js-docs-pr (github.com)
We would like to get feedback and suggestions on your experience with unit testing/mocking office.js, as we plan on delivering a solution to help alleviate your problems. Here are some questions that we would like to understand with your feedback:
- Do you face difficulties when dealing with mocking office-js API?
- What would you like to help easier the unit testing experiences?
- What are some pain points you are facing?