From 5a998bb262675285241f0d2fab310ecb5401cb28 Mon Sep 17 00:00:00 2001 From: devfd Date: Tue, 2 Aug 2016 19:29:42 +0200 Subject: [PATCH] update to mocha 3 --- package.json | 14 +++--- test/unit/geocoder.test.js | 89 +++++++++++++++---------------------- test/unit/googleApi.test.js | 16 +++---- 3 files changed, 48 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index 62e706d..9a7b348 100644 --- a/package.json +++ b/package.json @@ -28,15 +28,15 @@ "homepage": "https://github.com/devfd/react-native-geocoder", "license": "MIT", "devDependencies": { - "appium": "^1.5.2", - "babel-core": "^6.8.0", - "babel-polyfill": "^6.8.0", - "babel-preset-react-native": "^1.8.0", + "appium": "^1.5.3", + "babel-core": "^6.11.4", + "babel-polyfill": "^6.9.1", + "babel-preset-react-native": "^1.9.0", "chai": "^3.5.0", "colors": "^1.1.2", - "mocha": "^2.4.5", - "proxyquire": "^1.7.9", - "sinon": "^1.17.4", + "mocha": "^3.0.0", + "proxyquire": "^1.7.10", + "sinon": "^1.17.5", "sinon-chai": "^2.8.0", "wd": "^0.4.0" } diff --git a/test/unit/geocoder.test.js b/test/unit/geocoder.test.js index f527bbc..7759e53 100644 --- a/test/unit/geocoder.test.js +++ b/test/unit/geocoder.test.js @@ -37,16 +37,13 @@ describe('geocoder', function() { describe('geocodePosition', function() { - it ('requires a valid position', async function(done) { - try { - await Geocoder.geocodePosition({}); - done(new Error('should not be there')); - } - catch(err) { - expect(err).to.be.ok; - expect(err.message).to.contain('valid'); - done(); - } + it ('requires a valid position', function() { + return Geocoder.geocodePosition({}).then( + () => { throw new Error('should not be there') }, + (err) => { + expect(err).to.be.ok; + expect(err.message).to.contain('valid'); + }); }); it ('returns geocoding results', async function() { @@ -55,16 +52,13 @@ describe('geocoder', function() { expect(RNGeocoder.geocodePosition).to.have.been.calledWith(position); }); - it ('does not call google api if no apiKey', async function(done) { + it ('does not call google api if no apiKey', function() { const position = {lat: 1.234, lng: 4.567}; RNGeocoder.geocodePosition = sinon.stub().returns(Promise.reject()); - try { - await Geocoder.geocodePosition(position); - done(new Error('should not be there')); - } catch(err) { - expect(GoogleApi.geocodePosition).to.not.have.been.called; - done(); - } + return Geocoder.geocodePosition(position).then( + () => { throw new Error('should not be there') }, + (err) => { expect(GoogleApi.geocodePosition).to.not.have.been.called; } + ); }); it ('fallbacks to google api when not available', async function() { @@ -76,32 +70,26 @@ describe('geocoder', function() { expect(ret).to.eql('google'); }); - it ('does not fallback to google api on error', async function(done) { + it ('does not fallback to google api on error', function() { const position = {lat: 1.234, lng: 4.567}; RNGeocoder.geocodePosition = sinon.stub().returns(Promise.reject(new Error('something wrong'))); Geocoder.fallbackToGoogle('myGoogleMapsAPIKey'); - try { - const ret = await Geocoder.geocodePosition(position); - done(new Error('should not be called')); - } - catch(err) { - expect(err.message).to.eql('something wrong'); - done(); - } + return Geocoder.geocodePosition(position).then( + () => { throw new Error('should not be there') }, + (err) => { expect(err.message).to.eql('something wrong'); } + ); }); }); describe('geocodeAddress', function() { - it ('requires a valid address', async function(done) { - try { - await Geocoder.geocodeAddress(); - done(new Error('should not be there')); - } - catch(err) { - expect(err).to.be.ok; - expect(err.message).to.contain('address is null'); - done(); - } + it ('requires a valid address', function() { + return Geocoder.geocodeAddress().then( + () => { throw new Error('should not be there') }, + (err) => { + expect(err).to.be.ok; + expect(err.message).to.contain('address is null'); + } + ); }); it ('returns geocoding results', async function() { @@ -110,30 +98,23 @@ describe('geocoder', function() { expect(RNGeocoder.geocodeAddress).to.have.been.calledWith(address); }); - it ('does not call google api if no apiKey', async function(done) { + it ('does not call google api if no apiKey', function() { const address = 'london'; RNGeocoder.geocodeAddress = sinon.stub().returns(Promise.reject()); - try { - await Geocoder.geocodeAddress(address); - done(new Error('should not be here')); - } catch(err) { - expect(GoogleApi.geocodeAddress).to.not.have.been.called; - done(); - } + return Geocoder.geocodeAddress(address).then( + () => { throw new Error('should not be there') }, + (err) => { expect(GoogleApi.geocodeAddress).to.not.have.been.called; } + ); }); - it ('does not fallback to google api on error', async function(done) { + it ('does not fallback to google api on error', function() { const address = 'london'; RNGeocoder.geocodeAddress = sinon.stub().returns(Promise.reject(new Error('something wrong'))); Geocoder.fallbackToGoogle('myGoogleMapsAPIKey'); - try { - const ret = await Geocoder.geocodeAddress(address); - done(new Error('should not be called')); - } - catch(err) { - expect(err.message).to.eql('something wrong'); - done(); - } + return Geocoder.geocodeAddress(address).then( + () => { throw new Error('should not be there') }, + (err) => { expect(err.message).to.eql('something wrong'); } + ); }); it ('fallbacks to google api on error', async function() { diff --git a/test/unit/googleApi.test.js b/test/unit/googleApi.test.js index d4de38f..f02e8b9 100644 --- a/test/unit/googleApi.test.js +++ b/test/unit/googleApi.test.js @@ -38,16 +38,12 @@ describe('googleApi', function() { })) } - it ('throws if invalid results', async function(done) { - try { - mockFetch({ status: "NOT_OK" }); - await GoogleApi.geocodeRequest(); - done(new Error('cannot be here')); - } - catch(err) { - expect(err.message).to.contain("NOT_OK"); - done(); - } + it ('throws if invalid results', function() { + mockFetch({ status: "NOT_OK" }); + return GoogleApi.geocodeRequest().then( + () => { throw new Error('cannot be there') }, + (err) => { expect(err.message).to.contain("NOT_OK"); } + ); }); describe('returns formatted results', function() {