Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

question from:https://stackoverflow.com/questions/65945545/how-to-spy-on-npm-library-function-node-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
160 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...