Last active
October 28, 2015 10:44
-
-
Save koba04/afda6fdd4211bf0fc030 to your computer and use it in GitHub Desktop.
a minimum fake implementation of fetch on Node environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assign from 'object-assign'; | |
export default function fakeFetch(res) { | |
global.fetch = (url, params) => { | |
return Promise.resolve(assign({}, res, {__arg: {url, params}})); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fakeFetch from './fakeFetch'; | |
describe('api', () => { | |
it('should be result is ok', done => { | |
fakeFetch({ | |
status: 200, | |
json: () => ({res: 'ok'}) | |
}); | |
fetch('/api', {user: 1}).then(res => { | |
assert(res.status === 200); | |
assert(res.json().res === 'ok'); | |
assert(res.__arg.url === '/api'); | |
assert(res.__arg.params.user === 1); | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment