Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you unit test office.js app code?

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?

like image 296
Sameera Avatar asked Nov 01 '16 16:11

Sameera


1 Answers

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.

like image 192
Benoit Patra Avatar answered Oct 18 '22 02:10

Benoit Patra