File tree Expand file tree Collapse file tree 4 files changed +24
-14
lines changed
Expand file tree Collapse file tree 4 files changed +24
-14
lines changed Original file line number Diff line number Diff line change 1- import fetch from 'isomorphic- fetch'
1+ import fetch from './utilities/ fetch'
22import normalize from './utilities/normalize'
33
44/*
@@ -12,12 +12,8 @@ export default (strings, ...vars) => {
1212 return ( strings , ...vars ) => {
1313 let finalData = normalize ( strings , vars )
1414 let mergedOptions = { ...options , ...finalData . options }
15+ let finalUrl = finalData . url || url
1516
16- return new Promise ( ( resolve , reject ) => {
17- fetch ( finalData . url || url , mergedOptions )
18- . then ( response => response . json ( ) )
19- . then ( json => resolve ( json ) )
20- . catch ( error => reject ( error ) )
21- } )
17+ return fetch ( finalUrl , mergedOptions )
2218 }
2319}
Original file line number Diff line number Diff line change 1- import fetch from 'isomorphic- fetch'
1+ import fetch from './utilities/ fetch'
22import normalize from './utilities/normalize'
33
44export default ( strings , ...vars ) => {
55 let { options, url } = normalize ( strings , vars )
66
7- return new Promise ( ( resolve , reject ) => {
8- fetch ( url , options )
9- . then ( response => response . json ( ) )
10- . then ( json => resolve ( json ) )
11- . catch ( error => reject ( error ) )
12- } )
7+ return fetch ( url , options )
138}
Original file line number Diff line number Diff line change 1+ import fetch from 'isomorphic-fetch'
2+
3+ export default ( url , options = { } ) => {
4+ return new Promise ( ( resolve , reject ) => {
5+ fetch ( url , options )
6+ . then ( response => response . json ( ) )
7+ . then ( json => resolve ( json ) )
8+ . catch ( error => reject ( error ) )
9+ } )
10+ }
Original file line number Diff line number Diff line change 1+ import fetch from '../../src/utilities/fetch'
2+
3+ describe ( 'fetch' , ( ) => {
4+ it ( 'returns value from response' , async function ( ) {
5+ let response = await fetch ( 'https://freegeoip.net/json/github.com' )
6+
7+ expect ( response . country_code ) . to . equal ( 'US' )
8+ } )
9+ } )
You can’t perform that action at this time.
0 commit comments