From c176506086099803594ae316780ac31f9e39c325 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 May 2018 22:28:06 -0400 Subject: [PATCH] put test alongside other store tests --- .../store-computed-compute-graph/_config.js | 22 ------------------- .../store-computed-compute-graph/main.html | 0 test/store/index.js | 18 +++++++++++++++ 3 files changed, 18 insertions(+), 22 deletions(-) delete mode 100644 test/runtime/samples/store-computed-compute-graph/_config.js delete mode 100644 test/runtime/samples/store-computed-compute-graph/main.html diff --git a/test/runtime/samples/store-computed-compute-graph/_config.js b/test/runtime/samples/store-computed-compute-graph/_config.js deleted file mode 100644 index ba7ac02f8d..0000000000 --- a/test/runtime/samples/store-computed-compute-graph/_config.js +++ /dev/null @@ -1,22 +0,0 @@ -import { Store } from '../../../../store.js'; - -const store = new Store(); - -export default { - store, - - test(assert, component, target) { - store.compute('dep4', ['dep1', 'dep2', 'dep3'], (...args) => ['dep4'].concat(...args)); - store.compute('dep1', ['source'], (...args) => ['dep1'].concat(...args)); - store.compute('dep2', ['dep1'], (...args) => ['dep2'].concat(...args)); - store.compute('dep3', ['dep1', 'dep2'], (...args) => ['dep3'].concat(...args)); - store.set({source: 'source'}); - assert.equal(JSON.stringify(store.get().dep4), JSON.stringify([ - 'dep4', - 'dep1', 'source', - 'dep2', 'dep1', 'source', - 'dep3', 'dep1', 'source', - 'dep2', 'dep1', 'source' - ])); - } -}; diff --git a/test/runtime/samples/store-computed-compute-graph/main.html b/test/runtime/samples/store-computed-compute-graph/main.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/store/index.js b/test/store/index.js index 8bddb046f1..daba075bfb 100644 --- a/test/store/index.js +++ b/test/store/index.js @@ -144,6 +144,24 @@ describe('store', () => { store.compute('b', ['a'], a => a + 1); }, /Cyclical dependency detected/); }); + + it('does not falsely report cycles', () => { + const store = new Store(); + + store.compute('dep4', ['dep1', 'dep2', 'dep3'], (...args) => ['dep4'].concat(...args)); + store.compute('dep1', ['source'], (...args) => ['dep1'].concat(...args)); + store.compute('dep2', ['dep1'], (...args) => ['dep2'].concat(...args)); + store.compute('dep3', ['dep1', 'dep2'], (...args) => ['dep3'].concat(...args)); + store.set({source: 'source'}); + + assert.deepEqual(store.get().dep4, [ + 'dep4', + 'dep1', 'source', + 'dep2', 'dep1', 'source', + 'dep3', 'dep1', 'source', + 'dep2', 'dep1', 'source' + ]); + }); }); describe('immutable', () => {