vendredi 17 avril 2015

Sequelize Model Unit Test

I have a User sequelize model that has a beforeCreate hook that encrypts the password using bcrypyt. Bcrypyt is loaded as a dependency by the model using a require statement.


Now, I'm writing my tests for my models and I want to write a test that ensures bcrypt is encrypting the password on create.


At the moment, I have added a setter onto the User model that sets the bcrypt object. In my tests, I can then create a spy using sinon and inject the spy using the setter and ensure it is called on create.


Is this the correct way to do it? I feel as if I'm creating a setter purely for my tests and that it serves no other purpose.


Aucun commentaire:

Enregistrer un commentaire