Skip to content

Instantly share code, notes, and snippets.

@marr
Created September 13, 2016 21:33
Show Gist options
  • Save marr/7909958f39dc5b504cafa7be2a348e19 to your computer and use it in GitHub Desktop.
Save marr/7909958f39dc5b504cafa7be2a348e19 to your computer and use it in GitHub Desktop.
import 'isomorphic-fetch'
import { test } from 'tap'
import nock from 'nock'
nock('http://localhost')
.get(/item\/(.*)/)
.times(2)
.reply(200, function(url, requestBody) {
const user = url.substr(url.lastIndexOf('/') + 1)
return `You found user ${user}`
})
test('maintain a list of promises', assert => {
const items = [{ id: 1 }, { id: 2 }]
items.forEach(async ({ id }) => {
const text = await fetch(`http://localhost/item/${id}`).then(res => {
return res.text()
})
assert.equal(text, `You found user ${id}`)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment