diff --git a/src/Cloud.ts b/src/Cloud.ts index c8fd781ad..b9b785708 100644 --- a/src/Cloud.ts +++ b/src/Cloud.ts @@ -46,6 +46,7 @@ export function run< T extends (param: { [P in keyof Parameters[0]]: Parameters[0][P] }) => any, >(name: string, data: Parameters[0], options?: RequestOptions): Promise>; export function run(name: string, data?: any, options?: RequestOptions): Promise { + options = options || {}; if (typeof name !== 'string' || name.length === 0) { throw new TypeError('Cloud function name must be a string.'); } diff --git a/src/__tests__/Cloud-test.js b/src/__tests__/Cloud-test.js index dba85b255..8ad96bcb4 100644 --- a/src/__tests__/Cloud-test.js +++ b/src/__tests__/Cloud-test.js @@ -357,8 +357,8 @@ describe('CloudController', () => { expect(options.useMasterKey).toBe(false); }); - it('run passes with empty options', () => { - const values = [undefined, {}]; + it('run passes with undefined, null or empty options', () => { + const values = [undefined, null, {}]; const mockRun = jest.fn(); mockRun.mockReturnValue(Promise.resolve({ result: {} })); @@ -377,7 +377,7 @@ describe('CloudController', () => { }); it('run throws with invalid options', () => { - const values = [null, []]; + const values = [[]]; for (const value of values) { expect(() => Cloud.run('myfunction', {}, value)).toThrow(); }