@wordpress/abilities 0.20.0 → 0.20.2-next.v.202609031004.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +6 -5
- package/src/store/tests/actions.test.ts +29 -27
- package/src/store/tests/reducer.test.ts +53 -20
- package/src/store/tests/selectors.test.ts +4 -2
- package/src/tests/api.test.ts +84 -67
- package/src/tests/validation.test.ts +18 -16
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/abilities",
|
|
3
|
-
"version": "0.20.0",
|
|
3
|
+
"version": "0.20.2-next.v.202609031004.0",
|
|
4
4
|
"description": "JavaScript client for WordPress Abilities API.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -45,17 +45,18 @@
|
|
|
45
45
|
},
|
|
46
46
|
"types": "build-types",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@wordpress/data": "^10.54.0",
|
|
49
|
-
"@wordpress/i18n": "^6.27.0",
|
|
48
|
+
"@wordpress/data": "^10.54.2-next.v.202609031004.0",
|
|
49
|
+
"@wordpress/i18n": "^6.27.1-next.v.202609031004.0",
|
|
50
50
|
"ajv": "^8.20.0",
|
|
51
51
|
"ajv-draft-04": "^1.0.0",
|
|
52
52
|
"ajv-formats": "^3.0.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@types/jest": "^30.0.0"
|
|
55
|
+
"@types/jest": "^30.0.0",
|
|
56
|
+
"vitest": "^4.1.10"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|
|
59
60
|
},
|
|
60
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "7275d6c6d93b542fca3cd98cdb9c7344ddd11e19"
|
|
61
62
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for store actions.
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
6
|
import {
|
|
5
7
|
registerAbility,
|
|
6
8
|
unregisterAbility,
|
|
@@ -22,10 +24,10 @@ import type {
|
|
|
22
24
|
describe( 'Store Actions', () => {
|
|
23
25
|
describe( 'registerAbility', () => {
|
|
24
26
|
let mockSelect: any;
|
|
25
|
-
let mockDispatch:
|
|
27
|
+
let mockDispatch: Mock;
|
|
26
28
|
|
|
27
29
|
beforeEach( () => {
|
|
28
|
-
|
|
30
|
+
vi.clearAllMocks();
|
|
29
31
|
const defaultCategories = [
|
|
30
32
|
{
|
|
31
33
|
slug: 'test-category',
|
|
@@ -40,11 +42,11 @@ describe( 'Store Actions', () => {
|
|
|
40
42
|
];
|
|
41
43
|
|
|
42
44
|
mockSelect = {
|
|
43
|
-
getAbility:
|
|
44
|
-
getAbilityCategories:
|
|
45
|
+
getAbility: vi.fn().mockReturnValue( null ),
|
|
46
|
+
getAbilityCategories: vi
|
|
45
47
|
.fn()
|
|
46
48
|
.mockReturnValue( defaultCategories ),
|
|
47
|
-
getAbilityCategory:
|
|
49
|
+
getAbilityCategory: vi.fn().mockImplementation( ( slug ) => {
|
|
48
50
|
const categories: Record< string, any > = {
|
|
49
51
|
'test-category': {
|
|
50
52
|
slug: 'test-category',
|
|
@@ -60,7 +62,7 @@ describe( 'Store Actions', () => {
|
|
|
60
62
|
return categories[ slug ] || null;
|
|
61
63
|
} ),
|
|
62
64
|
};
|
|
63
|
-
mockDispatch =
|
|
65
|
+
mockDispatch = vi.fn();
|
|
64
66
|
} );
|
|
65
67
|
|
|
66
68
|
it( 'should register a valid client ability', () => {
|
|
@@ -81,7 +83,7 @@ describe( 'Store Actions', () => {
|
|
|
81
83
|
success: { type: 'boolean' },
|
|
82
84
|
},
|
|
83
85
|
},
|
|
84
|
-
callback:
|
|
86
|
+
callback: vi.fn(),
|
|
85
87
|
};
|
|
86
88
|
|
|
87
89
|
const action = registerAbility( ability );
|
|
@@ -124,7 +126,7 @@ describe( 'Store Actions', () => {
|
|
|
124
126
|
label: 'Test Ability',
|
|
125
127
|
description: 'Test description',
|
|
126
128
|
category: 'test-category',
|
|
127
|
-
callback:
|
|
129
|
+
callback: vi.fn(),
|
|
128
130
|
};
|
|
129
131
|
|
|
130
132
|
const action = registerAbility( ability );
|
|
@@ -151,7 +153,7 @@ describe( 'Store Actions', () => {
|
|
|
151
153
|
label: 'Test Ability',
|
|
152
154
|
description: 'Test description',
|
|
153
155
|
category: 'test-category',
|
|
154
|
-
callback:
|
|
156
|
+
callback: vi.fn(),
|
|
155
157
|
};
|
|
156
158
|
|
|
157
159
|
const action = registerAbility( ability );
|
|
@@ -180,7 +182,7 @@ describe( 'Store Actions', () => {
|
|
|
180
182
|
label: 'Test Ability',
|
|
181
183
|
description: 'Test description',
|
|
182
184
|
category: 'test-category',
|
|
183
|
-
callback:
|
|
185
|
+
callback: vi.fn(),
|
|
184
186
|
};
|
|
185
187
|
|
|
186
188
|
mockSelect.getAbility.mockReturnValue( null );
|
|
@@ -205,7 +207,7 @@ describe( 'Store Actions', () => {
|
|
|
205
207
|
label: '',
|
|
206
208
|
description: 'Test description',
|
|
207
209
|
category: 'test-category',
|
|
208
|
-
callback:
|
|
210
|
+
callback: vi.fn(),
|
|
209
211
|
};
|
|
210
212
|
|
|
211
213
|
const action = registerAbility( ability );
|
|
@@ -222,7 +224,7 @@ describe( 'Store Actions', () => {
|
|
|
222
224
|
label: 'Test Ability',
|
|
223
225
|
description: '',
|
|
224
226
|
category: 'test-category',
|
|
225
|
-
callback:
|
|
227
|
+
callback: vi.fn(),
|
|
226
228
|
};
|
|
227
229
|
|
|
228
230
|
const action = registerAbility( ability );
|
|
@@ -239,7 +241,7 @@ describe( 'Store Actions', () => {
|
|
|
239
241
|
label: 'Test Ability',
|
|
240
242
|
description: 'Test description',
|
|
241
243
|
category: '',
|
|
242
|
-
callback:
|
|
244
|
+
callback: vi.fn(),
|
|
243
245
|
};
|
|
244
246
|
|
|
245
247
|
const action = registerAbility( ability );
|
|
@@ -267,7 +269,7 @@ describe( 'Store Actions', () => {
|
|
|
267
269
|
label: 'Test Ability',
|
|
268
270
|
description: 'Test description',
|
|
269
271
|
category: invalidCategory,
|
|
270
|
-
callback:
|
|
272
|
+
callback: vi.fn(),
|
|
271
273
|
};
|
|
272
274
|
|
|
273
275
|
const action = registerAbility( ability );
|
|
@@ -296,7 +298,7 @@ describe( 'Store Actions', () => {
|
|
|
296
298
|
label: 'Test Ability',
|
|
297
299
|
description: 'Test description',
|
|
298
300
|
category: validCategory,
|
|
299
|
-
callback:
|
|
301
|
+
callback: vi.fn(),
|
|
300
302
|
};
|
|
301
303
|
|
|
302
304
|
const categoriesForTest = [
|
|
@@ -357,7 +359,7 @@ describe( 'Store Actions', () => {
|
|
|
357
359
|
label: 'Test Ability',
|
|
358
360
|
description: 'Test description',
|
|
359
361
|
category: 'non-existent-category',
|
|
360
|
-
callback:
|
|
362
|
+
callback: vi.fn(),
|
|
361
363
|
};
|
|
362
364
|
|
|
363
365
|
const action = registerAbility( ability );
|
|
@@ -393,7 +395,7 @@ describe( 'Store Actions', () => {
|
|
|
393
395
|
label: 'Test Ability',
|
|
394
396
|
description: 'Test description',
|
|
395
397
|
category: 'data-retrieval',
|
|
396
|
-
callback:
|
|
398
|
+
callback: vi.fn(),
|
|
397
399
|
};
|
|
398
400
|
|
|
399
401
|
const action = registerAbility( ability );
|
|
@@ -433,7 +435,7 @@ describe( 'Store Actions', () => {
|
|
|
433
435
|
label: 'Test Ability',
|
|
434
436
|
description: 'Test ability with custom scope',
|
|
435
437
|
category: 'test-category',
|
|
436
|
-
callback:
|
|
438
|
+
callback: vi.fn(),
|
|
437
439
|
meta: {
|
|
438
440
|
scope: 'editor',
|
|
439
441
|
customProperty: 'customValue',
|
|
@@ -471,7 +473,7 @@ describe( 'Store Actions', () => {
|
|
|
471
473
|
label: 'Test Ability',
|
|
472
474
|
description: 'Test description',
|
|
473
475
|
category: 'test-category',
|
|
474
|
-
callback:
|
|
476
|
+
callback: vi.fn(),
|
|
475
477
|
};
|
|
476
478
|
|
|
477
479
|
const action = registerAbility( ability );
|
|
@@ -507,15 +509,15 @@ describe( 'Store Actions', () => {
|
|
|
507
509
|
|
|
508
510
|
describe( 'registerAbilityCategory', () => {
|
|
509
511
|
let mockSelect: any;
|
|
510
|
-
let mockDispatch:
|
|
512
|
+
let mockDispatch: Mock;
|
|
511
513
|
|
|
512
514
|
beforeEach( () => {
|
|
513
|
-
|
|
515
|
+
vi.clearAllMocks();
|
|
514
516
|
mockSelect = {
|
|
515
|
-
getAbilityCategory:
|
|
516
|
-
getAbilityCategories:
|
|
517
|
+
getAbilityCategory: vi.fn().mockReturnValue( null ),
|
|
518
|
+
getAbilityCategories: vi.fn().mockReturnValue( [] ),
|
|
517
519
|
};
|
|
518
|
-
mockDispatch =
|
|
520
|
+
mockDispatch = vi.fn();
|
|
519
521
|
} );
|
|
520
522
|
|
|
521
523
|
it( 'should register a valid category', () => {
|
|
@@ -808,10 +810,10 @@ describe( 'Store Actions', () => {
|
|
|
808
810
|
description: categoryArgs.description,
|
|
809
811
|
},
|
|
810
812
|
];
|
|
811
|
-
mockSelect.getAbilityCategories =
|
|
813
|
+
mockSelect.getAbilityCategories = vi
|
|
812
814
|
.fn()
|
|
813
815
|
.mockReturnValue( categoriesWithNew );
|
|
814
|
-
mockSelect.getAbility =
|
|
816
|
+
mockSelect.getAbility = vi.fn().mockReturnValue( null );
|
|
815
817
|
mockDispatch.mockClear();
|
|
816
818
|
|
|
817
819
|
// Register an ability using the new category
|
|
@@ -820,7 +822,7 @@ describe( 'Store Actions', () => {
|
|
|
820
822
|
label: 'Test Ability',
|
|
821
823
|
description: 'Test description',
|
|
822
824
|
category: categorySlug,
|
|
823
|
-
callback:
|
|
825
|
+
callback: vi.fn(),
|
|
824
826
|
};
|
|
825
827
|
|
|
826
828
|
const abilityAction = registerAbility( ability );
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for store reducer.
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
4
6
|
import reducer from '../reducer';
|
|
5
7
|
import {
|
|
6
8
|
REGISTER_ABILITY,
|
|
@@ -19,16 +21,20 @@ describe( 'Store Reducer', () => {
|
|
|
19
21
|
name: 'test/ability',
|
|
20
22
|
label: 'Test Ability',
|
|
21
23
|
description: 'Test ability',
|
|
24
|
+
category: 'test-category',
|
|
22
25
|
callback: () => Promise.resolve( {} ),
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
const action = {
|
|
26
29
|
type: REGISTER_ABILITY,
|
|
27
30
|
ability,
|
|
28
|
-
};
|
|
31
|
+
} as const;
|
|
29
32
|
|
|
30
33
|
const state = reducer(
|
|
31
|
-
{
|
|
34
|
+
{
|
|
35
|
+
abilitiesByName: defaultState,
|
|
36
|
+
categoriesBySlug: {},
|
|
37
|
+
},
|
|
32
38
|
action
|
|
33
39
|
);
|
|
34
40
|
|
|
@@ -45,6 +51,7 @@ describe( 'Store Reducer', () => {
|
|
|
45
51
|
name: 'test/ability',
|
|
46
52
|
label: 'Test Ability',
|
|
47
53
|
description: 'Test ability',
|
|
54
|
+
category: 'test-category',
|
|
48
55
|
callback: () => Promise.resolve( {} ),
|
|
49
56
|
// Extra properties that should be filtered out
|
|
50
57
|
_links: { self: { href: '/test' } },
|
|
@@ -54,10 +61,13 @@ describe( 'Store Reducer', () => {
|
|
|
54
61
|
const action = {
|
|
55
62
|
type: REGISTER_ABILITY,
|
|
56
63
|
ability,
|
|
57
|
-
};
|
|
64
|
+
} as const;
|
|
58
65
|
|
|
59
66
|
const state = reducer(
|
|
60
|
-
{
|
|
67
|
+
{
|
|
68
|
+
abilitiesByName: defaultState,
|
|
69
|
+
categoriesBySlug: {},
|
|
70
|
+
},
|
|
61
71
|
action
|
|
62
72
|
);
|
|
63
73
|
const registeredAbility =
|
|
@@ -80,6 +90,7 @@ describe( 'Store Reducer', () => {
|
|
|
80
90
|
name: 'test/ability',
|
|
81
91
|
label: 'Old Label',
|
|
82
92
|
description: 'Old description',
|
|
93
|
+
category: 'test-category',
|
|
83
94
|
},
|
|
84
95
|
};
|
|
85
96
|
|
|
@@ -87,16 +98,20 @@ describe( 'Store Reducer', () => {
|
|
|
87
98
|
name: 'test/ability',
|
|
88
99
|
label: 'New Label',
|
|
89
100
|
description: 'New description',
|
|
101
|
+
category: 'test-category',
|
|
90
102
|
input_schema: { type: 'string' },
|
|
91
103
|
};
|
|
92
104
|
|
|
93
105
|
const action = {
|
|
94
106
|
type: REGISTER_ABILITY,
|
|
95
107
|
ability,
|
|
96
|
-
};
|
|
108
|
+
} as const;
|
|
97
109
|
|
|
98
110
|
const state = reducer(
|
|
99
|
-
{
|
|
111
|
+
{
|
|
112
|
+
abilitiesByName: initialState,
|
|
113
|
+
categoriesBySlug: {},
|
|
114
|
+
},
|
|
100
115
|
action
|
|
101
116
|
);
|
|
102
117
|
|
|
@@ -119,21 +134,26 @@ describe( 'Store Reducer', () => {
|
|
|
119
134
|
name: 'test/ability1',
|
|
120
135
|
label: 'Test Ability 1',
|
|
121
136
|
description: 'First test ability',
|
|
137
|
+
category: 'test-category',
|
|
122
138
|
},
|
|
123
139
|
'test/ability2': {
|
|
124
140
|
name: 'test/ability2',
|
|
125
141
|
label: 'Test Ability 2',
|
|
126
142
|
description: 'Second test ability',
|
|
143
|
+
category: 'test-category',
|
|
127
144
|
},
|
|
128
145
|
};
|
|
129
146
|
|
|
130
147
|
const action = {
|
|
131
148
|
type: UNREGISTER_ABILITY,
|
|
132
149
|
name: 'test/ability1',
|
|
133
|
-
};
|
|
150
|
+
} as const;
|
|
134
151
|
|
|
135
152
|
const state = reducer(
|
|
136
|
-
{
|
|
153
|
+
{
|
|
154
|
+
abilitiesByName: initialState,
|
|
155
|
+
categoriesBySlug: {},
|
|
156
|
+
},
|
|
137
157
|
action
|
|
138
158
|
);
|
|
139
159
|
|
|
@@ -153,16 +173,20 @@ describe( 'Store Reducer', () => {
|
|
|
153
173
|
name: 'test/ability',
|
|
154
174
|
label: 'Test Ability',
|
|
155
175
|
description: 'Test ability',
|
|
176
|
+
category: 'test-category',
|
|
156
177
|
},
|
|
157
178
|
};
|
|
158
179
|
|
|
159
180
|
const action = {
|
|
160
181
|
type: UNREGISTER_ABILITY,
|
|
161
182
|
name: 'test/non-existent',
|
|
162
|
-
};
|
|
183
|
+
} as const;
|
|
163
184
|
|
|
164
185
|
const state = reducer(
|
|
165
|
-
{
|
|
186
|
+
{
|
|
187
|
+
abilitiesByName: initialState,
|
|
188
|
+
categoriesBySlug: {},
|
|
189
|
+
},
|
|
166
190
|
action
|
|
167
191
|
);
|
|
168
192
|
|
|
@@ -176,8 +200,13 @@ describe( 'Store Reducer', () => {
|
|
|
176
200
|
};
|
|
177
201
|
|
|
178
202
|
const state = reducer(
|
|
179
|
-
{
|
|
180
|
-
|
|
203
|
+
{
|
|
204
|
+
abilitiesByName: defaultState,
|
|
205
|
+
categoriesBySlug: {},
|
|
206
|
+
},
|
|
207
|
+
// Intentionally bypass the static contract to cover the
|
|
208
|
+
// reducer's defensive handling of invalid runtime input.
|
|
209
|
+
action as never
|
|
181
210
|
);
|
|
182
211
|
|
|
183
212
|
expect( state.abilitiesByName ).toEqual( defaultState );
|
|
@@ -199,7 +228,7 @@ describe( 'Store Reducer', () => {
|
|
|
199
228
|
const action = {
|
|
200
229
|
type: REGISTER_ABILITY_CATEGORY,
|
|
201
230
|
category,
|
|
202
|
-
};
|
|
231
|
+
} as const;
|
|
203
232
|
|
|
204
233
|
const state = reducer(
|
|
205
234
|
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
@@ -225,7 +254,7 @@ describe( 'Store Reducer', () => {
|
|
|
225
254
|
const action = {
|
|
226
255
|
type: REGISTER_ABILITY_CATEGORY,
|
|
227
256
|
category,
|
|
228
|
-
};
|
|
257
|
+
} as const;
|
|
229
258
|
|
|
230
259
|
const state = reducer(
|
|
231
260
|
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
@@ -251,7 +280,7 @@ describe( 'Store Reducer', () => {
|
|
|
251
280
|
const action = {
|
|
252
281
|
type: REGISTER_ABILITY_CATEGORY,
|
|
253
282
|
category,
|
|
254
|
-
};
|
|
283
|
+
} as const;
|
|
255
284
|
|
|
256
285
|
const state = reducer(
|
|
257
286
|
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
@@ -294,7 +323,7 @@ describe( 'Store Reducer', () => {
|
|
|
294
323
|
const action = {
|
|
295
324
|
type: REGISTER_ABILITY_CATEGORY,
|
|
296
325
|
category,
|
|
297
|
-
};
|
|
326
|
+
} as const;
|
|
298
327
|
|
|
299
328
|
const state = reducer(
|
|
300
329
|
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
@@ -320,7 +349,9 @@ describe( 'Store Reducer', () => {
|
|
|
320
349
|
|
|
321
350
|
const state = reducer(
|
|
322
351
|
{ categoriesBySlug: defaultState, abilitiesByName: {} },
|
|
323
|
-
|
|
352
|
+
// Intentionally bypass the static contract to cover the
|
|
353
|
+
// reducer's defensive handling of invalid runtime input.
|
|
354
|
+
action as never
|
|
324
355
|
);
|
|
325
356
|
|
|
326
357
|
expect( state.categoriesBySlug ).toEqual( defaultState );
|
|
@@ -345,7 +376,7 @@ describe( 'Store Reducer', () => {
|
|
|
345
376
|
const action = {
|
|
346
377
|
type: UNREGISTER_ABILITY_CATEGORY,
|
|
347
378
|
slug: 'category1',
|
|
348
|
-
};
|
|
379
|
+
} as const;
|
|
349
380
|
|
|
350
381
|
const state = reducer(
|
|
351
382
|
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
@@ -370,7 +401,7 @@ describe( 'Store Reducer', () => {
|
|
|
370
401
|
const action = {
|
|
371
402
|
type: UNREGISTER_ABILITY_CATEGORY,
|
|
372
403
|
slug: 'non-existent',
|
|
373
|
-
};
|
|
404
|
+
} as const;
|
|
374
405
|
|
|
375
406
|
const state = reducer(
|
|
376
407
|
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
@@ -396,7 +427,9 @@ describe( 'Store Reducer', () => {
|
|
|
396
427
|
|
|
397
428
|
const state = reducer(
|
|
398
429
|
{ categoriesBySlug: initialState, abilitiesByName: {} },
|
|
399
|
-
|
|
430
|
+
// Intentionally bypass the static contract to cover the
|
|
431
|
+
// reducer's defensive handling of invalid runtime input.
|
|
432
|
+
action as never
|
|
400
433
|
);
|
|
401
434
|
|
|
402
435
|
expect( state.categoriesBySlug ).toEqual( initialState );
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for store selectors.
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
6
|
import {
|
|
5
7
|
getAbilities,
|
|
6
8
|
getAbility,
|
|
@@ -29,7 +31,7 @@ describe( 'Store Selectors', () => {
|
|
|
29
31
|
category: 'test-category',
|
|
30
32
|
input_schema: { type: 'object' },
|
|
31
33
|
output_schema: { type: 'object' },
|
|
32
|
-
callback:
|
|
34
|
+
callback: vi.fn(),
|
|
33
35
|
},
|
|
34
36
|
},
|
|
35
37
|
categoriesBySlug: {},
|
|
@@ -206,7 +208,7 @@ describe( 'Store Selectors', () => {
|
|
|
206
208
|
category: 'test-category',
|
|
207
209
|
input_schema: { type: 'object' },
|
|
208
210
|
output_schema: { type: 'object' },
|
|
209
|
-
callback:
|
|
211
|
+
callback: vi.fn(),
|
|
210
212
|
},
|
|
211
213
|
},
|
|
212
214
|
categoriesBySlug: {},
|
package/src/tests/api.test.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for API functions.
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
|
|
4
6
|
import { dispatch, select } from '@wordpress/data';
|
|
5
7
|
import {
|
|
6
8
|
getAbilities,
|
|
@@ -14,18 +16,37 @@ import {
|
|
|
14
16
|
import { store } from '../store';
|
|
15
17
|
import type { Ability, AbilityCategory } from '../types';
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
vi.mock( import( '@wordpress/data' ), async ( importOriginal ) => ( {
|
|
20
|
+
...( await importOriginal() ),
|
|
21
|
+
select: vi.fn(),
|
|
22
|
+
dispatch: vi.fn(),
|
|
20
23
|
} ) );
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
vi.mock( import( '../store' ), async ( importOriginal ) => ( {
|
|
26
|
+
...( await importOriginal() ),
|
|
27
|
+
store: 'abilities-api/store' as unknown as typeof store,
|
|
24
28
|
} ) );
|
|
25
29
|
|
|
30
|
+
type AbilitySelectors = ReturnType< typeof select< typeof store > >;
|
|
31
|
+
type AbilityDispatch = ReturnType< typeof dispatch< typeof store > >;
|
|
32
|
+
const mockedSelect = vi.mocked( select ) as Mock<
|
|
33
|
+
( storeDescriptor: typeof store ) => AbilitySelectors
|
|
34
|
+
>;
|
|
35
|
+
const mockedDispatch = vi.mocked( dispatch ) as Mock<
|
|
36
|
+
( storeDescriptor: typeof store ) => AbilityDispatch
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
const mockSelect = ( selectors: Partial< AbilitySelectors > ) => {
|
|
40
|
+
mockedSelect.mockReturnValue( selectors as AbilitySelectors );
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const mockDispatch = ( actions: Partial< AbilityDispatch > ) => {
|
|
44
|
+
mockedDispatch.mockReturnValue( actions as AbilityDispatch );
|
|
45
|
+
};
|
|
46
|
+
|
|
26
47
|
describe( 'API functions', () => {
|
|
27
48
|
beforeEach( () => {
|
|
28
|
-
|
|
49
|
+
vi.clearAllMocks();
|
|
29
50
|
} );
|
|
30
51
|
|
|
31
52
|
describe( 'getAbilities', () => {
|
|
@@ -49,8 +70,8 @@ describe( 'API functions', () => {
|
|
|
49
70
|
},
|
|
50
71
|
];
|
|
51
72
|
|
|
52
|
-
const mockGetAbilities =
|
|
53
|
-
(
|
|
73
|
+
const mockGetAbilities = vi.fn().mockReturnValue( mockAbilities );
|
|
74
|
+
mockSelect( {
|
|
54
75
|
getAbilities: mockGetAbilities,
|
|
55
76
|
} );
|
|
56
77
|
|
|
@@ -81,8 +102,8 @@ describe( 'API functions', () => {
|
|
|
81
102
|
},
|
|
82
103
|
];
|
|
83
104
|
|
|
84
|
-
const mockGetAbilities =
|
|
85
|
-
(
|
|
105
|
+
const mockGetAbilities = vi.fn().mockReturnValue( mockAbilities );
|
|
106
|
+
mockSelect( {
|
|
86
107
|
getAbilities: mockGetAbilities,
|
|
87
108
|
} );
|
|
88
109
|
|
|
@@ -107,8 +128,8 @@ describe( 'API functions', () => {
|
|
|
107
128
|
output_schema: { type: 'object' },
|
|
108
129
|
};
|
|
109
130
|
|
|
110
|
-
const mockGetAbility =
|
|
111
|
-
(
|
|
131
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
132
|
+
mockSelect( {
|
|
112
133
|
getAbility: mockGetAbility,
|
|
113
134
|
} );
|
|
114
135
|
|
|
@@ -122,14 +143,14 @@ describe( 'API functions', () => {
|
|
|
122
143
|
|
|
123
144
|
describe( 'registerAbility', () => {
|
|
124
145
|
it( 'should register a client-side ability with a callback', () => {
|
|
125
|
-
const mockRegisterAbility =
|
|
126
|
-
(
|
|
146
|
+
const mockRegisterAbility = vi.fn();
|
|
147
|
+
mockDispatch( {
|
|
127
148
|
registerAbility: mockRegisterAbility,
|
|
128
149
|
} );
|
|
129
150
|
|
|
130
151
|
// Mock select to return no existing ability
|
|
131
|
-
(
|
|
132
|
-
getAbility:
|
|
152
|
+
mockSelect( {
|
|
153
|
+
getAbility: vi.fn().mockReturnValue( null ),
|
|
133
154
|
} );
|
|
134
155
|
|
|
135
156
|
const ability = {
|
|
@@ -139,7 +160,7 @@ describe( 'API functions', () => {
|
|
|
139
160
|
category: 'test-category',
|
|
140
161
|
input_schema: { type: 'object' },
|
|
141
162
|
output_schema: { type: 'object' },
|
|
142
|
-
callback:
|
|
163
|
+
callback: vi.fn(),
|
|
143
164
|
};
|
|
144
165
|
|
|
145
166
|
registerAbility( ability );
|
|
@@ -151,8 +172,8 @@ describe( 'API functions', () => {
|
|
|
151
172
|
|
|
152
173
|
describe( 'unregisterAbility', () => {
|
|
153
174
|
it( 'should unregister an ability', () => {
|
|
154
|
-
const mockUnregisterAbility =
|
|
155
|
-
(
|
|
175
|
+
const mockUnregisterAbility = vi.fn();
|
|
176
|
+
mockDispatch( {
|
|
156
177
|
unregisterAbility: mockUnregisterAbility,
|
|
157
178
|
} );
|
|
158
179
|
|
|
@@ -167,7 +188,7 @@ describe( 'API functions', () => {
|
|
|
167
188
|
|
|
168
189
|
describe( 'executeAbility', () => {
|
|
169
190
|
it( 'should execute a server-side ability via callback', async () => {
|
|
170
|
-
const mockServerCallback =
|
|
191
|
+
const mockServerCallback = vi
|
|
171
192
|
.fn()
|
|
172
193
|
.mockResolvedValue( { success: true, result: 'test' } );
|
|
173
194
|
const mockAbility: Ability = {
|
|
@@ -187,8 +208,8 @@ describe( 'API functions', () => {
|
|
|
187
208
|
meta: { annotations: { serverRegistered: true } },
|
|
188
209
|
};
|
|
189
210
|
|
|
190
|
-
const mockGetAbility =
|
|
191
|
-
(
|
|
211
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
212
|
+
mockSelect( {
|
|
192
213
|
getAbility: mockGetAbility,
|
|
193
214
|
} );
|
|
194
215
|
|
|
@@ -203,9 +224,7 @@ describe( 'API functions', () => {
|
|
|
203
224
|
} );
|
|
204
225
|
|
|
205
226
|
it( 'should execute a client-side ability locally', async () => {
|
|
206
|
-
const mockCallback =
|
|
207
|
-
.fn()
|
|
208
|
-
.mockResolvedValue( { success: true } );
|
|
227
|
+
const mockCallback = vi.fn().mockResolvedValue( { success: true } );
|
|
209
228
|
const mockAbility: Ability = {
|
|
210
229
|
name: 'test/client-ability',
|
|
211
230
|
label: 'Client Ability',
|
|
@@ -217,8 +236,8 @@ describe( 'API functions', () => {
|
|
|
217
236
|
meta: { annotations: { clientRegistered: true } },
|
|
218
237
|
};
|
|
219
238
|
|
|
220
|
-
const mockGetAbility =
|
|
221
|
-
(
|
|
239
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
240
|
+
mockSelect( {
|
|
222
241
|
getAbility: mockGetAbility,
|
|
223
242
|
} );
|
|
224
243
|
|
|
@@ -233,8 +252,8 @@ describe( 'API functions', () => {
|
|
|
233
252
|
} );
|
|
234
253
|
|
|
235
254
|
it( 'should throw error if ability not found', async () => {
|
|
236
|
-
const mockGetAbility =
|
|
237
|
-
(
|
|
255
|
+
const mockGetAbility = vi.fn().mockReturnValue( null );
|
|
256
|
+
mockSelect( {
|
|
238
257
|
getAbility: mockGetAbility,
|
|
239
258
|
} );
|
|
240
259
|
|
|
@@ -244,7 +263,7 @@ describe( 'API functions', () => {
|
|
|
244
263
|
} );
|
|
245
264
|
|
|
246
265
|
it( 'should validate input for client abilities', async () => {
|
|
247
|
-
const mockCallback =
|
|
266
|
+
const mockCallback = vi.fn();
|
|
248
267
|
const mockAbility: Ability = {
|
|
249
268
|
name: 'test/client-ability',
|
|
250
269
|
label: 'Client Ability',
|
|
@@ -262,8 +281,8 @@ describe( 'API functions', () => {
|
|
|
262
281
|
meta: { annotations: { clientRegistered: true } },
|
|
263
282
|
};
|
|
264
283
|
|
|
265
|
-
const mockGetAbility =
|
|
266
|
-
(
|
|
284
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
285
|
+
mockSelect( {
|
|
267
286
|
getAbility: mockGetAbility,
|
|
268
287
|
} );
|
|
269
288
|
|
|
@@ -273,7 +292,7 @@ describe( 'API functions', () => {
|
|
|
273
292
|
} );
|
|
274
293
|
|
|
275
294
|
it( 'should execute a read-only server ability', async () => {
|
|
276
|
-
const mockServerCallback =
|
|
295
|
+
const mockServerCallback = vi
|
|
277
296
|
.fn()
|
|
278
297
|
.mockResolvedValue( { data: 'read-only data' } );
|
|
279
298
|
const mockAbility: Ability = {
|
|
@@ -295,8 +314,8 @@ describe( 'API functions', () => {
|
|
|
295
314
|
callback: mockServerCallback,
|
|
296
315
|
};
|
|
297
316
|
|
|
298
|
-
const mockGetAbility =
|
|
299
|
-
(
|
|
317
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
318
|
+
mockSelect( {
|
|
300
319
|
getAbility: mockGetAbility,
|
|
301
320
|
} );
|
|
302
321
|
|
|
@@ -308,7 +327,7 @@ describe( 'API functions', () => {
|
|
|
308
327
|
} );
|
|
309
328
|
|
|
310
329
|
it( 'should execute a read-only ability with empty input', async () => {
|
|
311
|
-
const mockServerCallback =
|
|
330
|
+
const mockServerCallback = vi
|
|
312
331
|
.fn()
|
|
313
332
|
.mockResolvedValue( { data: 'read-only data' } );
|
|
314
333
|
const mockAbility: Ability = {
|
|
@@ -324,8 +343,8 @@ describe( 'API functions', () => {
|
|
|
324
343
|
callback: mockServerCallback,
|
|
325
344
|
};
|
|
326
345
|
|
|
327
|
-
const mockGetAbility =
|
|
328
|
-
(
|
|
346
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
347
|
+
mockSelect( {
|
|
329
348
|
getAbility: mockGetAbility,
|
|
330
349
|
} );
|
|
331
350
|
|
|
@@ -336,7 +355,7 @@ describe( 'API functions', () => {
|
|
|
336
355
|
} );
|
|
337
356
|
|
|
338
357
|
it( 'should execute a destructive idempotent server ability', async () => {
|
|
339
|
-
const mockServerCallback =
|
|
358
|
+
const mockServerCallback = vi
|
|
340
359
|
.fn()
|
|
341
360
|
.mockResolvedValue( 'Item deleted successfully.' );
|
|
342
361
|
const mockAbility: Ability = {
|
|
@@ -362,8 +381,8 @@ describe( 'API functions', () => {
|
|
|
362
381
|
callback: mockServerCallback,
|
|
363
382
|
};
|
|
364
383
|
|
|
365
|
-
const mockGetAbility =
|
|
366
|
-
(
|
|
384
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
385
|
+
mockSelect( {
|
|
367
386
|
getAbility: mockGetAbility,
|
|
368
387
|
} );
|
|
369
388
|
|
|
@@ -375,11 +394,11 @@ describe( 'API functions', () => {
|
|
|
375
394
|
} );
|
|
376
395
|
|
|
377
396
|
it( 'should handle errors in client ability execution', async () => {
|
|
378
|
-
const consoleErrorSpy =
|
|
397
|
+
const consoleErrorSpy = vi
|
|
379
398
|
.spyOn( console, 'error' )
|
|
380
|
-
.mockImplementation();
|
|
399
|
+
.mockImplementation( () => {} );
|
|
381
400
|
const executionError = new Error( 'Execution failed' );
|
|
382
|
-
const mockCallback =
|
|
401
|
+
const mockCallback = vi.fn().mockRejectedValue( executionError );
|
|
383
402
|
|
|
384
403
|
const mockAbility: Ability = {
|
|
385
404
|
name: 'test/client-ability',
|
|
@@ -392,8 +411,8 @@ describe( 'API functions', () => {
|
|
|
392
411
|
meta: { annotations: { clientRegistered: true } },
|
|
393
412
|
};
|
|
394
413
|
|
|
395
|
-
const mockGetAbility =
|
|
396
|
-
(
|
|
414
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
415
|
+
mockSelect( {
|
|
397
416
|
getAbility: mockGetAbility,
|
|
398
417
|
} );
|
|
399
418
|
|
|
@@ -410,13 +429,11 @@ describe( 'API functions', () => {
|
|
|
410
429
|
} );
|
|
411
430
|
|
|
412
431
|
it( 'should handle errors in server ability execution', async () => {
|
|
413
|
-
const consoleErrorSpy =
|
|
432
|
+
const consoleErrorSpy = vi
|
|
414
433
|
.spyOn( console, 'error' )
|
|
415
|
-
.mockImplementation();
|
|
434
|
+
.mockImplementation( () => {} );
|
|
416
435
|
const serverError = new Error( 'Server execution failed' );
|
|
417
|
-
const mockServerCallback =
|
|
418
|
-
.fn()
|
|
419
|
-
.mockRejectedValue( serverError );
|
|
436
|
+
const mockServerCallback = vi.fn().mockRejectedValue( serverError );
|
|
420
437
|
|
|
421
438
|
const mockAbility: Ability = {
|
|
422
439
|
name: 'test/server-ability',
|
|
@@ -429,8 +446,8 @@ describe( 'API functions', () => {
|
|
|
429
446
|
meta: { annotations: { serverRegistered: true } },
|
|
430
447
|
};
|
|
431
448
|
|
|
432
|
-
const mockGetAbility =
|
|
433
|
-
(
|
|
449
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
450
|
+
mockSelect( {
|
|
434
451
|
getAbility: mockGetAbility,
|
|
435
452
|
} );
|
|
436
453
|
|
|
@@ -447,7 +464,7 @@ describe( 'API functions', () => {
|
|
|
447
464
|
} );
|
|
448
465
|
|
|
449
466
|
it( 'should execute ability without callback as server ability', async () => {
|
|
450
|
-
const mockServerCallback =
|
|
467
|
+
const mockServerCallback = vi
|
|
451
468
|
.fn()
|
|
452
469
|
.mockResolvedValue( { success: true } );
|
|
453
470
|
const mockAbility: Ability = {
|
|
@@ -462,8 +479,8 @@ describe( 'API functions', () => {
|
|
|
462
479
|
meta: { annotations: { serverRegistered: true } },
|
|
463
480
|
};
|
|
464
481
|
|
|
465
|
-
const mockGetAbility =
|
|
466
|
-
(
|
|
482
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
483
|
+
mockSelect( {
|
|
467
484
|
getAbility: mockGetAbility,
|
|
468
485
|
} );
|
|
469
486
|
|
|
@@ -478,7 +495,7 @@ describe( 'API functions', () => {
|
|
|
478
495
|
} );
|
|
479
496
|
|
|
480
497
|
it( 'should validate output for client abilities', async () => {
|
|
481
|
-
const mockCallback =
|
|
498
|
+
const mockCallback = vi
|
|
482
499
|
.fn()
|
|
483
500
|
.mockResolvedValue( { invalid: 'response' } );
|
|
484
501
|
const mockAbility: Ability = {
|
|
@@ -498,8 +515,8 @@ describe( 'API functions', () => {
|
|
|
498
515
|
meta: { annotations: { clientRegistered: true } },
|
|
499
516
|
};
|
|
500
517
|
|
|
501
|
-
const mockGetAbility =
|
|
502
|
-
(
|
|
518
|
+
const mockGetAbility = vi.fn().mockReturnValue( mockAbility );
|
|
519
|
+
mockSelect( {
|
|
503
520
|
getAbility: mockGetAbility,
|
|
504
521
|
} );
|
|
505
522
|
|
|
@@ -524,10 +541,10 @@ describe( 'API functions', () => {
|
|
|
524
541
|
},
|
|
525
542
|
];
|
|
526
543
|
|
|
527
|
-
const mockGetAbilityCategories =
|
|
544
|
+
const mockGetAbilityCategories = vi
|
|
528
545
|
.fn()
|
|
529
546
|
.mockReturnValue( mockCategories );
|
|
530
|
-
(
|
|
547
|
+
mockSelect( {
|
|
531
548
|
getAbilityCategories: mockGetAbilityCategories,
|
|
532
549
|
} );
|
|
533
550
|
|
|
@@ -539,8 +556,8 @@ describe( 'API functions', () => {
|
|
|
539
556
|
} );
|
|
540
557
|
|
|
541
558
|
it( 'should return empty array when no categories exist', () => {
|
|
542
|
-
const mockGetAbilityCategories =
|
|
543
|
-
(
|
|
559
|
+
const mockGetAbilityCategories = vi.fn().mockReturnValue( [] );
|
|
560
|
+
mockSelect( {
|
|
544
561
|
getAbilityCategories: mockGetAbilityCategories,
|
|
545
562
|
} );
|
|
546
563
|
|
|
@@ -558,10 +575,10 @@ describe( 'API functions', () => {
|
|
|
558
575
|
description: 'Abilities that retrieve data',
|
|
559
576
|
};
|
|
560
577
|
|
|
561
|
-
const mockGetAbilityCategory =
|
|
578
|
+
const mockGetAbilityCategory = vi
|
|
562
579
|
.fn()
|
|
563
580
|
.mockReturnValue( mockCategory );
|
|
564
|
-
(
|
|
581
|
+
mockSelect( {
|
|
565
582
|
getAbilityCategory: mockGetAbilityCategory,
|
|
566
583
|
} );
|
|
567
584
|
|
|
@@ -584,10 +601,10 @@ describe( 'API functions', () => {
|
|
|
584
601
|
},
|
|
585
602
|
};
|
|
586
603
|
|
|
587
|
-
const mockGetAbilityCategory =
|
|
604
|
+
const mockGetAbilityCategory = vi
|
|
588
605
|
.fn()
|
|
589
606
|
.mockReturnValue( mockCategory );
|
|
590
|
-
(
|
|
607
|
+
mockSelect( {
|
|
591
608
|
getAbilityCategory: mockGetAbilityCategory,
|
|
592
609
|
} );
|
|
593
610
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for schema validation utilities.
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
6
|
import { validateValueFromSchema } from '../validation';
|
|
5
7
|
|
|
6
8
|
describe( 'validateValueFromSchema', () => {
|
|
@@ -133,9 +135,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
133
135
|
|
|
134
136
|
describe( 'edge cases', () => {
|
|
135
137
|
it( 'should pass validation when empty schema provided', () => {
|
|
136
|
-
const consoleSpy =
|
|
138
|
+
const consoleSpy = vi
|
|
137
139
|
.spyOn( console, 'warn' )
|
|
138
|
-
.mockImplementation();
|
|
140
|
+
.mockImplementation( () => {} );
|
|
139
141
|
|
|
140
142
|
expect( validateValueFromSchema( 'anything', {} ) ).toBe( true );
|
|
141
143
|
expect( consoleSpy ).toHaveBeenCalledWith(
|
|
@@ -146,9 +148,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
146
148
|
} );
|
|
147
149
|
|
|
148
150
|
it( 'should warn when type is missing but still pass validation', () => {
|
|
149
|
-
const consoleSpy =
|
|
151
|
+
const consoleSpy = vi
|
|
150
152
|
.spyOn( console, 'warn' )
|
|
151
|
-
.mockImplementation();
|
|
153
|
+
.mockImplementation( () => {} );
|
|
152
154
|
const schema = { properties: { name: { type: 'string' } } };
|
|
153
155
|
const result = validateValueFromSchema( { name: 'test' }, schema );
|
|
154
156
|
|
|
@@ -161,9 +163,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
161
163
|
} );
|
|
162
164
|
|
|
163
165
|
it( 'should include param name in warning when provided', () => {
|
|
164
|
-
const consoleSpy =
|
|
166
|
+
const consoleSpy = vi
|
|
165
167
|
.spyOn( console, 'warn' )
|
|
166
|
-
.mockImplementation();
|
|
168
|
+
.mockImplementation( () => {} );
|
|
167
169
|
const schema = { format: 'email' }; // Schema without type
|
|
168
170
|
const result = validateValueFromSchema(
|
|
169
171
|
'test@example.com',
|
|
@@ -449,9 +451,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
449
451
|
|
|
450
452
|
describe( 'schema edge cases and errors', () => {
|
|
451
453
|
it( 'should handle empty schema object as valid but warn about missing type', () => {
|
|
452
|
-
const consoleSpy =
|
|
454
|
+
const consoleSpy = vi
|
|
453
455
|
.spyOn( console, 'warn' )
|
|
454
|
-
.mockImplementation();
|
|
456
|
+
.mockImplementation( () => {} );
|
|
455
457
|
|
|
456
458
|
// Empty object schema triggers warning about missing type
|
|
457
459
|
expect( validateValueFromSchema( 'anything', {} ) ).toBe( true );
|
|
@@ -463,9 +465,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
463
465
|
} );
|
|
464
466
|
|
|
465
467
|
it( 'should warn for invalid schema types but still pass validation', () => {
|
|
466
|
-
const consoleSpy =
|
|
468
|
+
const consoleSpy = vi
|
|
467
469
|
.spyOn( console, 'warn' )
|
|
468
|
-
.mockImplementation();
|
|
470
|
+
.mockImplementation( () => {} );
|
|
469
471
|
|
|
470
472
|
// Testing edge cases where schema is not a valid object
|
|
471
473
|
expect(
|
|
@@ -506,9 +508,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
506
508
|
it( 'should handle schema compilation errors', () => {
|
|
507
509
|
// Pass an invalid schema that will cause compilation error
|
|
508
510
|
const invalidSchema = { type: 'invalid-type' };
|
|
509
|
-
const consoleErrorSpy =
|
|
511
|
+
const consoleErrorSpy = vi
|
|
510
512
|
.spyOn( console, 'error' )
|
|
511
|
-
.mockImplementation();
|
|
513
|
+
.mockImplementation( () => {} );
|
|
512
514
|
|
|
513
515
|
const result = validateValueFromSchema( 'test', invalidSchema );
|
|
514
516
|
|
|
@@ -566,9 +568,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
566
568
|
},
|
|
567
569
|
},
|
|
568
570
|
};
|
|
569
|
-
const consoleErrorSpy =
|
|
571
|
+
const consoleErrorSpy = vi
|
|
570
572
|
.spyOn( console, 'error' )
|
|
571
|
-
.mockImplementation();
|
|
573
|
+
.mockImplementation( () => {} );
|
|
572
574
|
|
|
573
575
|
expect(
|
|
574
576
|
validateValueFromSchema( { name: 'hello' }, schema )
|
|
@@ -587,9 +589,9 @@ describe( 'validateValueFromSchema', () => {
|
|
|
587
589
|
type: 'string',
|
|
588
590
|
sanitize_callback: 'sanitize_text_field',
|
|
589
591
|
};
|
|
590
|
-
const consoleErrorSpy =
|
|
592
|
+
const consoleErrorSpy = vi
|
|
591
593
|
.spyOn( console, 'error' )
|
|
592
|
-
.mockImplementation();
|
|
594
|
+
.mockImplementation( () => {} );
|
|
593
595
|
|
|
594
596
|
expect( validateValueFromSchema( 'hello', schema ) ).toBe(
|
|
595
597
|
'Invalid schema provided for validation.'
|