-
-
Notifications
You must be signed in to change notification settings - Fork 599
Description
New Issue Checklist
- [ x ] I am not disclosing a vulnerability.
- [ x ] I am not just asking a question.
- [ x ] I have searched through existing issues.
- [ x ] I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK.
Issue Description
In a jsdom environment, any test that directly or indirectly imports parse (or parse/node) gets terminated due to an UnhandledPromiseRejection. Mocking with jest.mock doesn't help.
The error message is "ReferenceError: indexedDB is not defined"
Steps to reproduce
Run this test:
/*
* @jest-environment jsdom
*/
import Parse from 'parse'; // or 'parse/node'
jest.mock('parse'); // or don't, it doesn't make a difference
describe('a test', () => {
it("shouldn't break just because we import the parse module", () => {
expect(1).toBe(1);
});
});Actual Outcome
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise which was not handled with .catch().
The promise rejected with the reason "ReferenceError: indexedDB is not defined".] {
code: 'ERR_UNHANDLED_REJECTION'
}
Process finished with exit code 1
Expected Outcome
Test passed (expect(1).toBe(1)).
Notes
Outside of a jsdom environment, this error doesn't happen. (You can verify this by running the same test without the @jest-environment decorator at the top.)
So maybe the parse SDK is checking for window or document, or something else that jsdom provides, and then expecting something else that jsdom doesn't provide?
But the issue also occurs if you import parse/node instead of parse—ie, when the SDK shouldn't be expecting a browser environment.
Environment
(not a server issue, but...)
Server
- Parse Server version: 4.5.0
- Operating system: MacOS 12.4
- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): back4app.com
(not a db issue, but...)
Database
- System (MongoDB or Postgres): MongoDB
- Database version: 3.6
- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): back4app.com
Client
- Parse JS SDK version: 3.4.2
Logs
See Actual Outcome above