Skip to content

Commit

Permalink
Add conditional testing for Node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikos Vasileiou committed Dec 1, 2021
1 parent 68c3a6f commit c048e77
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/native/tests/renderer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { expect } from 'chai';
import { tx, t } from '../src/index';

const NODE_VER = parseInt((process.version.split('.')[0]).replace('v', ''), 10);

describe('String renderer', () => {
it('renders with localized dates', async () => {
const d = Date.parse('2020-02-01');
Expand All @@ -11,13 +13,18 @@ describe('String renderer', () => {
expect(tx.stringRenderer.render('Date is {d, date, long}', '', { d }))
.to.equal('Date is February 1, 2020');

// French locale
expect(tx.stringRenderer.render('Date is {d, date, long}', 'fr', { d }))
.to.equal('Date is 1 février 2020');

// German locale
expect(tx.stringRenderer.render('Date is {d, date, long}', 'de_DE', { d }))
.to.equal('Date is 1. Februar 2020');
// Node prior to 13 is build with small-icu support and date localization
// will not work. So enable this test only on latest versions
expect(NODE_VER).to.be.greaterThanOrEqual(10);
if (NODE_VER >= 13) {
// French locale
expect(tx.stringRenderer.render('Date is {d, date, long}', 'fr', { d }))
.to.equal('Date is 1 février 2020');

// German locale
expect(tx.stringRenderer.render('Date is {d, date, long}', 'de_DE', { d }))
.to.equal('Date is 1. Februar 2020');
}

// invalid locale fallsback to english
expect(tx.stringRenderer.render('Date is {d, date, long}', 'a', { d }))
Expand Down

0 comments on commit c048e77

Please sign in to comment.