How can I mock a service within a React component to isolate unit tests in jest?
问题 I'm trying to refactor a unit test to isolate a service that calls an API using axios from the component calling the service. The service is for the moment really simple: import axios from 'axios' export default class SomeService { getObjects() { return axios.get('/api/objects/').then(response => response.data); } } Here's a snippet of the component that calls the service: const someService = new SomeService(); class ObjectList extends Component { state = { data: [], } componentDidMount() {