deno.land / x / jotai@v1.8.4 / tests / babel / plugin-debug-label.test.ts

plugin-debug-label.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import path from 'path'import { transformSync } from '@babel/core'
const plugin = path.join(__dirname, '../../src/babel/plugin-debug-label')
const transform = (code: string, filename?: string) => transformSync(code, { babelrc: false, configFile: false, filename, plugins: [[plugin]], })?.code
it('Should add a debugLabel to an atom', () => { expect(transform(`const countAtom = atom(0);`)).toMatchInlineSnapshot(` "const countAtom = atom(0); countAtom.debugLabel = "countAtom";" `)})
it('Should handle a atom from a default export', () => { expect(transform(`const countAtom = jotai.atom(0);`)).toMatchInlineSnapshot(` "const countAtom = jotai.atom(0); countAtom.debugLabel = "countAtom";" `)})
it('Should handle a atom being exported', () => { expect(transform(`export const countAtom = atom(0);`)).toMatchInlineSnapshot(` "export const countAtom = atom(0); countAtom.debugLabel = "countAtom";" `)})
it('Should handle a default exported atom', () => { expect(transform(`export default atom(0);`, 'countAtom.ts')) .toMatchInlineSnapshot(` "const countAtom = atom(0); countAtom.debugLabel = "countAtom"; export default countAtom;" `)})
it('Should handle a default exported atom in a barrel file', () => { expect(transform(`export default atom(0);`, 'atoms/index.ts')) .toMatchInlineSnapshot(` "const atoms = atom(0); atoms.debugLabel = "atoms"; export default atoms;" `)})
it('Should handle all types of exports', () => { expect( transform( ` export const countAtom = atom(0); export default atom(0); `, 'atoms/index.ts' ) ).toMatchInlineSnapshot(` "export const countAtom = atom(0); countAtom.debugLabel = "countAtom"; const atoms = atom(0); atoms.debugLabel = "atoms"; export default atoms;" `)})
it('Should handle all atom types', () => { expect( transform( ` export const countAtom = atom(0);
const myFamily = atomFamily((param) => atom(param));
const countAtomWithDefault = atomWithDefault((get) => get(countAtom) * 2);
const observableAtom = atomWithObservable(() => {});
const reducerAtom = atomWithReducer(0, () => {});
const resetAtom = atomWithReset(0);
const storageAtom = atomWithStorage('count', 1);
const freezedAtom = freezeAtom(atom({ count: 0 }));
const loadedAtom = loadable(countAtom);
const selectedValueAtom = selectAtom(atom({ a: 0, b: 'othervalue' }), (v) => v.a);
const splittedAtom = splitAtom(atom([])); `, 'atoms/index.ts' ) ).toMatchInlineSnapshot(` "export const countAtom = atom(0); countAtom.debugLabel = "countAtom"; const myFamily = atomFamily(param => atom(param)); myFamily.debugLabel = "myFamily"; const countAtomWithDefault = atomWithDefault(get => get(countAtom) * 2); countAtomWithDefault.debugLabel = "countAtomWithDefault"; const observableAtom = atomWithObservable(() => {}); observableAtom.debugLabel = "observableAtom"; const reducerAtom = atomWithReducer(0, () => {}); reducerAtom.debugLabel = "reducerAtom"; const resetAtom = atomWithReset(0); resetAtom.debugLabel = "resetAtom"; const storageAtom = atomWithStorage('count', 1); storageAtom.debugLabel = "storageAtom"; const freezedAtom = freezeAtom(atom({ count: 0 })); freezedAtom.debugLabel = "freezedAtom"; const loadedAtom = loadable(countAtom); loadedAtom.debugLabel = "loadedAtom"; const selectedValueAtom = selectAtom(atom({ a: 0, b: 'othervalue' }), v => v.a); selectedValueAtom.debugLabel = "selectedValueAtom"; const splittedAtom = splitAtom(atom([])); splittedAtom.debugLabel = "splittedAtom";" `)})
jotai

Version Info

Tagged at
a year ago