test: add jest

This commit is contained in:
LeoKu
2021-10-17 20:31:36 +08:00
parent 024f9afd5c
commit 01c4307174
9 changed files with 2494 additions and 38 deletions

View File

@@ -0,0 +1,16 @@
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')
})
test('check locales completeness', () => {
const zh = Reflect.ownKeys(localeZH).sort()
const en = Reflect.ownKeys(localeEN).sort()
expect(zh).toEqual(en)
})

View File

@@ -97,7 +97,7 @@ export const NONE = 'none'
export const TRIGGER_PROBABILITY = 0.1
export const SPECIAL_AVATARS: Readonly<AvatarOption>[] = [
export const SPECIAL_AVATARS: Readonly<AvatarOption[]> = [
{
wrapperShape: 'squircle',
background: {

View File

@@ -102,7 +102,7 @@ export function getRandomAvatarOption(
return avatarOption
}
export function getSpecialAvatarOption() {
export function getSpecialAvatarOption(): AvatarOption {
return SPECIAL_AVATARS[Math.floor(Math.random() * SPECIAL_AVATARS.length)]
}