Skip to content

Commit

Permalink
fix(getValue): Add reminder to add tests for getValue, hopefulyl trig…
Browse files Browse the repository at this point in the history
…ger a release
  • Loading branch information
kevinchappell committed Nov 2, 2018
1 parent 17f472b commit 4a7fa02
Showing 1 changed file with 70 additions and 68 deletions.
138 changes: 70 additions & 68 deletions src/mi18n.test.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,90 @@
const { expect } = require("chai");
const i18n = require("./mi18n.js");
const { expect } = require('chai')
const i18n = require('./mi18n.js')

const { default: mi18n, I18N } = i18n;
const { default: mi18n, I18N } = i18n

describe("I18N", () => {
const locale = "te-ST";
// @todo add more tests for getValue and getFallbackValue

describe('I18N', () => {
const locale = 'te-ST'
const testOpts = {
locale,
override: {
"te-ST": {
testKey: "Teeesst",
testVars: "I saw {count} {animals}"
'te-ST': {
testKey: 'Teeesst',
testVars: 'I saw {count} {animals}'
}
}
};
}

it("should exist", () => {
expect(mi18n).to.exist;
});
it('should exist', () => {
expect(mi18n).to.exist
})

describe("should have methods", () => {
describe('should have methods', () => {
mi18n.init(testOpts).then(() => {
describe("init()", () => {
it("should exist", () => {
expect(typeof mi18n.init).to.equal("function");
});
it("should set locale", () => {
expect(mi18n.config.locale).to.equal(locale);
});
it("should set current language", () => {
expect(mi18n.current).to.exist;
expect(Object.keys(mi18n.current)).to.contain("testKey");
});
});
});
});
describe('init()', () => {
it('should exist', () => {
expect(typeof mi18n.init).to.equal('function')
})
it('should set locale', () => {
expect(mi18n.config.locale).to.equal(locale)
})
it('should set current language', () => {
expect(mi18n.current).to.exist
expect(Object.keys(mi18n.current)).to.contain('testKey')
})
})
})
})

describe("should have methods after init", () => {
describe('should have methods after init', () => {
mi18n.init(testOpts).then(() => {
describe("get()", () => {
it("shall exist", () => expect(mi18n.get).to.exist);
describe('get()', () => {
it('shall exist', () => expect(mi18n.get).to.exist)

it("shall return a string", () => {
const str = mi18n.get("testKey");
expect(str).to.equal("Teeesst");
});
it('shall return a string', () => {
const str = mi18n.get('testKey')
expect(str).to.equal('Teeesst')
})

it("shall return a string with vars", () => {
const str = mi18n.get("testVars", {
it('shall return a string with vars', () => {
const str = mi18n.get('testVars', {
count: 3,
animals: "chickens"
});
expect(str).to.equal("I saw 3 chickens");
});
});
});
});
animals: 'chickens'
})
expect(str).to.equal('I saw 3 chickens')
})
})
})
})

describe("loadLang", () => {
const location = "https://formbuilder.online/assets/lang/";
const i18n = new I18N({ location });
it("should load de-DE", done => {
i18n.loadLang("de-DE").then(lang => {
expect(lang).to.be.an("object");
expect(Object.keys(i18n.langs)[0]).to.equal("de-DE");
done();
});
});
});
describe('loadLang', () => {
const location = 'https://formbuilder.online/assets/lang/'
const i18n = new I18N({ location })
it('should load de-DE', done => {
i18n.loadLang('de-DE').then(lang => {
expect(lang).to.be.an('object')
expect(Object.keys(i18n.langs)[0]).to.equal('de-DE')
done()
})
})
})

describe("addLanguage", () => {
const locale = "te-ST";
const i18n = new I18N();
it("should load te-ST", done => {
describe('addLanguage', () => {
const locale = 'te-ST'
const i18n = new I18N()
it('should load te-ST', done => {
i18n.addLanguage(locale, {
myKey: "one thing",
myKey: 'one thing',
yourKey: "shouldn't change"
});
})
i18n.setCurrent(locale).then(() => {
expect(i18n.locale).to.equal(locale);
expect(i18n.get("myKey")).to.equal("one thing");
expect(i18n.get("yourKey")).to.equal("shouldn't change");
done();
});
});
});
});
expect(i18n.locale).to.equal(locale)
expect(i18n.get('myKey')).to.equal('one thing')
expect(i18n.get('yourKey')).to.equal("shouldn't change")
done()
})
})
})
})

0 comments on commit 4a7fa02

Please sign in to comment.