Browse Source

Merge pull request #385 from pelias/use-tapes-does-not-throw

Use throws and doesNotThrow from Tape
pull/394/head
David Riordan 9 years ago
parent
commit
7fa5a4e292
  1. 26
      test/unit/helper/types.js
  2. 36
      test/unit/middleware/confidenceScore.js
  3. 20
      test/unit/middleware/confidenceScoreReverse.js

26
test/unit/helper/types.js

@ -4,29 +4,13 @@ module.exports.tests = {};
module.exports.tests.no_cleaned_types = function(test, common) { module.exports.tests.no_cleaned_types = function(test, common) {
test('no cleaned types', function(t) { test('no cleaned types', function(t) {
try { function testIt() {
types();
t.fail('exception should be thrown');
}
catch (err) {
t.equal(err.message, 'clean_types should not be null or undefined', 'no input should result in exception');
}
finally {
t.end();
}
});
test('no cleaned types', function(t) {
try {
types({}); types({});
t.fail('exception should be thrown');
}
catch (err) {
t.equal(err.message, 'clean_types should not be null or undefined', 'no input should result in exception');
}
finally {
t.end();
} }
t.throws(testIt, /clean_types should not be null or undefined/, 'no input should result in exception');
t.end();
}); });
}; };

36
test/unit/middleware/confidenceScore.js

@ -5,17 +5,12 @@ module.exports.tests = {};
module.exports.tests.confidenceScore = function(test, common) { module.exports.tests.confidenceScore = function(test, common) {
test('empty res and req should not throw exception', function(t) { test('empty res and req should not throw exception', function(t) {
try { function testIt() {
confidenceScore({}, {}, function() {}); confidenceScore({}, {}, function() {});
t.pass('no exception');
}
catch (e) {
t.fail('an exception should not have been thrown');
}
finally {
t.end();
} }
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
}); });
test('res.results without parsed_text should not throw exception', function(t) { test('res.results without parsed_text should not throw exception', function(t) {
@ -27,18 +22,12 @@ module.exports.tests.confidenceScore = function(test, common) {
meta: [10] meta: [10]
}; };
try { function testIt() {
confidenceScore(req, res, function() {}); confidenceScore(req, res, function() {});
t.pass('no exception');
}
catch (e) {
t.fail('an exception should not have been thrown');
console.log(e.stack);
}
finally {
t.end();
} }
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
}); });
test('hit without address should not error', function(t) { test('hit without address should not error', function(t) {
@ -61,17 +50,12 @@ module.exports.tests.confidenceScore = function(test, common) {
} }
}; };
try { function testIt() {
confidenceScore(req, res, function() {}); confidenceScore(req, res, function() {});
t.pass('no exception');
}
catch (e) {
t.fail('an exception should not have been thrown with no address');
console.log(e.stack);
}
finally {
t.end();
} }
t.doesNotThrow(testIt, 'an exception should not have been thrown with no address');
t.end();
}); });

20
test/unit/middleware/confidenceScoreReverse.js

@ -6,16 +6,12 @@ module.exports.tests.confidenceScoreReverse = function(test, common) {
test('res without results should not throw exception', function(t) { test('res without results should not throw exception', function(t) {
var res = {}; var res = {};
try { function testIt() {
confidenceScoreReverse(null, res, function() {}); confidenceScoreReverse(null, res, function() {});
} }
catch (e) {
t.fail('an exception should not have been thrown');
}
finally {
t.end();
}
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
}); });
test('res.results without data should not throw exception', function(t) { test('res.results without data should not throw exception', function(t) {
@ -23,16 +19,12 @@ module.exports.tests.confidenceScoreReverse = function(test, common) {
results: {} results: {}
}; };
try { function testIt() {
confidenceScoreReverse(null, res, function() {}); confidenceScoreReverse(null, res, function() {});
} }
catch (e) {
t.fail('an exception should not have been thrown');
}
finally {
t.end();
}
t.doesNotThrow(testIt, 'an exception should not have been thrown');
t.end();
}); });
test('0m <= distance < 1m should be given score 1.0', function(t) { test('0m <= distance < 1m should be given score 1.0', function(t) {

Loading…
Cancel
Save