Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

fix: use non-breaking spaces for assertions

goenninge0e7dcd3cc4b
diff --git a/public/services/utils.spec.ts b/public/services/utils.spec.ts
index 5c98bb51f..927efe5dc 100644
--- a/public/services/utils.spec.ts
+++ b/public/services/utils.spec.ts
@@ -1,5 +1,13 @@
import { classSet, formatDate, timeSince, fileToBase64 } from "./utils"
import { readFileSync } from "fs"
+
+// replaces non-breaking spaces with normal spaces
+const normalize = (str: string) =>
+ str
+ .replace(/\xa0/g, " ")
+ .replace(/\u202f/g, " ")
+ .trim()
+
;[
{ input: null, expected: "" },
{ input: undefined, expected: "" },
@@ -25,18 +33,18 @@ import { readFileSync } from "fs"
})
})
;[
- { input: new Date(2018, 4, 27, 10, 12, 59), expectedEn: "May 27, 2018 at 10:12 AM", expectedPtBr: "27 de maio de 2018 às 10:12" },
- { input: new Date(2058, 12, 12, 23, 21, 53), expectedEn: "January 12, 2059 at 11:21 PM", expectedPtBr: "12 de janeiro de 2059 às 23:21" },
- { input: "2018-04-11T18:13:33.128082", expectedEn: "April 11, 2018 at 6:13 PM", expectedPtBr: "11 de abril de 2018 às 18:13" },
- { input: "2017-11-20T07:47:42.158142", expectedEn: "November 20, 2017 at 7:47 AM", expectedPtBr: "20 de novembro de 2017 às 07:47" },
+ { input: new Date(2018, 4, 27, 10, 12, 59), expectedEn: "May 27, 2018 at 10:12 AM", expectedPtBr: "27 de maio de 2018 às 10:12" },
+ { input: new Date(2058, 12, 12, 23, 21, 53), expectedEn: "January 12, 2059 at 11:21 PM", expectedPtBr: "12 de janeiro de 2059 às 23:21" },
+ { input: "2018-04-11T18:13:33.128082", expectedEn: "April 11, 2018 at 6:13 PM", expectedPtBr: "11 de abril de 2018 às 18:13" },
+ { input: "2017-11-20T07:47:42.158142", expectedEn: "November 20, 2017 at 7:47 AM", expectedPtBr: "20 de novembro de 2017 às 07:47" },
].forEach((x) => {
test(`[English] formatDate (full) of ${x.input} should be ${x.expectedEn}`, () => {
const result = formatDate("en", x.input, "full")
- expect(result).toEqual(x.expectedEn)
+ expect(normalize(result)).toEqual(x.expectedEn)
})
test(`[Brazilian Portuguese] formatDate (full) of ${x.input} should be ${x.expectedPtBr}`, () => {
const result = formatDate("pt-BR", x.input, "full")
- expect(result).toEqual(x.expectedPtBr)
+ expect(normalize(result)).toEqual(x.expectedPtBr)
})
})
;[
@@ -47,11 +55,11 @@ import { readFileSync } from "fs"
].forEach((x) => {
test(`[English] formatDate (short) of ${x.input} should be ${x.expectedEn}`, () => {
const result = formatDate("en", x.input, "short")
- expect(result).toEqual(x.expectedEn)
+ expect(normalize(result)).toEqual(x.expectedEn)
})
test(`[Brazilian Portuguese] formatDate (short) of ${x.input} should be ${x.expectedPtBr}`, () => {
const result = formatDate("pt-BR", x.input, "short")
- expect(result).toEqual(x.expectedPtBr)
+ expect(normalize(result)).toEqual(x.expectedPtBr)
})
})
;[
@@ -62,11 +70,11 @@ import { readFileSync } from "fs"
].forEach((x) => {
test(`[English] formatDate (date) of ${x.input} should be ${x.expectedEn}`, () => {
const result = formatDate("en", x.input, "date")
- expect(result).toEqual(x.expectedEn)
+ expect(normalize(result)).toEqual(x.expectedEn)
})
test(`[Brazilian Portuguese] formatDate (date) of ${x.input} should be ${x.expectedPtBr}`, () => {
const result = formatDate("pt-BR", x.input, "date")
- expect(result).toEqual(x.expectedPtBr)
+ expect(normalize(result)).toEqual(x.expectedPtBr)
})
})
;[
@@ -82,12 +90,12 @@ import { readFileSync } from "fs"
test(`[English] timeSince ${x.input} should be ${x.expectedEn}`, () => {
const now = new Date(2018, 4, 27, 19, 51, 10)
const result = timeSince("en", now, x.input)
- expect(result).toEqual(x.expectedEn)
+ expect(normalize(result)).toEqual(x.expectedEn)
})
test(`[Brazilian Portuguese] timeSince ${x.input} should be ${x.expectedPtBr}`, () => {
const now = new Date(2018, 4, 27, 19, 51, 10)
const result = timeSince("pt-BR", now, x.input)
- expect(result).toEqual(x.expectedPtBr)
+ expect(normalize(result)).toEqual(x.expectedPtBr)
})
})