I'm using BluebirdJS promise library and I have .catch
that I can't mock that is why I can't cover it with my code coverage using istanbul.
.then(() => ....)
/* istanbul ignore next */ -> Does not work
.catch((err) => err) /// I want to ignore this
Is this possible with istanbul library?
This is the full code, my test can't reach the .catch
because it's always passing and I can't seem to another way to force mongoose to throw an error
const { payload } = request
const group = new LocationGroups(payload)
group.save()
.then(reply)
.catch((error) => reply(boomify(error)))
I'm using BluebirdJS promise library and I have .catch
that I can't mock that is why I can't cover it with my code coverage using istanbul.
.then(() => ....)
/* istanbul ignore next */ -> Does not work
.catch((err) => err) /// I want to ignore this
Is this possible with istanbul library?
This is the full code, my test can't reach the .catch
because it's always passing and I can't seem to another way to force mongoose to throw an error
const { payload } = request
const group = new LocationGroups(payload)
group.save()
.then(reply)
.catch((error) => reply(boomify(error)))
Share
Improve this question
edited Mar 24, 2023 at 11:18
Dharman♦
33.5k27 gold badges101 silver badges148 bronze badges
asked Sep 18, 2017 at 0:14
kdlcruzkdlcruz
1,38813 silver badges20 bronze badges
5
- Try making it testable? Why do you think you can't mock it? – Bergi Commented Sep 18, 2017 at 0:53
- How about putting the ment inside the callback that should be ignored? – Bergi Commented Sep 18, 2017 at 0:53
-
@Bergi Please see my edit. I'm not sure how to force mongoose to force an error with
.save
– kdlcruz Commented Sep 18, 2017 at 1:04 - @Bergi putting the ment inside won't work because I can't reach it. Thanks btw, for the ment :) – kdlcruz Commented Sep 18, 2017 at 1:07
-
You can't force mongoose to do anything, but you could just mock
save
?What libraries do you use for testing? – Bergi Commented Sep 18, 2017 at 1:08
2 Answers
Reset to default 6try {
} catch (err) /* istanbul ignore next */ {
}
In your case
group.save()
.then(reply)
.catch( /* istanbul ignore next */(error) => reply(boomify(error)))
Alternatively, you can wrap your catch in another block
try {
stuff()
} catch (err) {
/* istanbul ignore next */ {
console.error(err)
throw err
}
}