@@ -41,7 +41,7 @@ describe('writable', () => {
4141
4242 const store = writable ( 0 , ( ) => {
4343 called += 1 ;
44- return ( ) => ( called -= 1 ) ;
44+ return ( ) => { called -= 1 } ;
4545 } ) ;
4646
4747 const unsubscribe1 = store . subscribe ( ( ) => { } ) ;
@@ -81,10 +81,10 @@ describe('writable', () => {
8181 let count1 = 0 ;
8282 let count2 = 0 ;
8383
84- store . subscribe ( ( ) => ( count1 += 1 ) ) ( ) ;
84+ store . subscribe ( ( ) => { count1 += 1 } ) ( ) ;
8585 assert . equal ( count1 , 1 ) ;
8686
87- const unsubscribe = store . subscribe ( ( ) => ( count2 += 1 ) ) ;
87+ const unsubscribe = store . subscribe ( ( ) => { count2 += 1 } ) ;
8888 assert . equal ( count2 , 1 ) ;
8989
9090 unsubscribe ( ) ;
@@ -270,7 +270,44 @@ describe('derived', () => {
270270 assert . deepEqual ( values , [ 6 , 12 , 20 ] ) ;
271271 } ) ;
272272
273- it ( 'passes optional set function' , ( ) => {
273+ it ( 'allows derived with different types' , ( ) => {
274+ const a = writable ( 'one' ) ;
275+ const b = writable ( 1 ) ;
276+
277+ // @ts -expect-error TODO feels like inference should work here
278+ const c = derived ( [ a , b ] , ( [ a , b ] ) => `${ a } ${ b } ` ) ;
279+
280+ assert . deepEqual ( get ( c ) , 'one 1' ) ;
281+
282+ a . set ( 'two' ) ;
283+ b . set ( 2 ) ;
284+ assert . deepEqual ( get ( c ) , 'two 2' ) ;
285+ } ) ;
286+
287+ it ( 'errors on undefined stores #1' , ( ) => {
288+ assert . throws ( ( ) => {
289+ // @ts -expect-error TODO feels like inference should work here
290+ derived ( null , ( n ) => n ) ;
291+ } ) ;
292+ } ) ;
293+
294+ it ( 'errors on undefined stores #2' , ( ) => {
295+ assert . throws ( ( ) => {
296+ const a = writable ( 1 ) ;
297+ // @ts -expect-error TODO feels like inference should work here
298+ derived ( [ a , null , undefined ] , ( [ n ] ) => {
299+ return n * 2 ;
300+ } ) ;
301+ } ) ;
302+ } ) ;
303+
304+ it ( 'works with RxJS-style observables' , ( ) => {
305+ // @ts -expect-error TODO feels like inference should work here
306+ const d = derived ( fake_observable , ( _ ) => _ ) ;
307+ assert . equal ( get ( d ) , 42 ) ;
308+ } ) ;
309+
310+ it ( 'passes optional `set` function' , ( ) => {
274311 const number = writable ( 1 ) ;
275312 const evens = derived (
276313 number ,
@@ -301,9 +338,9 @@ describe('derived', () => {
301338 assert . deepEqual ( values , [ 0 , 2 , 4 ] ) ;
302339 } ) ;
303340
304- it ( 'passes optional set and update functions' , ( ) => {
341+ it ( 'passes optional ` set` and ` update` functions' , ( ) => {
305342 const number = writable ( 1 ) ;
306- const evensAndSquaresOf4 = derived (
343+ const evens_and_squares_of_4 = derived (
307344 number ,
308345 // @ts -expect-error TODO feels like inference should work here
309346 ( n , set , update ) => {
@@ -316,7 +353,7 @@ describe('derived', () => {
316353
317354 const values : number [ ] = [ ] ;
318355
319- const unsubscribe = evensAndSquaresOf4 . subscribe ( ( value ) => {
356+ const unsubscribe = evens_and_squares_of_4 . subscribe ( ( value ) => {
320357 values . push ( value ) ;
321358 } ) ;
322359
@@ -341,21 +378,20 @@ describe('derived', () => {
341378 } ) ;
342379
343380 it ( 'prevents glitches' , ( ) => {
344- const lastname = writable ( 'Jekyll' ) ;
345-
381+ const last_name = writable ( 'Jekyll' ) ;
346382 // @ts -expect-error TODO feels like inference should work here
347- const firstname = derived ( lastname , ( n ) => ( n === 'Jekyll' ? 'Henry' : 'Edward' ) ) ;
383+ const first_name = derived ( last_name , ( n ) => ( n === 'Jekyll' ? 'Henry' : 'Edward' ) ) ;
348384
349385 // @ts -expect-error TODO feels like inference should work here
350- const fullname = derived ( [ firstname , lastname ] , ( names ) => names . join ( ' ' ) ) ;
386+ const full_name = derived ( [ first_name , last_name ] , ( names ) => names . join ( ' ' ) ) ;
351387
352388 const values : string [ ] = [ ] ;
353389
354- const unsubscribe = fullname . subscribe ( ( value ) => {
390+ const unsubscribe = full_name . subscribe ( ( value ) => {
355391 values . push ( value as string ) ;
356392 } ) ;
357393
358- lastname . set ( 'Hyde' ) ;
394+ last_name . set ( 'Hyde' ) ;
359395
360396 assert . deepEqual ( values , [ 'Henry Jekyll' , 'Edward Hyde' ] ) ;
361397
@@ -421,7 +457,7 @@ describe('derived', () => {
421457 unsubscribe ( ) ;
422458 } ) ;
423459
424- it ( 'is updated with safe_not_equal logic' , ( ) => {
460+ it ( 'is updated with ` safe_not_equal` logic' , ( ) => {
425461 const arr = [ 0 ] ;
426462
427463 const number = writable ( 1 ) ;
@@ -446,7 +482,7 @@ describe('derived', () => {
446482 unsubscribe ( ) ;
447483 } ) ;
448484
449- it ( 'calls a cleanup function' , ( ) => {
485+ it ( 'calls a ` cleanup` function' , ( ) => {
450486 const num = writable ( 1 ) ;
451487
452488 const values : number [ ] = [ ] ;
@@ -503,26 +539,6 @@ describe('derived', () => {
503539 unsubscribe ( ) ;
504540 } ) ;
505541
506- it ( 'allows derived with different types' , ( ) => {
507- const a = writable ( 'one' ) ;
508- const b = writable ( 1 ) ;
509-
510- // @ts -expect-error TODO feels like inference should work here
511- const c = derived ( [ a , b ] , ( [ a , b ] ) => `${ a } ${ b } ` ) ;
512-
513- assert . deepEqual ( get ( c ) , 'one 1' ) ;
514-
515- a . set ( 'two' ) ;
516- b . set ( 2 ) ;
517- assert . deepEqual ( get ( c ) , 'two 2' ) ;
518- } ) ;
519-
520- it ( 'works with RxJS-style observables' , ( ) => {
521- // @ts -expect-error TODO feels like inference should work here
522- const d = derived ( fake_observable , ( _ ) => _ ) ;
523- assert . equal ( get ( d ) , 42 ) ;
524- } ) ;
525-
526542 it ( "doesn't restart when unsubscribed from another store with a shared ancestor" , ( ) => {
527543 const a = writable ( true ) ;
528544 let b_started = false ;
@@ -545,23 +561,6 @@ describe('derived', () => {
545561 a . set ( false ) ;
546562 assert . equal ( b_started , false ) ;
547563 } ) ;
548-
549- it ( 'errors on undefined stores #1' , ( ) => {
550- assert . throws ( ( ) => {
551- // @ts -expect-error TODO feels like inference should work here
552- derived ( null , ( n ) => n ) ;
553- } ) ;
554- } ) ;
555-
556- it ( 'errors on undefined stores #2' , ( ) => {
557- assert . throws ( ( ) => {
558- const a = writable ( 1 ) ;
559- // @ts -expect-error TODO feels like inference should work here
560- derived ( [ a , null , undefined ] , ( [ n ] ) => {
561- return n * 2 ;
562- } ) ;
563- } ) ;
564- } ) ;
565564} ) ;
566565
567566describe ( 'get' , ( ) => {
@@ -577,17 +576,17 @@ describe('get', () => {
577576
578577describe ( 'readonly' , ( ) => {
579578 it ( 'makes a store readonly' , ( ) => {
580- const writableStore = writable ( 1 ) ;
581- const readableStore = readonly ( writableStore ) ;
579+ const writable_store = writable ( 1 ) ;
580+ const readable_store = readonly ( writable_store ) ;
582581
583- assert . equal ( get ( readableStore ) , get ( writableStore ) ) ;
582+ assert . equal ( get ( readable_store ) , get ( writable_store ) ) ;
584583
585- writableStore . set ( 2 ) ;
584+ writable_store . set ( 2 ) ;
586585
587- assert . equal ( get ( readableStore ) , 2 ) ;
588- assert . equal ( get ( readableStore ) , get ( writableStore ) ) ;
586+ assert . equal ( get ( readable_store ) , 2 ) ;
587+ assert . equal ( get ( readable_store ) , get ( writable_store ) ) ;
589588
590589 // @ts -ignore
591- assert . throws ( ( ) => readableStore . set ( 3 ) ) ;
590+ assert . throws ( ( ) => readable_store . set ( 3 ) ) ;
592591 } ) ;
593592} ) ;
0 commit comments