Skip to content

Commit

Permalink
test against private fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis committed Apr 15, 2024
1 parent c4d4d24 commit 665911e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions integration/test/ParseLiveQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 665911e

Please sign in to comment.