forked from parse-community/Parse-SDK-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrayContainsObject-test.js
40 lines (37 loc) · 1.21 KB
/
arrayContainsObject-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
jest.dontMock('../arrayContainsObject');
let localCount = 0;
const mockObject = function (className, id) {
this.className = className;
this.id = id;
if (!id) {
this._localId = 'local' + localCount++;
}
};
mockObject.prototype._getId = function () {
return this.id || this._localId;
};
jest.setMock('../ParseObject', {
__esModule: true,
default: mockObject,
});
const arrayContainsObject = require('../arrayContainsObject').default;
const ParseObject = require('../ParseObject').default;
const CoreManager = require('../CoreManager').default;
jest
.spyOn(CoreManager, 'getParseObject')
.mockImplementation(() => require('../ParseObject').default);
describe('arrayContainsObject', () => {
it('detects objects by their id', () => {
const o = new ParseObject('Item');
expect(arrayContainsObject([], o)).toBe(false);
expect(arrayContainsObject([1, 'string'], o)).toBe(false);
expect(arrayContainsObject([o], o)).toBe(true);
expect(arrayContainsObject([new ParseObject('Item')], new ParseObject('Item'))).toBe(false);
expect(
arrayContainsObject(
[new ParseObject('Item', 'a'), new ParseObject('Item', 'b')],
new ParseObject('Item', 'a')
)
).toBe(true);
});
});