I want to test the type of uploaded file, but since it doesn't need to be uploaded I just want to change the returned value of the function that gets the type
I read about stubs but I couldn't use expect after stubbing, I think I'm getting things wrong I want to test that function and change the returned value of fileType
const check_avatar_errors = avatar => {
const allowed_types = ["image/png", "image/jpg", "image/jpeg"];
const file_type = fileType(avatar.data).mime
if (!allowed_types.includes(file_type)) {
return create_error("invalid_content_type");
}
};
so That the next test would pass :
const validators = require("../../helpers/validator.js");
const check_avatar_errors = validator.__get__("check_avatar_errors");
it("should return invalid content type error if the uploaded file is not an img",function () {
/************** Some code here ********/
expect(check_avatar_errors("not_img_type")).to.deep.equal([{error: "invalid_content_type"}]);
});
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire