2

I have service where javascript fetch is used to call an endpoints How to mock fetch API calls in angular using jasmine

fetch('https://' + this.sericeOption.url + '/rest/ms/2/user',
      { 
        method: 'PUT', headers: headers, 
        body: JSON.stringify(updatedUser) 
      }
      ).then((res) => 
      {
       return res.status != 200
        ? res.json()
       .then((error) => Promise.reject
        (
         { code: error.code, message: error.message })
        )
       : res.json();
     });
suchi
  • 83
  • 10
  • In order to mock ´fetch´-method of javascript you can use the framework ´fetch-mock´: http://www.wheresrhys.co.uk/fetch-mock/ – Aedvald Tseh Feb 06 '21 at 10:45
  • There is an answer here that worked for me: https://stackoverflow.com/questions/66200776/jasmine-how-to-test-a-fetch-in-a-fetch – Eli Mar 12 '23 at 10:13

0 Answers0