Skip to content

Commit fa85d35

Browse files
authored
test: Refactor tests to bump jest and jsdom to 29.4.1 (#1733)
1 parent a67254f commit fa85d35

14 files changed

+4893
-5328
lines changed

package-lock.json

Lines changed: 4709 additions & 5104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@semantic-release/npm": "9.0.2",
5555
"@semantic-release/release-notes-generator": "10.0.3",
5656
"babel-eslint": "10.1.0",
57-
"babel-jest": "24.9.0",
57+
"babel-jest": "29.4.1",
5858
"babel-plugin-inline-package-json": "2.0.0",
5959
"babel-plugin-minify-dead-code-elimination": "0.5.2",
6060
"babel-plugin-transform-inline-environment-variables": "0.4.3",
@@ -77,7 +77,8 @@
7777
"jasmine": "3.5.0",
7878
"jasmine-reporters": "2.5.2",
7979
"jasmine-spec-reporter": "7.0.0",
80-
"jest": "24.9.0",
80+
"jest": "29.4.1",
81+
"jest-environment-jsdom": "29.4.1",
8182
"jsdoc": "3.6.3",
8283
"jsdoc-babel": "0.5.0",
8384
"lint-staged": "10.5.3",
@@ -150,8 +151,6 @@
150151
"/node_modules/",
151152
"package.json"
152153
],
153-
"setupFilesAfterEnv": [
154-
"./setup-jest.js"
155-
]
154+
"testEnvironment": "jsdom"
156155
}
157156
}

setup-jest.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/__tests__/EventuallyQueue-test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@ const ParseObject = require('../ParseObject');
5151
const RESTController = require('../RESTController');
5252
const Storage = require('../Storage');
5353
const mockXHR = require('./test_helpers/mockXHR');
54+
const flushPromises = require('./test_helpers/flushPromises');
5455

5556
CoreManager.setInstallationController({
5657
currentInstallationId() {
5758
return Promise.resolve('iid');
5859
},
5960
});
6061

61-
function flushPromises() {
62-
return new Promise(resolve => setImmediate(resolve));
63-
}
64-
6562
describe('EventuallyQueue', () => {
6663
beforeEach(async () => {
6764
jest.clearAllMocks();

src/__tests__/Hooks-test.js

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -129,117 +129,84 @@ describe('Hooks', () => {
129129
]);
130130
});
131131

132-
it('shoud throw invalid create', async done => {
132+
it('shoud throw invalid create', async () => {
133+
expect.assertions(10);
133134
const p1 = Hooks.create({ functionName: 'myFunction' })
134-
.then(() => {
135-
done.fail('should not succeed');
136-
})
137135
.catch(err => {
138136
expect(err.code).toBe(143);
139137
expect(err.error).toBe('invalid hook declaration');
140138
});
141139

142140
const p2 = Hooks.create({ url: 'http://dummy.com' })
143-
.then(() => {
144-
done.fail('should not succeed');
145-
})
146141
.catch(err => {
147142
expect(err.code).toBe(143);
148143
expect(err.error).toBe('invalid hook declaration');
149144
});
150145

151146
const p3 = Hooks.create({ className: 'MyClass' })
152-
.then(() => {
153-
done.fail('should not succeed');
154-
})
155147
.catch(err => {
156148
expect(err.code).toBe(143);
157149
expect(err.error).toBe('invalid hook declaration');
158150
});
159151

160152
const p4 = Hooks.create({ className: 'MyClass', url: 'http://dummy.com' })
161-
.then(() => {
162-
done.fail('should not succeed');
163-
})
164153
.catch(err => {
165154
expect(err.code).toBe(143);
166155
expect(err.error).toBe('invalid hook declaration');
167156
});
168157

169158
const p5 = Hooks.create({ className: 'MyClass', triggerName: 'beforeSave' })
170-
.then(() => {
171-
done.fail('should not succeed');
172-
})
173159
.catch(err => {
174160
expect(err.code).toBe(143);
175161
expect(err.error).toBe('invalid hook declaration');
176162
});
177163

178164
await Promise.all([p1, p2, p3, p4, p5]);
179-
done();
180165
});
181166

182-
it('shoud throw invalid update', async done => {
167+
it('shoud throw invalid update', async () => {
168+
expect.assertions(6);
183169
const p1 = Hooks.update({ functionssName: 'myFunction' })
184-
.then(() => {
185-
done.fail('should not succeed');
186-
})
187170
.catch(err => {
188171
expect(err.code).toBe(143);
189172
expect(err.error).toBe('invalid hook declaration');
190173
});
191174

192175
const p2 = Hooks.update({ className: 'MyClass' })
193-
.then(() => {
194-
done.fail('should not succeed');
195-
})
196176
.catch(err => {
197177
expect(err.code).toBe(143);
198178
expect(err.error).toBe('invalid hook declaration');
199179
});
200180

201181
const p3 = Hooks.update({ className: 'MyClass', url: 'http://dummy.com' })
202-
.then(() => {
203-
done.fail('should not succeed');
204-
})
205182
.catch(err => {
206183
expect(err.code).toBe(143);
207184
expect(err.error).toBe('invalid hook declaration');
208185
});
209186
await Promise.all([p1, p2, p3]);
210-
done();
211187
});
212188

213-
it('shoud throw invalid remove', async done => {
189+
it('shoud throw invalid remove', async () => {
190+
expect.assertions(6);
214191
const p1 = Hooks.remove({ functionssName: 'myFunction' })
215-
.then(() => {
216-
done.fail('should not succeed');
217-
})
218192
.catch(err => {
219193
expect(err.code).toBe(143);
220194
expect(err.error).toBe('invalid hook declaration');
221195
});
222196

223197
const p2 = Hooks.remove({ className: 'MyClass' })
224-
.then(() => {
225-
done.fail('should not succeed');
226-
})
227198
.catch(err => {
228199
expect(err.code).toBe(143);
229200
expect(err.error).toBe('invalid hook declaration');
230201
});
231202

232203
const p3 = Hooks.remove({ className: 'MyClass', url: 'http://dummy.com' })
233-
.then(() => {
234-
done.fail('should not succeed');
235-
})
236204
.catch(err => {
237205
expect(err.code).toBe(143);
238206
expect(err.error).toBe('invalid hook declaration');
239207
});
240208

241209
await Promise.all([p1, p2, p3]);
242-
done();
243210
});
244211

245212
it('should sendRequest', async () => {

src/__tests__/Parse-test.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ jest.setMock('../EventuallyQueue', { poll: jest.fn() });
1010
global.indexedDB = require('./test_helpers/mockIndexedDB');
1111
const CoreManager = require('../CoreManager');
1212
const EventuallyQueue = require('../EventuallyQueue');
13+
const Parse = require('../Parse');
1314

1415
describe('Parse module', () => {
15-
let Parse;
16-
beforeEach(() => {
17-
jest.isolateModules(() => {
18-
Parse = require('../Parse');
19-
});
20-
});
21-
2216
it('can be initialized with keys', () => {
2317
Parse.initialize('A', 'B');
2418
expect(CoreManager.get('APPLICATION_ID')).toBe('A');
@@ -239,13 +233,15 @@ describe('Parse module', () => {
239233
});
240234

241235
it('can get IndexedDB storage', () => {
242-
expect(Parse.IndexedDB).toBeUndefined();
243-
process.env.PARSE_BUILD = 'browser';
244-
const ParseInstance = require('../Parse');
245-
expect(ParseInstance.IndexedDB).toBeDefined();
246-
CoreManager.setStorageController(ParseInstance.IndexedDB);
247-
const currentStorage = CoreManager.getStorageController();
248-
expect(currentStorage).toEqual(ParseInstance.IndexedDB);
249-
process.env.PARSE_BUILD = 'node';
236+
jest.isolateModules(() => {
237+
expect(Parse.IndexedDB).toBeUndefined();
238+
process.env.PARSE_BUILD = 'browser';
239+
const ParseInstance = require('../Parse');
240+
expect(ParseInstance.IndexedDB).toBeDefined();
241+
CoreManager.setStorageController(ParseInstance.IndexedDB);
242+
const currentStorage = CoreManager.getStorageController();
243+
expect(currentStorage).toEqual(ParseInstance.IndexedDB);
244+
process.env.PARSE_BUILD = 'node';
245+
});
250246
});
251247
});

src/__tests__/ParseFile-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,13 @@ describe('FileController', () => {
858858
expect(request).toHaveBeenCalled();
859859
});
860860

861-
it('should throw error if file deleted without name', async done => {
861+
it('should throw error if file deleted without name', async () => {
862+
expect.assertions(1);
862863
const file = new ParseFile('', [1, 2, 3]);
863864
try {
864865
await file.destroy();
865866
} catch (e) {
866867
expect(e.code).toBe(ParseError.FILE_DELETE_UNNAMED_ERROR);
867-
done();
868868
}
869869
});
870870

0 commit comments

Comments
 (0)