Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
fix handler not being called on reload without error
Browse files Browse the repository at this point in the history
  • Loading branch information
SerayaEryn committed Oct 12, 2018
1 parent 8d10d23 commit a595b4a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = class Translator {

reload (handler) {
return this._reload()
.then(() => {
if (handler) handler(null)
})
.catch((error) => {
if (handler) handler(error)
})
Expand Down
38 changes: 38 additions & 0 deletions test/translation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,44 @@ test('should use source', (t) => {
})

test('should use handler on reload()', (t) => {
t.plan(1)

const translations = {
test: {
title: '__count__ singular',
title_plural_2: '__count__ plural'
}
}

class TestSource {
load () {
return Promise.resolve([{
language: 'de',
namespace: 'DE',
translations
}])
}
}
const translation = new Translation({
preload: ['de']
})
return translation
.addRule('de', [1, 2], function (number) {
return number === 1 ? 0 : 1
})
.use(new TestSource())
.initialize()
.then(() => {
return new Promise((resolve) => {
translation.reload((error) => {
t.error(error)
resolve()
})
})
})
})

test('should use handler on reload() and handle error', (t) => {
t.plan(4)
class TestSource {
load () {
Expand Down

0 comments on commit a595b4a

Please sign in to comment.