npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

office-addin-mock

v4.0.1

Published

Provides mocking support for Office-js APIs

Readme

Office-Addin-Mock

This library makes it much easier to unit test the Office JavaScript API. It works with any JavaScript unit testing framework.

For details about the library and how to use it, see Unit testing in Office Add-ins.

Installation

Install office-addin-mock in the root of an add-in project with this command:

npm i office-addin-mock --save-dev

Examples

For basic examples that use the Jest framework, see Unit testing in Office Add-ins - Examples. Below are some examples using other frameworks.

Testing with Mocha for Excel platform

import { OfficeMockObject } from "office-addin-mock";

function run() {
  try {
    await Excel.run(async (context) => {
      const range: Excel.Range = context.workbook.getSelectedRange();
      range.load("address");

      // Update the cell color
      range.format.fill.color = "yellow";

      await context.sync();
      console.log(`The range address was ${range.address}.`);
    });
  } catch (error) {
    console.error(error);
  }
}

const MockData = {
  context: {
    workbook: {
      range: {
        address: "G4",
        format: {
          fill: {},
        },
      },
      getSelectedRange: function () {
        return this.range;
      },
    },
  },
  run: async function(callback) {
    await callback(this.context);
  },
};

describe(`Run`, function () {
  it("Excel", async function () {
    const excelMock = new OfficeMockObject(MockData) as any;
    global.Excel = excelMock;
    await run();
    assert.strictEqual(excelMock.context.workbook.range.format.fill.color, "yellow");
  });
});

Testing a function with Mocha for PowerPoint platform

import { OfficeMockObject } from "office-addin-mock";

async function run() {
  const options = { coercionType: Office.CoercionType.Text };

  await Office.context.document.setSelectedDataAsync(" ", options);
  await Office.context.document.setSelectedDataAsync("Hello World!", options);
}

const PowerPointMockData = {
  context: {
    document: {
      setSelectedDataAsync: function (data, options?) {
        this.data = data;
        this.options = options;
      },
    },
  },
  CoercionType: {
    Text: {},
  },
};

describe(`PowerPoint`, function () {
  it("Run", async function () {
    const officeMock = new OfficeMockObject(PowerPointMockData);
    global.Office = officeMock;

    await run();

    assert.strictEqual(officeMock.context.document.data, "Hello World!");
  });
});

Reference

OfficeMockObject class

Represents a mock Office object.

Constructor

The object parameter provides initial values for the mock object. (Optional) The host parameter identifies the host of the tests. (Optional)

constructor(object?: Object, host?: OfficeApp | undefined); 

Host can be any of the following:

OfficeApp {
  Excel = "excel",
  OneNote = "onenote",
  Outlook = "outlook",
  PowerPoint = "powerpoint",
  Project = "project",
  Word = "word",
}

Methods

load

Mock implementation of the load method in the application-specific Office.js APIs.

  • The propertyArgument specifies the properties that should be loaded.
load(propertyArgument: string | string[] | Object): void;
sync

Mock replacement for the sync method in the application-specific Office.js APIs.

sync(): void;