Skip to content

Commit

Permalink
[FIX] Critical fix - spawn should inherit onmiss functionality (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan authored Jan 21, 2020
1 parent bd0da6c commit 214472f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ class I18nChild extends I18n {

this.$scope = scopeChain.join('.') || undefined;
this.parent = parent;
this[MISSING] = this.parent[MISSING];
this[EMPTY] = this.parent[EMPTY];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fiverr/i18n",
"version": "1.8.0",
"version": "1.8.1",
"description": "Translation helper",
"keywords": [
"i18n",
Expand Down
22 changes: 22 additions & 0 deletions tests/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,26 @@ describe('child instances', () => {
expect(child.t('key')).to.equal('Child');
expect(child.t('key', {$scope: 'something'})).to.equal('Something');
});

it('Child calls parent onmiss functionallity', () => {
const i18n = new I18n({translations});
let miss = 0;
i18n.onmiss(() => miss++);
const child = i18n.spawn('child');
child.t('missing_translation');
expect(miss).to.equal(1);
});

it('Child overrides parent onmiss functionallity', () => {
const i18n = new I18n({translations});
let miss = 0;
let childMiss = 0;
i18n.onmiss(() => miss++);
const child = i18n.spawn('child');
child.onmiss(() => childMiss++);

child.t('missing_translation');
expect(miss).to.equal(0);
expect(childMiss).to.equal(1);
});
});

0 comments on commit 214472f

Please sign in to comment.