You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/observe-prevents-loop/_config.js

30 lines
494 B

export default {
data: {
thing: { a: 1 }
},
test(assert, component) {
const thing = component.get().thing;
component.on('state', ({ changed, current }) => {
if (changed.thing) {
const { thing } = current;
thing.b = thing.a * 2;
component.set({ thing }); // triggers infinite loop, unless event handler breaks it
}
});
assert.deepEqual(thing, {
a: 1
});
thing.a = 3;
component.set({ thing });
assert.deepEqual(thing, {
a: 3,
b: 6
});
}
};