Skip to content

Commit

Permalink
fix: use non-breaking spaces for assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Mar 24, 2023
1 parent b5c626b commit e0e7dcd
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions public/services/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -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: "" },
Expand All @@ -25,18 +33,18 @@ import { readFileSync } from "fs"
})
})
;[
{ input: new Date(2018, 4, 27, 10, 12, 59), expectedEn: "May 27, 2018 at 10:12AM", expectedPtBr: "27 de maio de 2018 às 10:12" },
{ input: new Date(2058, 12, 12, 23, 21, 53), expectedEn: "January 12, 2059 at 11:21PM", expectedPtBr: "12 de janeiro de 2059 às 23:21" },
{ input: "2018-04-11T18:13:33.128082", expectedEn: "April 11, 2018 at 6:13PM", expectedPtBr: "11 de abril de 2018 às 18:13" },
{ input: "2017-11-20T07:47:42.158142", expectedEn: "November 20, 2017 at 7:47AM", 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)
})
})
;[
Expand All @@ -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)
})
})
;[
Expand All @@ -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)
})
})
;[
Expand All @@ -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)
})
})

Expand Down

0 comments on commit e0e7dcd

Please sign in to comment.