This commit is contained in:
znetsixe
2026-03-11 11:13:26 +01:00
parent 33f3c2ef61
commit 6b2a8239f2
16 changed files with 2850 additions and 146 deletions

View File

@@ -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);
});