Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
update to mocha 3
Browse files Browse the repository at this point in the history
  • Loading branch information
devfd committed Aug 2, 2016
1 parent 0335854 commit 5a998bb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 71 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
89 changes: 35 additions & 54 deletions test/unit/geocoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
16 changes: 6 additions & 10 deletions test/unit/googleApi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5a998bb

Please sign in to comment.