attributesComparator-test.js
3.67 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* eslint-env mocha */
import expect from 'expect';
import attributesComparator from '../../../src/util/attributesComparator';
import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
import JSXElementMock from '../../../__mocks__/JSXElementMock';
describe('attributesComparator', () => {
describe('base attributes', () => {
let baseAttributes;
let attributes;
describe('are undefined', () => {
describe('and attributes are undefined', () => {
it('should return true', () => {
expect(attributesComparator()).toBe(true);
});
});
});
describe('are empty', () => {
beforeEach(() => {
baseAttributes = [];
});
describe('and attributes', () => {
describe('are empty', () => {
attributes = [];
it('should return true', () => {
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
describe('have values', () => {
attributes = [
JSXAttributeMock('foo', 0),
JSXAttributeMock('bar', 'baz'),
];
it('should return true', () => {
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
});
});
describe('have values', () => {
beforeEach(() => {
baseAttributes = [
{
name: 'biz',
value: 1,
}, {
name: 'fizz',
value: 'pop',
}, {
name: 'fuzz',
value: 'lolz',
},
];
});
describe('and attributes', () => {
describe('are empty', () => {
attributes = [];
it('should return false', () => {
expect(attributesComparator(baseAttributes, attributes))
.toBe(false);
});
});
describe('have values', () => {
describe('and the values are the different', () => {
it('should return false', () => {
attributes = [
JSXElementMock(),
JSXAttributeMock('biz', 2),
JSXAttributeMock('ziff', 'opo'),
JSXAttributeMock('far', 'lolz'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(false);
});
});
describe('and the values are a subset', () => {
it('should return true', () => {
attributes = [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('goo', 'gazz'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(false);
});
});
describe('and the values are the same', () => {
it('should return true', () => {
attributes = [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
describe('and the values are a superset', () => {
it('should return true', () => {
attributes = [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
JSXAttributeMock('dar', 'tee'),
];
expect(attributesComparator(baseAttributes, attributes))
.toBe(true);
});
});
});
});
});
});
});