Friday, 12 May 2017

Unit testing mongoose method

I'm new to unit testing, can't wrap my head what I should unit test given this function ? Note that I don't want to hit database, so I need to mock/stub mongoose built in function "findById" maybe ? Can't figure it out big picture here :). Not asking for complete solution, just an idea or some pointer to go from there.

LyricSchema.statics.like = function(id) {
  const Lyric = mongoose.model('lyric');

  return Lyric.findById(id)
    .then(lyric => {
      ++lyric.likes;
      return lyric.save();
    })
}

Thank you !



via Polisas

No comments:

Post a Comment