I have an endpoint which calls mongoose findOne as well as some other external methods such as "getDecodedSession" which comes from a library of my own. I'm looking to mock these methods with my own implementations in order to test the various cases of the unit. After my initial research, the closest I've come is the "rewire" library, but it appears this does not mesh well with babel according to the docs. The modules are all written using ES6 imports/exports and transpiled with babel. What is the standard way to mock external dependencies in a node.js project that utilizes transpiled es6?
Example endpoint to test:
app.get('/post/save', async (req, res) => {
try {
const { _id } = getDecodedSession(req);
const user = await User.findOne({_id});
if (!user) {
return res.with(403, UNAUTHORIZED);
}
res.with(200);
} catch (e) {
res.with(500, SERVER_ERROR);
}
});
Aucun commentaire:
Enregistrer un commentaire