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

TypeError: context.log.warn is not a function #295

Closed
rukasakurai opened this issue Apr 14, 2020 · 4 comments
Closed

TypeError: context.log.warn is not a function #295

rukasakurai opened this issue Apr 14, 2020 · 4 comments

Comments

@rukasakurai
Copy link

rukasakurai commented Apr 14, 2020

Repro steps

  1. For ah httpTrigger Azure Function written in TypeScript
  2. Add context.log.warn("xxx"); to the code
  3. Run a unit test on the function using jest

Expected behavior

The expected behavior is that the unit test passes.

Actual behavior

TypeError: context.log.warn is not a function

@rukasakurai
Copy link
Author

Here's some sample code that reproduces the error when running npm test to execute the jest unit tests on the code:
https://github.com/rukasakurai/azure-functions-httptrigger-typescript-sample

@mhoeger
Copy link
Contributor

mhoeger commented Apr 27, 2020

Hi @rukasakurai, it looks like your original issue is resolved but I can keep this issue open to track better support for unit tests? Please note though that we likely won't publish those as there are many different testing frameworks and will rely on other folks to contribute (example: https://www.npmjs.com/package/azure-function-context-mock)

@ThaddeusJiang
Copy link

Hi @rukasakurai @mhoeger

It works.

const context = {
  log: jest.fn(),
}

context.log.warn = jest.fn();

@ejizba
Copy link
Contributor

ejizba commented Jan 28, 2022

Closing in favor of #515 and #120

@ejizba ejizba closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants