lundi 8 avril 2019

how to call a method of an external class in jest

I'm new in jest and im using that with react native. i have a class like this which contains some methods i call one of them as example:

/src/order.js
export default class Order {
constructor(auth) {
    this.rest = new rest()
    this.auth = auth

     myMethod(someVar){
         console.log('function called')
        return 'hi'
      }
    }

}

and i want to call it in jest:

let orderService = new Order('654654652321221');

test('call function', async(done) => {
  orderService.test =jest.fn(()=>orderService.test('f'))
  expect(orderService.test()).toHaveBeenCalled();
  done();
},6000);

but no function calls with this code and got this error:'Timeout - Async callback was not invoked within the 6000ms timeout specified by jest.setTimeout.'

Aucun commentaire:

Enregistrer un commentaire