lundi 4 mars 2019

Mocking constructor to force my way into a conditional

So I'm doing unit testing and I need to make it into a conditional based upon the below condition (i.e I want the condition to be true)

if(foo.body.constructor === Object && Object.keys(foo.body).length === 0) {
.
.
.
}

My mock up looks like this so far. This doesn't crash but it won't go into the conditional as I would like.

let foo = {
    body:()=> jest.fn()
}

I've also tried the below and noticed that the length returned is always 1.

let foo = {
        body:{
            constructor: Object
        }
    }

Not sure what I need to do to get the length of foo.body to be 0 as well as have the foo.body.constructor be 0

Aucun commentaire:

Enregistrer un commentaire