Skip to content

Commit d384814

Browse files
eneufeldedgarmueller
authored andcommitted
Add helper method in test for ref parser option
1 parent ba7ea9c commit d384814

File tree

1 file changed

+24
-70
lines changed

1 file changed

+24
-70
lines changed

packages/core/test/reducers/core.test.ts

Lines changed: 24 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ import {
3737

3838
import { createAjv } from '../../src';
3939

40+
const createRefParserOptions = (
41+
encoding = 'testEncoding'
42+
): RefParser.Options => {
43+
const parserOptions: RefParser.ParserOptions & { encoding?: string } = {
44+
encoding
45+
};
46+
const myOptions: RefParser.Options = {
47+
parse: {
48+
text: parserOptions
49+
}
50+
};
51+
return myOptions;
52+
};
53+
4054
test('core reducer should support v7', t => {
4155
const schema: JsonSchema = {
4256
type: 'object',
@@ -140,13 +154,7 @@ test('core reducer - no previous state - init with options object with ref parse
140154
}
141155
}
142156
};
143-
const myOptions: RefParser.Options = {
144-
parse: {
145-
text: {
146-
encoding: 'testEncoding'
147-
}
148-
}
149-
};
157+
const myOptions = createRefParserOptions();
150158
const after = coreReducer(
151159
undefined,
152160
init({}, schema, undefined, {
@@ -170,13 +178,7 @@ test('core reducer - no previous state - init with options object with ajv and r
170178
const myAjv = new AJV({
171179
errorDataPath: 'mypath'
172180
});
173-
const myOptions: RefParser.Options = {
174-
parse: {
175-
text: {
176-
encoding: 'testEncoding'
177-
}
178-
}
179-
};
181+
const myOptions = createRefParserOptions();
180182
const after = coreReducer(
181183
undefined,
182184
init({}, schema, undefined, {
@@ -201,13 +203,7 @@ test('core reducer - previous state - init without options should keep previous
201203
const myAjv = new AJV({
202204
errorDataPath: 'mypath'
203205
});
204-
const myOptions: RefParser.Options = {
205-
parse: {
206-
text: {
207-
encoding: 'testEncoding'
208-
}
209-
}
210-
};
206+
const myOptions = createRefParserOptions();
211207
const after = coreReducer(
212208
{
213209
data: {},
@@ -240,13 +236,7 @@ test('core reducer - previous state - init with ajv options object should overwr
240236
const newAjv = new AJV({
241237
errorDataPath: 'newajv'
242238
});
243-
const myOptions: RefParser.Options = {
244-
parse: {
245-
text: {
246-
encoding: 'testEncoding'
247-
}
248-
}
249-
};
239+
const myOptions = createRefParserOptions();
250240
const after = coreReducer(
251241
{
252242
data: {},
@@ -279,13 +269,7 @@ test('core reducer - previous state - init with options with ajv should overwrit
279269
const newAjv = new AJV({
280270
errorDataPath: 'newajv'
281271
});
282-
const myOptions: RefParser.Options = {
283-
parse: {
284-
text: {
285-
encoding: 'testEncoding'
286-
}
287-
}
288-
};
272+
const myOptions = createRefParserOptions();
289273
const after = coreReducer(
290274
{
291275
data: {},
@@ -317,20 +301,8 @@ test('core reducer - previous state - init with options with ref parser options
317301
const myAjv = new AJV({
318302
errorDataPath: 'mypath'
319303
});
320-
const previousOptions: RefParser.Options = {
321-
parse: {
322-
text: {
323-
encoding: 'testEncoding'
324-
}
325-
}
326-
};
327-
const newOptions: RefParser.Options = {
328-
parse: {
329-
text: {
330-
encoding: 'newEncoding'
331-
}
332-
}
333-
};
304+
const previousOptions = createRefParserOptions();
305+
const newOptions = createRefParserOptions('newEncoding');
334306
const after = coreReducer(
335307
{
336308
data: {},
@@ -365,20 +337,8 @@ test('core reducer - previous state - init with both options should overwrite bo
365337
const newAjv = new AJV({
366338
errorDataPath: 'newajv'
367339
});
368-
const previousOptions: RefParser.Options = {
369-
parse: {
370-
text: {
371-
encoding: 'testEncoding'
372-
}
373-
}
374-
};
375-
const newOptions: RefParser.Options = {
376-
parse: {
377-
text: {
378-
encoding: 'newEncoding'
379-
}
380-
}
381-
};
340+
const previousOptions = createRefParserOptions();
341+
const newOptions = createRefParserOptions('newEncoding');
382342
const after = coreReducer(
383343
{
384344
data: {},
@@ -411,13 +371,7 @@ test('core reducer - previous state - init with empty options should not overwri
411371
const myAjv = new AJV({
412372
errorDataPath: 'mypath'
413373
});
414-
const myOptions: RefParser.Options = {
415-
parse: {
416-
text: {
417-
encoding: 'testEncoding'
418-
}
419-
}
420-
};
374+
const myOptions = createRefParserOptions();
421375
const after = coreReducer(
422376
{
423377
data: {},

0 commit comments

Comments
 (0)