test(sim): update PWM-callback assertions for the new timeMs arg

The sample-accurate scheduling (06526c7) added an optional 3rd `timeMs`
argument to PwmCallback / updatePwm, which broke 9 existing strict
toHaveBeenCalledWith(pin, duty) assertions (PinManager, AVRSimulator,
mega-emulation, attiny85). Match the real signature: PinManager drives
updatePwm directly with no timeMs (assert `undefined`); the AVR OCR-poll path
computes timeMs = cpu.cycles / 16000 (assert `expect.anything()`).

Leaves one pre-existing red — component-to-spice "custom-chip missing fixture"
— which fails on master too and is unrelated to this PR.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ciegovolador 2026-06-11 03:14:32 -03:00
parent 6a1f79e331
commit e6ba5ed9c7
4 changed files with 9 additions and 9 deletions

View File

@ -168,7 +168,7 @@ describe('AVRSimulator — PWM OCR monitoring', () => {
sim.start();
sim.stop();
expect(pwmCb).toHaveBeenCalledWith(9, 128 / 255);
expect(pwmCb).toHaveBeenCalledWith(9, 128 / 255, expect.anything()); // 3rd arg = sim timeMs
});
it('PWM covers all six Arduino PWM pins', () => {
@ -202,7 +202,7 @@ describe('AVRSimulator — PWM OCR monitoring', () => {
PWM_MAP.forEach(({ pin }, i) => {
const expected = ((i + 1) * 25) / 255;
expect(cbs[pin]).toHaveBeenCalledWith(pin, expected);
expect(cbs[pin]).toHaveBeenCalledWith(pin, expected, expect.anything()); // 3rd arg = sim timeMs
});
});
});

View File

@ -124,7 +124,7 @@ describe('PinManager — PWM duty cycle', () => {
const cb = vi.fn();
pm.onPwmChange(9, cb);
pm.updatePwm(9, 0.5);
expect(cb).toHaveBeenCalledWith(9, 0.5);
expect(cb).toHaveBeenCalledWith(9, 0.5, undefined); // 3rd arg = optional timeMs (not passed here)
});
it('stores the latest PWM value', () => {
@ -150,7 +150,7 @@ describe('PinManager — PWM duty cycle', () => {
pwmPins.forEach((pin, i) => {
const dc = (i + 1) / 6;
pm.updatePwm(pin, dc);
expect(callbacks[i]).toHaveBeenCalledWith(pin, dc);
expect(callbacks[i]).toHaveBeenCalledWith(pin, dc, undefined); // optional timeMs not passed
});
});
});

View File

@ -283,7 +283,7 @@ describe('ATtiny85 — PWM monitoring', () => {
sim.start();
sim.stop();
expect(pwmCb).toHaveBeenCalledWith(1, 128 / 255);
expect(pwmCb).toHaveBeenCalledWith(1, 128 / 255, expect.anything()); // 3rd arg = sim timeMs
});
it('PinManager receives PWM update on pin 0 when OCR0A (0x56) is written', () => {
@ -300,7 +300,7 @@ describe('ATtiny85 — PWM monitoring', () => {
sim.start();
sim.stop();
expect(pwmCb).toHaveBeenCalledWith(0, 64 / 255);
expect(pwmCb).toHaveBeenCalledWith(0, 64 / 255, expect.anything()); // 3rd arg = sim timeMs
});
it('ATtiny85 PWM covers 4 pins (OCR0A/OCR0B/OCR1A/OCR1B)', () => {

View File

@ -301,7 +301,7 @@ describe('AVRSimulator Mega — PWM OCR mapping differs from Uno', () => {
// Call pollPwmRegisters directly — avoids RAF dependency in unit tests
(sim as any).pollPwmRegisters();
expect(cb).toHaveBeenCalledWith(13, 128 / 255);
expect(cb).toHaveBeenCalledWith(13, 128 / 255, expect.anything()); // 3rd arg = sim timeMs
sim.stop();
});
@ -318,7 +318,7 @@ describe('AVRSimulator Mega — PWM OCR mapping differs from Uno', () => {
(sim as any).pollPwmRegisters();
expect(cb).toHaveBeenCalledWith(5, 200 / 255);
expect(cb).toHaveBeenCalledWith(5, 200 / 255, expect.anything()); // 3rd arg = sim timeMs
sim.stop();
});
@ -335,7 +335,7 @@ describe('AVRSimulator Mega — PWM OCR mapping differs from Uno', () => {
(sim as any).pollPwmRegisters();
expect(cb).toHaveBeenCalledWith(6, 100 / 255);
expect(cb).toHaveBeenCalledWith(6, 100 / 255, expect.anything()); // 3rd arg = sim timeMs
sim.stop();
});
});