Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Test fetch with jest

I have method in Vue component with fetch, how to check by jest + vtu

expect(wrapper.vm.collectionRelatedEntries).toEqual('related_entries')

Or something else in then(() => { //do something else })

requestRemoveEntry(url){
      this.addPreloader = true

      return fetch(url, {
        method: 'DELETE',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(this.selectedIdEntries)
      })
          .then(response => {
            if(response.ok){
              if(response.status === 204){
                this.selectedIdEntries = []
                this.stateSelected = false
              }
              if(response.status === 200){
                return response.json().then((data) => {
                  this.collectionRelatedEntries = data.related_entries
                })
              }
            }else {
              this.isShowModalError = true
            }
          })
          .then(() => {
            //do something else
          })
          .catch((error) => {
            this.isShowModalError = true
          })
          .finally(() => this.addPreloader = false)
    },




 test('test method for remove entry', async () => {
        global.fetch = jest.fn(() =>
            Promise.resolve({data: [{ 'title': 'title', id: 'id', related_entries: ['related_entries'] }], ok: true, status: 200}));
        wrapper.setData({ statusMassDelete: false })
        await wrapper.vm.requestRemoveEntry('/api/get_entries', 'id')
        expect(fetch).toHaveBeenCalledWith("/api/get_entries", {"body": null, "headers": {"Content-Type": "application/json"}, "method": "DELETE"})

expect(wrapper.vm.collectionRelatedEntries).toEqual('related_entries') })

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!