I developed a plugin for Microsoft Office utilizing the Office.js libraries and TypeScript. Currently, I'm employing Jest for unit testing purposes.
An obstacle I've encountered involves @types/office-js
defining type definitions with everything existing behind global objects like Office
and Word
. Creating fake or mock implementations presents challenges due to conflicts with these type definitions. Moreover, attempts to directly import or utilize Jest mock on @microsoft/office-js
proves tricky as it's not a genuine module but rather intended to be loaded by the browser through a script tag. Consequently, when running Jest, my newly introduced global namespaces fail to resolve - resulting in a
ReferenceError: Word is not defined
.
The following represents a simplified outline of my goals:
// __mocks__/word.ts
//@ts-ignore
export namespace Word {
// implementation details
}
// __tests__/something.ts
it('should detect Word', () => Word...);
Is there a way for me to effectively create fakes/mocks to successfully test the calls?