I'm using express-prom-bundle to provide a prometheus statistics endpoint, this library creates a middleware that is applied to an Express app:
import promBundle from 'express-prom-bundle';
...
app.use(promBundle({
includeMethod: process.env.PROMETHEUS_INCLUDE_METHOD === 'true' ? true : false,
includePath: process.env.PROMETHEUS_INCLUDE_PATH === 'true' ? true : false,
includeStatusCode: process.env.PROMETHEUS_INCLUDE_STATUS_CODE === 'true' ? true : false,
}));
This is what I'm currently trying to do:
import * as promBundle from 'express-prom-bundle';
...
spyOn(promBundle, 'default');
spyOnProperty(promBundle, 'default').and.returnValue({});
expect(promBundle).toHaveBeenCalled();
but I'm receiving the following error:
Error: <spyOn> : default is not declared writable or has no setter Usage: spyOn(<object>, <methodName>)
How it could be mocked and tested by Jasmine?
Coverage shows that lines where process.env
variables are checking need to be tested.