From 92cd141d2d2aaf2c102564530478b4ee19860948 Mon Sep 17 00:00:00 2001 From: fanmd Date: Mon, 8 Aug 2022 15:26:20 +0800 Subject: [PATCH] add some test cases --- packages/react-intl-universal/test/index.test.js | 15 +++++++++++++++ .../react-intl-universal/test/locales/en-US.js | 2 ++ .../react-intl-universal/test/locales/zh-CN.js | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/react-intl-universal/test/index.test.js b/packages/react-intl-universal/test/index.test.js index d6209c1..aac8970 100644 --- a/packages/react-intl-universal/test/index.test.js +++ b/packages/react-intl-universal/test/index.test.js @@ -368,3 +368,18 @@ test("Resolve directly if the environment is not browser", async () => { }); expect(result).toBe(undefined); }); + +test("Set default variables locale", () => { + intl.init({ locales, currentLocale: "zh-CN", + defaultVariables:{ + company:"Jivation-Group" + } + }); + expect(intl.get("COMPANY")).toBe("Jivation-Group是一个国际集团公司"); + expect(intl.get("BUSINESS")).toBe("Jivation-Group处理国际性事务"); + intl.init({ locales, currentLocale: "en-US", defaultVariables:{ + company:"Jivation-Group" + } }); + expect(intl.get("COMPANY")).toBe("Jivation-Group is a international group of companies"); + expect(intl.get("BUSINESS")).toBe("Jivation-Group handle international business"); +}); \ No newline at end of file diff --git a/packages/react-intl-universal/test/locales/en-US.js b/packages/react-intl-universal/test/locales/en-US.js index 96b32f3..ec9174a 100644 --- a/packages/react-intl-universal/test/locales/en-US.js +++ b/packages/react-intl-universal/test/locales/en-US.js @@ -8,6 +8,8 @@ module.exports = ({ "COUPON": "Coupon expires at {expires, time, medium}", "SALE_PRICE": "The price is {price, number, USD}", "PHOTO": "You have {num, plural, =0 {no photos.} =1 {one photo.} other {# photos.}}", + "COMPANY":"{company} is a international group of companies", + "BUSINESS":"{company} handle international business", "NESTED": { "HELLO": "Hello World", "HELLO_NAME": "Hello, {name}" diff --git a/packages/react-intl-universal/test/locales/zh-CN.js b/packages/react-intl-universal/test/locales/zh-CN.js index 76cc519..c6d65b2 100644 --- a/packages/react-intl-universal/test/locales/zh-CN.js +++ b/packages/react-intl-universal/test/locales/zh-CN.js @@ -8,5 +8,7 @@ module.exports = ({ "COUPON": "优惠卷将在{expires, time, medium}过期", "TIME": "时间是{theTime, time}", "SALE_PRICE": "售价{price, number, CNY}", - "PHOTO": "你有{num}张照片" + "PHOTO": "你有{num}张照片", + "COMPANY":"{company}是一个国际集团公司", + "BUSINESS":"{company}处理国际性事务" });