-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconvert-array-of-objects-to-csv.spec.js
More file actions
92 lines (70 loc) · 3.46 KB
/
Copy pathconvert-array-of-objects-to-csv.spec.js
File metadata and controls
92 lines (70 loc) · 3.46 KB
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
import { convertArrayOfObjectsToCSV } from '../../src/modules/convert-array-of-objects-to-csv';
import {
dataObject,
dataObjectWithNullAndUndefined,
dataObjectWithDoubleQuotesInsideElement,
dataObjectWithFloat,
dataObjectWith0,
} from '../fixtures/data';
import {
optionsHeaderSeparatorSemicolon,
optionsHeaderSeparatorDefault,
optionsNullHeaderSeparatorDefault,
optionsHeaderDefaultSeparatorTab,
optionsDefault,
optionsHeaderZero,
} from '../fixtures/options';
import {
expectedResultObjectNoOptions,
expectedResultObjectHeaderSeparatorSemicolon,
expectedResultObjectOnlyHeader,
expectedResultObjectNoHeader,
expectedResultObjectOnlySeparatorTab,
expectedResultObjectNullAndUndefined,
expectedResultObjectWithDoubleQuotesInsideElement,
expectedResultObjectWithFloats,
expectedResultObjectZero,
} from '../fixtures/expected-results';
test('convertArrayOfObjectsToCSV | array of objects | with default options', () => {
const result = convertArrayOfObjectsToCSV(dataObjectWithDoubleQuotesInsideElement, optionsDefault); // eslint-disable-line
expect(result).toBe(expectedResultObjectWithDoubleQuotesInsideElement);
});
test('convertArrayOfObjectsToCSV | array of objects | with default options and double quotes in element', () => {
const result = convertArrayOfObjectsToCSV(dataObject, optionsDefault);
expect(result).toBe(expectedResultObjectNoOptions);
});
test('convertArrayOfObjectsToCSV | array of objects | options: header + separator semicolon', () => {
const result = convertArrayOfObjectsToCSV(dataObject, optionsHeaderSeparatorSemicolon);
expect(result).toBe(expectedResultObjectHeaderSeparatorSemicolon);
});
test('convertArrayOfObjectsToCSV | array of objects | options: header + default separator', () => {
const result = convertArrayOfObjectsToCSV(dataObject, optionsHeaderSeparatorDefault);
expect(result).toBe(expectedResultObjectOnlyHeader);
});
test('convertArrayOfObjectsToCSV | array of objects | options: header = null + default separator', () => {
const result = convertArrayOfObjectsToCSV(dataObject, optionsNullHeaderSeparatorDefault);
expect(result).toBe(expectedResultObjectNoHeader);
});
test('convertArrayOfObjectsToCSV | array of objects | options: default header + separator tab', () => {
const result = convertArrayOfObjectsToCSV(dataObject, optionsHeaderDefaultSeparatorTab);
expect(result).toBe(expectedResultObjectOnlySeparatorTab);
});
test('convertArrayOfObjectsToCSV | array of objects with values of null and undefined | options: header + default separator', () => {
const result = convertArrayOfObjectsToCSV(
dataObjectWithNullAndUndefined,
optionsHeaderSeparatorDefault,
);
expect(result).toBe(expectedResultObjectNullAndUndefined);
});
test('convertArrayOfObjectsToCSV | array of objects with float | options: default header', () => {
const result = convertArrayOfObjectsToCSV(dataObjectWithFloat, optionsDefault);
expect(result).toBe(expectedResultObjectWithFloats);
});
test('convertArrayOfObjectsToCSV | array of objects with value of zero | options: header with zero and "" + default separator', () => {
const result = convertArrayOfObjectsToCSV(dataObjectWith0, optionsHeaderZero);
expect(result).toBe(expectedResultObjectZero);
});
test('convertArrayOfObjectsToCSV | array of objects with value of zero | options: default header + default separator', () => {
const result = convertArrayOfObjectsToCSV(dataObjectWith0, optionsDefault);
expect(result).toBe(expectedResultObjectZero);
});