utils.test.ts 748 字节
Newer Older
L
LeoKu 已提交
1 2 3 4 5 6 7 8 9 10 11
import localeEN from '../i18n/locales/en'
import localeZH from '../i18n/locales/zh'
import { highlightJSON } from '../utils'

test('highlightJSON', () => {
  const str = JSON.stringify({ a: 1, b: '2' })
  expect(highlightJSON(str)).toMatch('key')
  expect(highlightJSON(str)).toMatch('number')
  expect(highlightJSON(str)).toMatch('string')
})

L
LeoKu 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25
const getKeys = (target: Record<string, any>) => {
  const keys: string[] = []

  for (const key in target) {
    if (typeof target[key] === 'object') {
      keys.push(...getKeys(target[key]))
    } else {
      keys.push(key)
    }
  }

  return keys
}

L
LeoKu 已提交
26
test('check locales completeness', () => {
L
LeoKu 已提交
27 28
  const zh = getKeys(localeZH).sort()
  const en = getKeys(localeEN).sort()
L
LeoKu 已提交
29 30
  expect(zh).toEqual(en)
})