From e7eb8aff2f8de48ba101559c227a097fbf272ec0 Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Sun, 11 Feb 2018 01:10:13 -0700 Subject: [PATCH] Adds some runtime tests for the immutable option --- test/runtime/index.js | 4 +++- .../samples/immutable-mutable/Nested.html | 13 +++++++++++++ .../runtime/samples/immutable-mutable/_config.js | 16 ++++++++++++++++ test/runtime/samples/immutable-mutable/main.html | 13 +++++++++++++ .../runtime/samples/immutable-nested/Nested.html | 12 ++++++++++++ test/runtime/samples/immutable-nested/_config.js | 16 ++++++++++++++++ test/runtime/samples/immutable-nested/main.html | 13 +++++++++++++ test/runtime/samples/immutable-root/_config.js | 15 +++++++++++++++ test/runtime/samples/immutable-root/main.html | 14 ++++++++++++++ 9 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/immutable-mutable/Nested.html create mode 100644 test/runtime/samples/immutable-mutable/_config.js create mode 100644 test/runtime/samples/immutable-mutable/main.html create mode 100644 test/runtime/samples/immutable-nested/Nested.html create mode 100644 test/runtime/samples/immutable-nested/_config.js create mode 100644 test/runtime/samples/immutable-nested/main.html create mode 100644 test/runtime/samples/immutable-root/_config.js create mode 100644 test/runtime/samples/immutable-root/main.html diff --git a/test/runtime/index.js b/test/runtime/index.js index 778f47c0cc..8ec4c5194a 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -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); diff --git a/test/runtime/samples/immutable-mutable/Nested.html b/test/runtime/samples/immutable-mutable/Nested.html new file mode 100644 index 0000000000..02278e385e --- /dev/null +++ b/test/runtime/samples/immutable-mutable/Nested.html @@ -0,0 +1,13 @@ +

Called {{count}} times.

+ + \ No newline at end of file diff --git a/test/runtime/samples/immutable-mutable/_config.js b/test/runtime/samples/immutable-mutable/_config.js new file mode 100644 index 0000000000..5dab0f239b --- /dev/null +++ b/test/runtime/samples/immutable-mutable/_config.js @@ -0,0 +1,16 @@ +export default { + immutable: true, + html: `

Called 0 times.

`, + + 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, `

Called 1 times.

`); + + nested.set({ foo: nested.get('foo') }); + assert.htmlEqual(target.innerHTML, `

Called 2 times.

`); + } +}; diff --git a/test/runtime/samples/immutable-mutable/main.html b/test/runtime/samples/immutable-mutable/main.html new file mode 100644 index 0000000000..4e36143361 --- /dev/null +++ b/test/runtime/samples/immutable-mutable/main.html @@ -0,0 +1,13 @@ +
+ +
+ + diff --git a/test/runtime/samples/immutable-nested/Nested.html b/test/runtime/samples/immutable-nested/Nested.html new file mode 100644 index 0000000000..05eb9f3fdf --- /dev/null +++ b/test/runtime/samples/immutable-nested/Nested.html @@ -0,0 +1,12 @@ +

Called {{count}} times.

+ + \ No newline at end of file diff --git a/test/runtime/samples/immutable-nested/_config.js b/test/runtime/samples/immutable-nested/_config.js new file mode 100644 index 0000000000..541566ce4d --- /dev/null +++ b/test/runtime/samples/immutable-nested/_config.js @@ -0,0 +1,16 @@ +export default { + immutable: true, + html: `

Called 0 times.

`, + + 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, `

Called 1 times.

`); + + nested.set({ foo: nested.get('foo') }); + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + } +}; diff --git a/test/runtime/samples/immutable-nested/main.html b/test/runtime/samples/immutable-nested/main.html new file mode 100644 index 0000000000..4e36143361 --- /dev/null +++ b/test/runtime/samples/immutable-nested/main.html @@ -0,0 +1,13 @@ +
+ +
+ + diff --git a/test/runtime/samples/immutable-root/_config.js b/test/runtime/samples/immutable-root/_config.js new file mode 100644 index 0000000000..a862008d7d --- /dev/null +++ b/test/runtime/samples/immutable-root/_config.js @@ -0,0 +1,15 @@ +export default { + immutable: true, + html: `

Called 0 times.

`, + + test(assert, component, target, window) { + component.observe('foo', foo => { + component.set({ count: component.get('count') + 1 }); + }); + + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + + component.set({ foo: component.get('foo') }); + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + } +}; diff --git a/test/runtime/samples/immutable-root/main.html b/test/runtime/samples/immutable-root/main.html new file mode 100644 index 0000000000..087f561caf --- /dev/null +++ b/test/runtime/samples/immutable-root/main.html @@ -0,0 +1,14 @@ +
+

Called {{count}} times.

+
+ + \ No newline at end of file