Joe Lin uses a length converter in Preventing Feedback Loops in a Two-Way Vue Unit Converter to show what can go wrong when either field in a Vue form can drive the calculation. The component uses meters as the shared intermediate unit. The interaction hinges on which field supplies the input for each operation.
Choose the source for each edit
A numeric edit makes the edited field the source and recalculates its counterpart. Lin's converter rounds the calculated value to six decimal places. A test that only checks the displayed conversion can miss a second write back to the source field. If the second watcher converts the rounded value again, the original measurement can change even when the watchers eventually settle.
The component holds a boolean guard while assigning the calculated result. Because the watchers use synchronous flushing, the callback triggered by that assignment sees the guard and returns before doing a reverse conversion. Vue's documentation confirms that synchronous watchers run without batching. If the callbacks are queued instead, the write can schedule a callback that runs after the guard has been cleared. Vue watcher documentation
Test unit changes and swaps separately
Changing a unit dropdown always uses the left field as the source in Lin's example. A useful test starts with a numeric edit on the right and then changes the right unit. The left measurement should stay fixed while the right number is recalculated in the newly selected unit. That sequence distinguishes the dropdown rule from the rule for editing a number.
A swap has a different expected result. Both units and both displayed numbers exchange places, with synchronization suppressed while the component assigns the individual values. The guard applies to the converter's own synchronization logic. Tests can check the complete pair after one swap and check that a second swap restores the original display. Which field should stay fixed when a unit changes in a converter you use?