forked from parse-community/Parse-SDK-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequals-test.js
123 lines (104 loc) · 3.9 KB
/
equals-test.js
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
117
118
119
120
121
122
123
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
jest.autoMockOff();
var equals = require('../equals');
var ParseACL = require('../ParseACL');
var ParseFile = require('../ParseFile');
var ParseGeoPoint = require('../ParseGeoPoint');
var ParseObject = require('../ParseObject');
describe('equals', () => {
it('tests equality of primitives', () => {
expect(equals(1, 'string')).toBe(false);
expect(equals(1, true)).toBe(false);
expect(equals(1, undefined)).toBe(false);
expect(equals(1, null)).toBe(false);
expect(equals(1, {})).toBe(false);
expect(equals(1, 4)).toBe(false);
expect(equals(1, 1)).toBe(true);
expect(equals(null, 'string')).toBe(false);
expect(equals(true, 'string')).toBe(false);
expect(equals(undefined, 'string')).toBe(false);
expect(equals(true, 'string')).toBe(false);
expect(equals({}, 'string')).toBe(false);
expect(equals('abc', 'def')).toBe(false);
expect(equals('abc', 'abc')).toBe(true);
expect(equals(false, false)).toBe(true);
expect(equals(true, true)).toBe(true);
expect(equals(true, false)).toBe(false);
expect(equals(null, null)).toBe(true);
expect(equals(undefined, undefined)).toBe(true);
expect(equals(null, undefined)).toBe(false);
});
it('tests equality of objects and arrays', () => {
var a = {};
expect(equals(a, a)).toBe(true);
expect(equals({}, {})).toBe(true);
expect(equals({ a: 1 }, { a: 1 })).toBe(true);
expect(equals({ a: 1, b: 2 }, { b: 2, a: 1 })).toBe(true);
expect(equals({ a: 1, b: 2 }, { b: 2 })).toBe(false);
expect(equals({ a: {} }, { a: {} })).toBe(true);
expect(equals([], [])).toBe(true);
expect(equals([1, 2, 3], [1, 2, 3])).toBe(true);
expect(equals([1, 2, 3], [3, 2, 1])).toBe(false);
expect(equals([1, 2, 3], [1, 2])).toBe(false);
expect(equals([{ c: 3 }, 2, 1], [{ c: 3 }, 2, 1])).toBe(true);
});
it('tests equality of ACLs', () => {
// Defer to ParseACL tests for the majority of testing
var a = new ParseACL();
var b = new ParseACL();
expect(equals(a, a)).toBe(true);
expect(equals(a, b)).toBe(true);
expect(equals(b, a)).toBe(true);
a.setPublicReadAccess(true);
expect(equals(a, a)).toBe(true);
expect(equals(a, b)).toBe(false);
expect(equals(b, a)).toBe(false);
});
it('tests equality of GeoPoints', () => {
// Defer to ParseGeoPoint tests for the majority of testing
var a = new ParseGeoPoint(40, 40);
expect(equals(a, a)).toBe(true);
var b = new ParseGeoPoint(40, 40);
expect(equals(a, b)).toBe(true);
expect(equals(b, a)).toBe(true);
b = new ParseGeoPoint(50, 40);
expect(equals(a, b)).toBe(false);
expect(equals(b, a)).toBe(false);
});
it('tests equality of Files', () => {
// Defer to ParseFile tests for the majority of testing
var a = new ParseFile('parse.txt', [61, 170, 236, 120]);
var b = new ParseFile('parse.txt', [61, 170, 236, 120]);
expect(equals(a, a)).toBe(true);
// unsaved files are never equal
expect(equals(a, b)).toBe(false);
a = ParseFile.fromJSON({
__type: 'File',
name: 'parse.txt',
url: 'http://files.parsetfss.com/a/parse.txt'
});
b = ParseFile.fromJSON({
__type: 'File',
name: 'parse.txt',
url: 'http://files.parsetfss.com/a/parse.txt'
});
expect(equals(a, b)).toBe(true);
});
it('tests equality of ParseObjects', () => {
// Defer to ParseObject tests for the majority of testing
var a = new ParseObject('Item');
var b = new ParseObject('Item');
expect(equals(a, a)).toBe(true);
expect(equals(a, b)).toBe(false);
a.id = 'myobj';
b.id = 'myobj';
expect(equals(a, b)).toBe(true);
});
});