deno.land / x / fuse@v6.4.1 / test / typings.test.ts

typings.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import Fuse from '../dist/fuse'import { BattlePokedex } from './fixtures/pokedex'import { PokedexType } from './fixtures/types'
const idx = (result) => result.map((obj) => obj.refIndex)
const defaultOptions: Fuse.IFuseOptions<PokedexType> = { keys: ['alias', 'species', 'name', 'num'], threshold: 0.2}
describe('Search with typings', () => { test('When searching by number', () => { let pokeFuse = new Fuse(BattlePokedex, defaultOptions)
const pokemon = '2' const firstSearch = pokeFuse.search(pokemon)
const poke: PokedexType = firstSearch[0].item
// let x = Fuse.createIndex<PokedexType>( // ['alias', 'species', 'name', 'num'], // BattlePokedex, // )
const expected = { num: 2, species: 'Ivysaur', types: ['Grass', 'Poison'], genderRatio: { M: 0.875, F: 0.125 }, baseStats: { hp: 60, atk: 62, def: 63, spa: 80, spd: 80, spe: 60 }, abilities: { 0: 'Overgrow', H: 'Chlorophyll' }, heightm: 1, weightkg: 13, color: 'Green', prevo: 'bulbasaur', evos: ['venusaur'], evoLevel: 16, eggGroups: ['Monster', 'Grass'] }
expect(poke.species).toBe('Ivysaur') expect(poke).toMatchObject(expected) })})
describe('Search results with indices', () => { test('When searching by number', () => { interface Board { readonly name: string } const list: Array<Board> = [ { name: 'Arduino Duemilanove or Diecimila' } ] const options: Fuse.IFuseOptions<Board> = { includeMatches: true, minMatchCharLength: 1, keys: ['name'] }
const fuse = new Fuse(list, options) const results = fuse.search(`ar due di`)
expect(results.length).toBe(1)
const matches = results[0].matches
expect(matches.length).toBe(1) expect(matches[0].indices.length).toBe(9) expect(matches[0].indices[0]).toMatchObject([0, 4]) })})
describe('Logical search results', () => { interface Author { readonly name: string readonly title: string }
const list: Array<Author> = [ { title: 'The Code of the Wooster', name: 'Woodhouse' } ]
const options: Fuse.IFuseOptions<Author> = { useExtendedSearch: true, includeMatches: true, includeScore: true, keys: ['name', 'title'] }
const fuse = new Fuse(list, options)
test('Search: AND with multiple entries + exact match', () => { let result = fuse.search({ $and: [{ name: 'Woodhose' }, { title: "'The" }] }) expect(result.length).toBe(1) expect(idx(result)).toMatchObject([0]) })})
fuse

Version Info

Tagged at
3 years ago