@@ -275,4 +275,54 @@ describe("nested derived", () => {
275275 expectSpy ( spyDerived1 , 2 , { result : 3 } ) ;
276276 expectSpy ( spyDerived2 , 2 , { result : 0 } ) ;
277277 } ) ;
278+ test ( "find a better name" , async ( ) => {
279+ /**
280+ * +-------+
281+ * | s1 |
282+ * +-------+
283+ * v
284+ * +-------+
285+ * | d1 |
286+ * +-------+
287+ * v v
288+ * +-------+ +-------+
289+ * | d2 | | d3 |
290+ * +-------+ +-------+
291+ * | v v
292+ * | +-------+
293+ * | | d4 |
294+ * | +-------+
295+ * | |
296+ * v v
297+ * +-------+
298+ * | e1 |
299+ * +-------+
300+ *
301+ * change s1
302+ * -> d1, d2, d3, d4, e1 should recomputes
303+ */
304+ const state = reactive ( { a : 1 } ) ;
305+ const spyDerived1 = jest . fn ( ( ) => state . a ) ;
306+ const d1 = derived ( spyDerived1 ) ;
307+ const spyDerived2 = jest . fn ( ( ) => d1 ( ) + 1 ) ; // 1 + 1 = 2
308+ const d2 = derived ( spyDerived2 ) ;
309+ const spyDerived3 = jest . fn ( ( ) => d1 ( ) + 2 ) ; // 1 + 2 = 3
310+ const d3 = derived ( spyDerived3 ) ;
311+ const spyDerived4 = jest . fn ( ( ) => d2 ( ) + d3 ( ) ) ; // 2 + 3 = 5
312+ const d4 = derived ( spyDerived4 ) ;
313+ const spyEffect = jest . fn ( ( ) => d4 ( ) ) ;
314+ effect ( spyEffect ) ;
315+ expectSpy ( spyEffect , 1 ) ;
316+ expectSpy ( spyDerived1 , 1 , { result : 1 } ) ;
317+ expectSpy ( spyDerived2 , 1 , { result : 2 } ) ;
318+ expectSpy ( spyDerived3 , 1 , { result : 3 } ) ;
319+ expectSpy ( spyDerived4 , 1 , { result : 5 } ) ;
320+ state . a = 2 ;
321+ await waitScheduler ( ) ;
322+ expectSpy ( spyEffect , 2 ) ;
323+ expectSpy ( spyDerived1 , 2 , { result : 2 } ) ;
324+ expectSpy ( spyDerived2 , 2 , { result : 3 } ) ;
325+ expectSpy ( spyDerived3 , 2 , { result : 4 } ) ;
326+ expectSpy ( spyDerived4 , 2 , { result : 7 } ) ;
327+ } ) ;
278328} ) ;
0 commit comments