UNPKG

dark-sky-skeleton

Version:

barebones dark sky weather api - for client or server-side js

41 lines (37 loc) 1.43 kB
import DarkSkySkelton from './dark-sky-skeleton'; import fetchJsonp from 'fetch-jsonp'; import fetch from 'whatwg-fetch'; jest.mock('fetch-jsonp'); jest.mock('whatwg-fetch'); describe('DarkSkySkeleton', () => { it('should include api key in query url', () => { const key = 123; const skeleton = new DarkSkySkelton(key); skeleton.generateReqUrl(); expect(skeleton.url).toBe(`https://api.darksky.net/forecast/{$key}/,`); }); it('should include lat and long in query', () => { const key = 123; const skeleton = new DarkSkySkelton(key); skeleton.latitude(12.3).longitude(45.6).generateReqUrl(); expect(skeleton.url).toBe(`https://api.darksky.net/forecast/{$key}/12.3,45.6`); }); it('should use proxy url in place of normal dark sky url', ()=> { const proxyUrl = '/localhost/weather'; const skeleton = new DarkSkySkelton(false, proxyUrl); skeleton.generateReqUrl(); expect(skeleton.url).toBe(`{$proxyUrl}/,`); }); it('should throw rejectp promise if get called without lat and long', ()=> { const key = 123; const skeleton = new DarkSkySkelton(key); return skeleton.get() .catch(e => { expect(e).toBe('Request not sent. ERROR: Longitute or Latitude is missing.'); }); }); it('should call fetch if using proxy url', ()=> { }); it('should call fetchJsonp if using api key', ()=> { }); });