Are there any common practices, frameworks or patterns for unit testing office.js based code? Given the large number of the components in thr object model, it's impossible to mock calls to office.js. Is there something like a karma launcher to launch test code in to a test container task pane app? Anybody has worked out an effective way to test code that interact with office.js?
I think you should unit test Office.js based code the same way you would do for "standard" javascript code. Indeed, Office.js is just another javascript dependency like JQuery etc.
Of course you should not include Office.js in your test page and replace Office object by a mock. You can have a look at Sinon Js a javascript mocking framework.
When you write unit test, you isolate a piece of code (a class or a module) which is called the System Under Test (SUT). If you based your addin on a Single Page Application framework such as Angular, a SUT can be a controller. Then you can inject the Office object as a dependency, in real context this will be the real Office from Office.js. In test, this will be a mock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With