@@ -8,8 +8,18 @@ const avatar = 'https://i.imgur.com/MK3eW3As.jpg';
8
8
const example = {
9
9
avatar,
10
10
} ;
11
+ const exampleWithBigInt = {
12
+ avatar,
13
+ bigint : BigInt ( 1000 ) ,
14
+ } ;
11
15
12
- it ( 'renders <JsonView /> Copied test case' , async ( ) => {
16
+ // BigInt(1000) should render to '1000n'
17
+ const exampleWithBigIntAnswer = {
18
+ avatar,
19
+ bigint : BigInt ( 1000 ) . toString ( ) + 'n' ,
20
+ } ;
21
+
22
+ it ( 'render <JsonView />, copy String test case' , async ( ) => {
13
23
const user = userEvent . setup ( ) ;
14
24
// Mock the necessary functions and values
15
25
const writeTextMock = jest . fn ( ) . mockResolvedValue ( undefined ) ;
@@ -54,7 +64,7 @@ it('renders <JsonView /> Copied test case', async () => {
54
64
jest . restoreAllMocks ( ) ;
55
65
} ) ;
56
66
57
- it ( 'renders <JsonView /> Copy number test case' , async ( ) => {
67
+ it ( 'render <JsonView />, copy Number test case' , async ( ) => {
58
68
const user = userEvent . setup ( ) ;
59
69
60
70
// Mock the necessary functions and values
@@ -77,7 +87,7 @@ it('renders <JsonView /> Copy number test case', async () => {
77
87
jest . restoreAllMocks ( ) ;
78
88
} ) ;
79
89
80
- it ( 'renders <JsonView.Copied /> render test case' , async ( ) => {
90
+ it ( 'render <JsonView.Copied />, copy Number test case' , async ( ) => {
81
91
const user = userEvent . setup ( ) ;
82
92
83
93
// Mock the necessary functions and values
@@ -107,7 +117,7 @@ it('renders <JsonView.Copied /> render test case', async () => {
107
117
jest . restoreAllMocks ( ) ;
108
118
} ) ;
109
119
110
- it ( 'renders <JsonView.Copied /> copy NaN test case' , async ( ) => {
120
+ it ( 'render <JsonView.Copied />, copy NaN test case' , async ( ) => {
111
121
const user = userEvent . setup ( ) ;
112
122
113
123
// Mock the necessary functions and values
@@ -129,7 +139,7 @@ it('renders <JsonView.Copied /> copy NaN test case', async () => {
129
139
jest . restoreAllMocks ( ) ;
130
140
} ) ;
131
141
132
- it ( 'renders <JsonView.Copied /> copy Infinity test case' , async ( ) => {
142
+ it ( 'render <JsonView.Copied />, copy Infinity test case' , async ( ) => {
133
143
const user = userEvent . setup ( ) ;
134
144
135
145
// Mock the necessary functions and values
@@ -151,7 +161,7 @@ it('renders <JsonView.Copied /> copy Infinity test case', async () => {
151
161
jest . restoreAllMocks ( ) ;
152
162
} ) ;
153
163
154
- it ( 'renders <JsonView.Copied /> copy Infinity test case' , async ( ) => {
164
+ it ( 'render <JsonView.Copied />, copy BigInt test case' , async ( ) => {
155
165
const user = userEvent . setup ( ) ;
156
166
157
167
// Mock the necessary functions and values
@@ -176,3 +186,26 @@ it('renders <JsonView.Copied /> copy Infinity test case', async () => {
176
186
expect ( bigint . nextElementSibling ) . toBeNull ( ) ;
177
187
jest . restoreAllMocks ( ) ;
178
188
} ) ;
189
+
190
+ it ( 'render <JsonView.Copied />, copy Object with BigInt test case' , async ( ) => {
191
+ const user = userEvent . setup ( ) ;
192
+
193
+ // Mock the necessary functions and values
194
+ const writeTextMock = jest . fn ( ) . mockResolvedValue ( undefined ) ;
195
+ jest . spyOn ( navigator . clipboard , 'writeText' ) . mockImplementation ( writeTextMock ) ;
196
+ const { container, debug } = render (
197
+ < JsonView value = { exampleWithBigInt } >
198
+ < JsonView . Copied data-testid = "copied" />
199
+ < JsonView . CountInfo data-testid = "countInfo" />
200
+ </ JsonView > ,
201
+ ) ;
202
+ expect ( container . firstElementChild ) . toBeInstanceOf ( Element ) ;
203
+ fireEvent . mouseEnter ( container . lastElementChild ! ) ;
204
+ const copied = screen . getByTestId ( 'copied' ) ;
205
+ await user . click ( copied ) ;
206
+ // Assertions
207
+ expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( JSON . stringify ( exampleWithBigIntAnswer , null , 2 ) ) ;
208
+ await user . unhover ( container . lastElementChild ! ) ;
209
+ // Restore the original implementation
210
+ jest . restoreAllMocks ( ) ;
211
+ } ) ;
0 commit comments