Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request Office-Addin-Mock support CustomFunctions.Error #733

Open
mcshaz opened this issue Jan 9, 2023 · 1 comment
Open

feature request Office-Addin-Mock support CustomFunctions.Error #733

mcshaz opened this issue Jan 9, 2023 · 1 comment

Comments

@mcshaz
Copy link

mcshaz commented Jan 9, 2023

In an excel custom functions add in, I have to add a CustomFunctions.Error function to the global scope before running tests. I am using the following code (which I am not suggesting is sufficient to cover the use cases for the broad range of users) which gives a brief outline of another module which could be useful if added to the Office-Addin-Mock package:

enum ErrorCode {
  invalidValue = "#VALUE!",
  notAvailable = "#N/A",
  divisionByZero = "#DIV/0!",
  invalidNumber = "#NUM!",
  nullReference = "#NULL!",
  invalidName = "#NAME?",
  invalidReference = "#REF!",
}

class CustomFunctionError extends Error {
  constructor(readonly code: ErrorCode, message?: string) {
    super(message);
  }
}

const CustomFunctions = {
  Error: CustomFunctionError,
  ErrorCode: ErrorCode,
  associate: () => undefined,
};

and it is used something like (mocha/chai):

describe("myFunction", function () {
  global.CustomFunctions = CustomFunctions;
  it("throws an error when the string argument is empty", function () {
    expect(() => myFunction("", [[["a"]]])).to.throw(/require/i);
'''
@rhdhvolschenk
Copy link

The office-addin-mock package does not provide one of the available enums in the Office namespace.
This means that each one you use in code has to be mocked before being able to run tests. Silly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants