Skip to content

Commit

Permalink
Created cb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dachev committed May 6, 2020
1 parent 5e22d2e commit 50ab0d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
20 changes: 17 additions & 3 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand All @@ -159,5 +171,7 @@ function runCrossCheckTests(detected) {
await runTldHintTests();
await runHttpHintTests();
await runUnreliableTests();

runCallbackTests();
runCrossCheckTests(detected);
})();

0 comments on commit 50ab0d5

Please sign in to comment.