diff --git a/src/ParseObject.ts b/src/ParseObject.ts index 9ecb3292e..59a486618 100644 --- a/src/ParseObject.ts +++ b/src/ParseObject.ts @@ -514,6 +514,9 @@ class ParseObject { static _getRequestOptions(options: RequestOptions & FullOptions & { json?: boolean } = {}) { const requestOptions: RequestOptions & FullOptions & { json?: boolean } = {}; + if (Object.prototype.toString.call(options) !== '[object Object]') { + throw new Error('request options must be of type Object'); + } const { hasOwn } = Object; if (hasOwn(options, 'useMasterKey')) { requestOptions.useMasterKey = !!options.useMasterKey; diff --git a/src/__tests__/Cloud-test.js b/src/__tests__/Cloud-test.js index 6ed1e84e1..dba85b255 100644 --- a/src/__tests__/Cloud-test.js +++ b/src/__tests__/Cloud-test.js @@ -356,4 +356,30 @@ describe('CloudController', () => { }); expect(options.useMasterKey).toBe(false); }); + + it('run passes with empty options', () => { + const values = [undefined, {}]; + + const mockRun = jest.fn(); + mockRun.mockReturnValue(Promise.resolve({ result: {} })); + + CoreManager.setCloudController({ + run: mockRun, + getJobsData: jest.fn(), + startJob: jest.fn(), + }); + + for (const value of values) { + mockRun.mockClear(); + expect(() => Cloud.run('myfunction', {}, value)).not.toThrow(); + expect(mockRun).toHaveBeenLastCalledWith('myfunction', {}, {}); + } + }); + + it('run throws with invalid options', () => { + const values = [null, []]; + for (const value of values) { + expect(() => Cloud.run('myfunction', {}, value)).toThrow(); + } + }); });