
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
stub-azure-function-context
Advanced tools
Provides an object similar to Function Runtime's context for use in unit testing
Aims to implement the context object as described on the Azure Functions JavaScript Developer Guide.
By default the behaviour assumes a req
HTTP trigger and a res
HTTP output, but if you have more exotic config, then
you can set that up!
If you follow the "ordered argument" pattern then you'll need to define the triggers/outputs in the same order
as in your function.json
.
From 1.0.3 this library supports endpoint handlers returning Promise objects, and by extension, the async/await style.
stubContext
resolves with an object containing:
{
context: context, // the actual stubbed context object after your function manipulates it
err: null|Error, // any error thrown or passed to context.done; eg: context.done(new Error("Oops"))
propertyBag: {}, // object of any overrides you want to make on your outputs
}
By default, logging uses console
as a backend, although you can import and use setContextLogger
to set your own.
Only the methods defined in the developer guide are available in the stubContext
call:
error
warn
info
verbose
const { stubContext, setContextLogger } = require('stub-azure-function-context');
const functionToTest = require('../function-under-test');
// Optional step to direct context.log output elsewhere:
const logger = require('./your-own-logger');
setContextLogger(logger);
describe('app code', () => {
it('returns 200', async () => {
const { context, err, propertyBag, } = await stubContext(functionToTest);
expect(context).to.have.nested.property('res.status', 200);
});
it('returns 200 in promise/a+ style', (done) => {
stubContext(functionToTest)
.then(({ context, err, propertyBag }) => {
expect(context).to.have.nested.property('res.status', 200);
done();
})
.catch(done);
});
it('change trigger values before calling your function under test', async () => {
const { context } = await stubContext((context, req, ...otherTriggers) => {
req.body = { 'helpful': 'test object' };
return functionToTest(context, req, ...otherTriggers);
});
expect(context).to.have.nested.property('res.body.helpful', 'test object');
});
});
FAQs
Provides an object similar to Function Runtime's context for use in unit testing
The npm package stub-azure-function-context receives a total of 1,869 weekly downloads. As such, stub-azure-function-context popularity was classified as popular.
We found that stub-azure-function-context demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.