diff --git a/index.js b/index.js index 0017aa3..b59d40b 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ module.exports = { tldHint : '', httpHint : '' }; - options = _.defaults(options, defaults); + options = _.defaults({}, options, defaults); if (!_.isBoolean(options.isHTML)) { throw new Error('Invalid isHTML value'); diff --git a/test/runner.js b/test/runner.js index 13cab79..1fab928 100755 --- a/test/runner.js +++ b/test/runner.js @@ -54,7 +54,8 @@ async function runEncodingHintTests() { try { await cld.detect(data.all[0].sample, { encodingHint: 'p' }); assert.ok(false, 'Should not have detected'); - } catch (err) { + } + catch (err) { assert.equal(err.message, 'Invalid encodingHint, see ENCODINGS'); } } @@ -123,7 +124,8 @@ async function runHttpHintTests() { let result; try { result = await cld.detect(item.sample, { httpHint: 'mi,en' }); - } catch (err) { + } + catch (err) { assert.equal(err.message, 'Failed to identify language'); return; } @@ -135,11 +137,21 @@ async function runHttpHintTests() { async function runUnreliableTests() { try { await cld.detect('interaktive infografik \xc3\xbcber videospielkonsolen'); - } catch (err) { + } + catch (err) { assert.equal(err.message, 'Failed to identify language'); } } +function runCallbackTests() { + cld.detect('This is a language recognition example', (err, result) => { + assert.equal(result.languages.length > 0, true); + }); + cld.detect('This is a language recognition example', {isHTML:false}, (err, result) => { + assert.equal(result.languages.length > 0, true); + }); +} + function runCrossCheckTests(detected) { // Confirm that we didn't detect languages that are not listed in DETECTED_LANGUAGES _.each(_.values(cld.DETECTED_LANGUAGES), function(val, key) { @@ -159,5 +171,7 @@ function runCrossCheckTests(detected) { await runTldHintTests(); await runHttpHintTests(); await runUnreliableTests(); + + runCallbackTests(); runCrossCheckTests(detected); })();