updates
This commit is contained in:
@@ -25,3 +25,29 @@ test('registerChild listens to measurement events and stores measured pressure',
|
||||
assert.equal(typeof stored, 'number');
|
||||
assert.equal(Math.round(stored), 123);
|
||||
});
|
||||
|
||||
test('registerChild deduplicates listeners on re-registration', async () => {
|
||||
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
||||
const child = makeChildMeasurement({ id: 'pt-dup', positionVsParent: 'downstream', type: 'pressure', unit: 'mbar' });
|
||||
const eventName = 'pressure.measured.downstream';
|
||||
|
||||
let handlerCalls = 0;
|
||||
const originalUpdatePressure = machine.updateMeasuredPressure.bind(machine);
|
||||
machine.updateMeasuredPressure = (...args) => {
|
||||
handlerCalls += 1;
|
||||
return originalUpdatePressure(...args);
|
||||
};
|
||||
|
||||
machine.registerChild(child, 'measurement');
|
||||
machine.registerChild(child, 'measurement');
|
||||
|
||||
assert.equal(child.measurements.emitter.listenerCount(eventName), 1);
|
||||
|
||||
child.measurements
|
||||
.type('pressure')
|
||||
.variant('measured')
|
||||
.position('downstream')
|
||||
.value(321, Date.now(), 'mbar');
|
||||
|
||||
assert.equal(handlerCalls, 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user