Adds some runtime tests for the immutable option

pull/1164/head
Jacob Wright 7 years ago
parent 046a8000e6
commit cb446bca64

@ -66,6 +66,7 @@ describe("runtime", () => {
compileOptions.hydratable = hydrate;
compileOptions.dev = config.dev;
compileOptions.store = !!config.store;
compileOptions.immutable = config.immutable;
// check that no ES2015+ syntax slipped in
if (!config.allowES2015) {
@ -160,7 +161,8 @@ describe("runtime", () => {
target,
hydrate,
data: config.data,
store: (config.store !== true && config.store)
store: (config.store !== true && config.store),
immutable: config.immutable
}, config.options || {});
const component = new SvelteComponent(options);

@ -0,0 +1,13 @@
<h3>Called {{count}} times.</h3>
<script>
export default {
immutable: false,
data() {
return {
count: 0,
foo: { bar: 'baz' }
};
}
}
</script>

@ -0,0 +1,16 @@
export default {
immutable: true,
html: `<div><h3>Called 0 times.</h3></div>`,
test(assert, component, target, window) {
var nested = component.refs.nested;
nested.observe('foo', foo => {
nested.set({ count: nested.get('count') + 1 });
});
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
nested.set({ foo: nested.get('foo') });
assert.htmlEqual(target.innerHTML, `<div><h3>Called 2 times.</h3></div>`);
}
};

@ -0,0 +1,13 @@
<div>
<Nested ref:nested />
</div>
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>

@ -0,0 +1,12 @@
<h3>Called {{count}} times.</h3>
<script>
export default {
data() {
return {
count: 0,
foo: { bar: 'baz' }
};
}
}
</script>

@ -0,0 +1,16 @@
export default {
immutable: true,
html: `<div><h3>Called 0 times.</h3></div>`,
test(assert, component, target, window) {
var nested = component.refs.nested;
nested.observe('foo', foo => {
nested.set({ count: nested.get('count') + 1 });
});
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
nested.set({ foo: nested.get('foo') });
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
}
};

@ -0,0 +1,13 @@
<div>
<Nested ref:nested />
</div>
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>

@ -0,0 +1,15 @@
export default {
immutable: true,
html: `<div><h3>Called 0 times.</h3></div>`,
test(assert, component, target, window) {
component.observe('foo', foo => {
component.set({ count: component.get('count') + 1 });
});
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
component.set({ foo: component.get('foo') });
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
}
};

@ -0,0 +1,14 @@
<div>
<h3>Called {{count}} times.</h3>
</div>
<script>
export default {
data() {
return {
count: 0,
foo: { bar: 'baz' }
};
}
}
</script>
Loading…
Cancel
Save