From 665911e57a88b323748ab3df33363160f66f7763 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Mon, 15 Apr 2024 09:29:21 -0500 Subject: [PATCH] test against private fields --- integration/test/ParseLiveQueryTest.js | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index c33f21a00..06a2c89d9 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -4,6 +4,7 @@ const assert = require('assert'); const Parse = require('../../node'); const sleep = require('./sleep'); const { resolvingPromise } = require('../../lib/node/promiseUtils'); +const { EventEmitter } = require('events'); describe('Parse LiveQuery', () => { beforeEach(() => { @@ -367,4 +368,41 @@ describe('Parse LiveQuery', () => { client.state = 'closed'; await client.close(); }); + + it('can subscribe to query with EventEmitter private fields', async () => { + class CustomEmitter { + #privateEmitter; + + constructor() { + this.#privateEmitter = new EventEmitter(); + } + on(event, listener) { + this.#privateEmitter.on(event, listener); + } + emit(event, ...args) { + this.#privateEmitter.emit(event, ...args); + } + } + + const EV = Parse.CoreManager.getEventEmitter(); + + Parse.CoreManager.setEventEmitter(CustomEmitter); + const object = new TestObject(); + await object.save(); + const installationId = await Parse.CoreManager.getInstallationController().currentInstallationId(); + + const query = new Parse.Query(TestObject); + query.equalTo('objectId', object.id); + const subscription = await query.subscribe(); + const promise = resolvingPromise(); + subscription.on('update', (object, original, response) => { + assert.equal(object.get('foo'), 'bar'); + assert.equal(response.installationId, installationId); + promise.resolve(); + }); + object.set({ foo: 'bar' }); + await object.save(); + await promise; + Parse.CoreManager.setEventEmitter(EV); + }); });