File size: 531 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { fixMojibake } from './fix-mojibake'

describe('Mojibake handling', () => {
  const validValues = [
    'hello-world',
    'hello world',
    encodeURIComponent('こんにちは'),
  ]
  it.each(validValues)(
    'should maintain value when encoding is correct $1',
    (testValue) => {
      expect(fixMojibake(testValue)).toBe(testValue)
    }
  )

  it('should fix invalid encoding', () => {
    expect(fixMojibake('/blog/ã\x81\x93ã\x82\x93ã\x81«ã\x81¡ã\x81¯')).toBe(
      '/blog/こんにちは'
    )
  })
})