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?
Here's what I ended up doing:
- Added a new Task Pane App project to the solution
- Included the Jasmine Standalone zip from https://github.com/jasmine/jasmine/releases
- Made TaskPane app's Manifest Source Location point to the SpecRunner.html
- Modified boot.js to replace the execution of test specs on window.load to execute on Office.initilize.
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.
Here's what I ended up doing:
- Added a new Task Pane App project to the solution
- Included the Jasmine Standalone zip from https://github.com/jasmine/jasmine/releases
- Made TaskPane app's Manifest Source Location point to the SpecRunner.html
- Modified boot.js to replace the execution of test specs on window.load to execute on Office.initilize.
© 2022 - 2024 — McMap. All rights reserved.