Przeglądaj źródła

cleaner way of compating localized formatted strings

Adam Shaw 7 lat temu
rodzic
commit
38eae17558

+ 7 - 5
tests/automated/datelib/formatting-api.js

@@ -16,9 +16,10 @@ describe('formatDate', function() {
       day: 'numeric',
       day: 'numeric',
       year: 'numeric',
       year: 'numeric',
       timeZoneName: 'short',
       timeZoneName: 'short',
-      timeZone: 'America/New_York' // but with no timeZoneImpl
+      timeZone: 'America/New_York', // but with no timeZoneImpl
+      omitCommas: true // for cross-browser
     })
     })
-    expect(str).toMatch(/^September 4, 2018,? 12:00 AM GMT-5$/)
+    expect(str).toBe('September 4 2018 12:00 AM GMT-5')
   })
   })
 
 
 })
 })
@@ -34,15 +35,16 @@ describe('formatRange', function() {
     expect(str).toBe('September 4 - October 4, 2018')
     expect(str).toBe('September 4 - October 4, 2018')
   })
   })
 
 
-  fit('works with timezone offset', function() {
+  it('works with timezone offset', function() {
     let str = FullCalendar.formatRange('2018-09-04T00:00:00-05:00', '2018-10-04T00:00:00-05:00', {
     let str = FullCalendar.formatRange('2018-09-04T00:00:00-05:00', '2018-10-04T00:00:00-05:00', {
       month: 'long',
       month: 'long',
       day: 'numeric',
       day: 'numeric',
       year: 'numeric',
       year: 'numeric',
       timeZoneName: 'short',
       timeZoneName: 'short',
-      timeZone: 'America/New_York' // but with no timeZoneImpl
+      timeZone: 'America/New_York', // but with no timeZoneImpl
+      omitCommas: true // for cross-browser
     })
     })
-    expect(str).toMatch(/^September 4 - October 4, 2018,? 12:00 AM GMT-5$/)
+    expect(str).toBe('September 4 - October 4 2018 12:00 AM GMT-5')
   })
   })
 
 
 })
 })

+ 6 - 8
tests/automated/datelib/main.js

@@ -1,8 +1,6 @@
 import { formatPrettyTimeZoneOffset, formatIsoTimeZoneOffset, formatIsoWithoutTz } from './utils'
 import { formatPrettyTimeZoneOffset, formatIsoTimeZoneOffset, formatIsoWithoutTz } from './utils'
 import { getDSTDeadZone } from './dst-dead-zone'
 import { getDSTDeadZone } from './dst-dead-zone'
 
 
-// can use omitCommas instead of match
-
 describe('datelib', function() {
 describe('datelib', function() {
   var DateEnv = FullCalendar.DateEnv
   var DateEnv = FullCalendar.DateEnv
   var createFormatter = FullCalendar.createFormatter
   var createFormatter = FullCalendar.createFormatter
@@ -179,10 +177,11 @@ describe('datelib', function() {
         hour: '2-digit',
         hour: '2-digit',
         minute: '2-digit',
         minute: '2-digit',
         year: 'numeric',
         year: 'numeric',
-        timeZoneName: 'short'
+        timeZoneName: 'short',
+        omitCommas: true // for cross-browser
       })
       })
       var s = env.format(marker, formatter)
       var s = env.format(marker, formatter)
-      expect(s).toMatch(/^Friday, June 8, 2018,? 12:00 AM (UTC|GMT)$/)
+      expect(s).toBe('Friday June 8 2018 12:00 AM UTC')
     })
     })
 
 
 
 
@@ -578,12 +577,11 @@ describe('datelib', function() {
         year: 'numeric',
         year: 'numeric',
         hour: '2-digit',
         hour: '2-digit',
         minute: '2-digit',
         minute: '2-digit',
-        timeZoneName: 'short'
+        timeZoneName: 'short',
+        omitCommas: true // for cross-browser
       })
       })
       var s = env.format(marker, formatter)
       var s = env.format(marker, formatter)
-      expect(s).toMatch(
-        new RegExp('^Friday, June 8, 2018,? 12:00 AM ' + formatPrettyTimeZoneOffset(new Date(2018, 5, 8)) + '$')
-      )
+      expect(s).toBe('Friday June 8 2018 12:00 AM ' + formatPrettyTimeZoneOffset(new Date(2018, 5, 8)))
     })
     })
 
 
     it('can output a timezone only', function() {
     it('can output a timezone only', function() {