DEV Community

Discussion on: Mocking ES6 class methods with Jest!

Collapse
 
amitozdeol profile image
Amitoz Deol

If I change the getById method to

async getById(id) {
    const url = `http://localhost:3000/api/user/{id}`;
    const response = await fetch(url);
    return await response.json();
  }

the test will still pass. This is not expected behavior I want from test

Collapse
 
jackcaldwell profile image
Jack Caldwell

I'm not quite sure what you mean. In this example the 'ProductsManager' is the class being tested. The 'ProductsClient' is being mocked so we make assumptions about its behaviour in order to test the 'ProductsManager' in isolation. It's assumed that the 'ProductsClient' would be tested separately.