How to use the fetch-mock.fetchMock.sandbox function in fetch-mock

To help you get started, we’ve selected a few fetch-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github voluntarily / vly2 / components / Interest / __tests__ / InterestSection.spec.js View on Github external
test('mount the InterestSection with two interests', async t => {
  const realStore = makeStore(initStore)
  const myMock = fetchMock.sandbox()
  reduxApi.use('fetch', adapterFetch(myMock))
  myMock.getOnce(`${API_URL}/interests/?op=${opid}`, interests)
  myMock.putOnce(`${API_URL}/interests/${interestid}`, invitedAndrew)

  const wrapper = await mountWithIntl(
    
      
    
  )
  await sleep(1) // allow asynch fetch to complete
  wrapper.update()
  t.is(wrapper.find('tbody tr').length, 2)
  t.regex(wrapper.find('tbody tr td').at(1).text(), /avowkind/)
  t.regex(wrapper.find('tbody tr').at(1).find('td').at(1).text(), /Dali/)

  // test invite button
github voluntarily / vly2 / components / Interest / __tests__ / InterestArchivedSection.spec.js View on Github external
test.serial('mount the InterestSection with two interests', async t => {
  const realStore = makeStore(initStore)
  const myMock = fetchMock.sandbox()
  reduxApi.use('fetch', adapterFetch(myMock))
  myMock.getOnce(`${API_URL}/interestsArchived/?op=${opid}`, interests)
  myMock.putOnce(`${API_URL}/interestsArchived/${interests[0]._id}`, markAndrewAsPresent)

  const wrapper = await mountWithIntl(
    
      
    
  )
  await sleep(1) // allow asynch fetch to complete
  wrapper.update()
  t.is(wrapper.find('h2').text(), 'Volunteers') // there are two cards on the screen
  t.is(wrapper.find('tbody tr').length, 2)
  t.is(wrapper.find('tbody tr td').at(0).text().trim(), people[0].nickname)
  t.is(wrapper.find('tbody tr td').at(1).text().trim(), interests[0].comment)
  t.is(wrapper.find('tbody tr td').at(2).text().trim(), interests[0].status)
github voluntarily / vly2 / components / Op / __tests__ / OpListSection.spec.js View on Github external
test.serial('test filter by date is called, no op is shown', async t => {
  const realStore = makeStore(initStore)
  const myMock = fetchMock.sandbox()
  reduxApi.use('fetch', adapterFetch(myMock))
  const api = `${API_URL}/opportunities/?search=Growing`
  myMock.get(api, ops)

  const wrapper = await mountWithIntl(
    
       {}} handleDeleteOp={() => {}} filter={filterDateState} dateFilterType={DatePickerType.IndividualDate} />
    
  )
  await sleep(1) // allow asynch fetch to complete
  wrapper.update()
  t.is(wrapper.find('OpCard').length, 0) // there are no cards on the screen
  t.truthy(myMock.done())
  myMock.restore()
})
github voluntarily / vly2 / components / Op / __tests__ / OpListSection.spec.js View on Github external
test.serial('test filter by week is called. No opportunities shown', async t => {
  const realStore = makeStore(initStore)
  const monthFilterValue = {
    date: [
      '2019-03-02T00:00:00+00:00', // Sat, 02 Mar 2019 00:00:00
      '2019-03-02T00:00:00+00:00' // Sat, 02 Mar 2019 00:00:00
    ]
  }
  const myMock = fetchMock.sandbox()
  reduxApi.use('fetch', adapterFetch(myMock))
  const api = `${API_URL}/opportunities/?search=Growing`
  myMock.getOnce(api, [ops[0]])

  const wrapper = await mountWithIntl(
    
       {}} handleDeleteOp={() => {}} filter={monthFilterValue} dateFilterType={DatePickerType.WeekRange} />
    
  )
  await sleep(1) // allow asynch fetch to complete
  wrapper.update()
  t.is(wrapper.find('OpCard').length, 1)
  t.truthy(myMock.done())
  myMock.restore()
})
github voluntarily / vly2 / components / Interest / __tests__ / RegisterInterestSection.spec.js View on Github external
test.serial('mount RegisterInterestSection with op and me', async t => {
  const realStore = makeStore(initStore)
  const myMock = fetchMock.sandbox()
  reduxApi.use('fetch', adapterFetch(myMock))
  const getmyinterests = `${API_URL}/interests/?op=${opid}&me=${meid}`
  myMock.getOnce(getmyinterests, interests[0])

  const wrapper = await mountWithIntl(
    
      
    
  )
  // before api completes the loading spinner should show.
  t.is(wrapper.find('img').prop('src'), '/static/loading.svg')
  await sleep(1) // allow asynch fetch to complete
  wrapper.update()
github voluntarily / vly2 / components / Interest / __tests__ / RegisterInterestSection.spec.js View on Github external
test.serial('mount RegisterInterestSection with with no existing interest', async t => {
  const realStore = makeStore(initStore)
  const myMock = fetchMock.sandbox()
  reduxApi.use('fetch', adapterFetch(myMock))
  const getmyinterests = `${API_URL}/interests/?op=${opid}&me=${meid}`
  myMock.getOnce(getmyinterests, [])

  const wrapper = await mountWithIntl(
    
      
    
  )
  await sleep(1) // allow asynch fetch to complete
  wrapper.update()
  // we should see "i'm interested"
  t.is(wrapper.find('button').first().text(), "I'm Interested")
github voluntarily / vly2 / components / Member / __tests__ / MemberSectionInfo.spec.js View on Github external
test.before('Setup fixtures', t => {
  fixture(t)
  const initStore = {
    members: {
      loading: false,
      data: [ ]
    },
    session: {
      me: t.context.people[1]
    }
  }
  t.context.store = makeStore(initStore)
  t.context.fetchMock = fetchMock.sandbox()
  t.context.fetchMock.config.overwriteRoutes = false
  reduxApi.use('fetch', adapterFetch(t.context.fetchMock))

  t.context.orgMembers = (status, who) => [
    {
      _id: objectid().toString(),
      person: t.context.people[who],
      organisation: t.context.orgs[0],
      status
    }
  ]
})
github voluntarily / vly2 / components / Interest / __tests__ / InterestArchivedSection.spec.js View on Github external
test.serial('mount the InterestSection with no interests', async t => {
  const realStore = makeStore(initStore)
  const myMock = fetchMock.sandbox()
  const fakeObjectId = mongoose.Types.ObjectId().toString()
  reduxApi.use('fetch', adapterFetch(myMock))
  myMock.getOnce(`${API_URL}/interestsArchived/?op=${fakeObjectId}`, [])
  const wrapper = await mountWithIntl(
    
      
    
  )
  t.is(wrapper.find('p').text(), 'No Data')
})
github voluntarily / vly2 / components / Member / __tests__ / MemberSection.spec.js View on Github external
test.before('Setup fixtures', t => {
  fixture(t)

  const initStore = {
    members: {
      loading: false,
      data: []
    },
    session: {
      me: t.context.people[0]
    }
  }
  t.context.store = makeStore(initStore)
  t.context.fetchMock = fetchMock.sandbox()
  t.context.fetchMock.config.overwriteRoutes = false
  reduxApi.use('fetch', adapterFetch(t.context.fetchMock))
})
github voluntarily / vly2 / __tests__ / home.spec.js View on Github external
test.serial('retrieve completed archived opportunities', async t => {
  const props = {
    me: t.context.me
  }
  const { fetchMock } = require('fetch-mock')
  const myMock = fetchMock.sandbox()
  myMock.get(API_URL + '/archivedOpportunities/', { body: { archivedOpportunities } })
  reduxApi.use('fetch', adapterFetch(myMock))
  const wrapper = mountWithIntl(
    
      
    )
  const res = await wrapper.find('PersonHomePage').first().instance().getArchivedOpportunitiesByStatus('completed')
  t.is(res.length, 3)
  t.is(res[0], archivedOpportunities[0])
  t.is(res[1], archivedOpportunities[1])
})