@@ -310,7 +310,7 @@ describe('Middleware options', () => {
310
310
311
311
it ( 'should call a new onSave function after being set' , ( ) => {
312
312
global . console . info = vi . fn ( ) ;
313
- global . console . log = vi . fn ( ) ;
313
+ global . console . warn = vi . fn ( ) ;
314
314
global . console . error = vi . fn ( ) ;
315
315
const storeWithOnSave = createVanillaStore ( {
316
316
onSave : ( pastStates ) => {
@@ -325,11 +325,11 @@ describe('Middleware options', () => {
325
325
} ) ;
326
326
expect ( storeWithOnSave . temporal . getState ( ) . pastStates . length ) . toBe ( 2 ) ;
327
327
expect ( console . info ) . toHaveBeenCalledTimes ( 2 ) ;
328
- expect ( console . log ) . toHaveBeenCalledTimes ( 0 ) ;
328
+ expect ( console . warn ) . toHaveBeenCalledTimes ( 0 ) ;
329
329
expect ( console . error ) . toHaveBeenCalledTimes ( 0 ) ;
330
330
act ( ( ) => {
331
331
setOnSave ( ( pastStates , currentState ) => {
332
- console . log ( pastStates , currentState ) ;
332
+ console . warn ( pastStates , currentState ) ;
333
333
} ) ;
334
334
} ) ;
335
335
act ( ( ) => {
@@ -338,7 +338,7 @@ describe('Middleware options', () => {
338
338
} ) ;
339
339
expect ( storeWithOnSave . temporal . getState ( ) . pastStates . length ) . toBe ( 4 ) ;
340
340
expect ( console . info ) . toHaveBeenCalledTimes ( 2 ) ;
341
- expect ( console . log ) . toHaveBeenCalledTimes ( 2 ) ;
341
+ expect ( console . warn ) . toHaveBeenCalledTimes ( 2 ) ;
342
342
expect ( console . error ) . toHaveBeenCalledTimes ( 0 ) ;
343
343
act ( ( ) => {
344
344
setOnSave ( ( pastStates , currentState ) => {
@@ -351,7 +351,7 @@ describe('Middleware options', () => {
351
351
} ) ;
352
352
expect ( storeWithOnSave . temporal . getState ( ) . pastStates . length ) . toBe ( 6 ) ;
353
353
expect ( console . info ) . toHaveBeenCalledTimes ( 2 ) ;
354
- expect ( console . log ) . toHaveBeenCalledTimes ( 2 ) ;
354
+ expect ( console . warn ) . toHaveBeenCalledTimes ( 2 ) ;
355
355
expect ( console . error ) . toHaveBeenCalledTimes ( 2 ) ;
356
356
} ) ;
357
357
} ) ;
@@ -425,17 +425,16 @@ describe('Middleware options', () => {
425
425
expect ( storeWithHandleSet . temporal . getState ( ) . futureStates . length ) . toBe (
426
426
2 ,
427
427
) ;
428
- expect ( console . log ) . toHaveBeenCalledTimes ( 2 ) ;
428
+ expect ( console . warn ) . toHaveBeenCalledTimes ( 2 ) ;
429
429
} ) ;
430
430
} ) ;
431
431
432
432
describe ( 'secret internals' , ( ) => {
433
433
it ( 'should have a secret internal state' , ( ) => {
434
- const { __internal } =
434
+ const { __handleUserSet , __onSave } =
435
435
store . temporal . getState ( ) as TemporalStateWithInternals < MyState > ;
436
- expect ( __internal ) . toBeDefined ( ) ;
437
- expect ( __internal . handleUserSet ) . toBeInstanceOf ( Function ) ;
438
- expect ( __internal . onSave ) . toBe ( undefined ) ;
436
+ expect ( __handleUserSet ) . toBeInstanceOf ( Function ) ;
437
+ expect ( __onSave ) . toBe ( undefined ) ;
439
438
} ) ;
440
439
describe ( 'onSave' , ( ) => {
441
440
it ( 'should call onSave cb without adding a new state when onSave is set by user' , ( ) => {
@@ -446,13 +445,12 @@ describe('Middleware options', () => {
446
445
console . error ( pastStates , currentState ) ;
447
446
} ) ;
448
447
} ) ;
449
- const { __internal } =
448
+ const { __onSave } =
450
449
store . temporal . getState ( ) as TemporalStateWithInternals < MyState > ;
451
- const { onSave } = __internal ;
452
450
act ( ( ) => {
453
- onSave ( store . getState ( ) , store . getState ( ) ) ;
451
+ __onSave ( store . getState ( ) , store . getState ( ) ) ;
454
452
} ) ;
455
- expect ( __internal . onSave ) . toBeInstanceOf ( Function ) ;
453
+ expect ( __onSave ) . toBeInstanceOf ( Function ) ;
456
454
expect ( store . temporal . getState ( ) . pastStates . length ) . toBe ( 0 ) ;
457
455
expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
458
456
} ) ;
@@ -463,11 +461,10 @@ describe('Middleware options', () => {
463
461
console . info ( pastStates ) ;
464
462
} ,
465
463
} ) ;
466
- const { __internal } =
464
+ const { __onSave } =
467
465
storeWithOnSave . temporal . getState ( ) as TemporalStateWithInternals < MyState > ;
468
- const { onSave } = __internal ;
469
466
act ( ( ) => {
470
- onSave ( storeWithOnSave . getState ( ) , storeWithOnSave . getState ( ) ) ;
467
+ __onSave ( storeWithOnSave . getState ( ) , storeWithOnSave . getState ( ) ) ;
471
468
} ) ;
472
469
expect ( storeWithOnSave . temporal . getState ( ) . pastStates . length ) . toBe ( 0 ) ;
473
470
expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -483,7 +480,7 @@ describe('Middleware options', () => {
483
480
act ( ( ) => {
484
481
(
485
482
storeWithOnSave . temporal . getState ( ) as TemporalStateWithInternals < MyState >
486
- ) . __internal . onSave (
483
+ ) . __onSave (
487
484
storeWithOnSave . getState ( ) ,
488
485
storeWithOnSave . getState ( ) ,
489
486
) ;
@@ -501,7 +498,7 @@ describe('Middleware options', () => {
501
498
act ( ( ) => {
502
499
(
503
500
storeWithOnSave . temporal . getState ( ) as TemporalStateWithInternals < MyState >
504
- ) . __internal . onSave ( store . getState ( ) , store . getState ( ) ) ;
501
+ ) . __onSave ( store . getState ( ) , store . getState ( ) ) ;
505
502
} ) ;
506
503
expect ( store . temporal . getState ( ) . pastStates . length ) . toBe ( 0 ) ;
507
504
expect ( console . dir ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -511,31 +508,29 @@ describe('Middleware options', () => {
511
508
512
509
describe ( 'handleUserSet' , ( ) => {
513
510
it ( 'should update the temporal store with the pastState when called' , ( ) => {
514
- const { __internal } =
511
+ const { __handleUserSet } =
515
512
store . temporal . getState ( ) as TemporalStateWithInternals < MyState > ;
516
- const { handleUserSet } = __internal ;
517
513
act ( ( ) => {
518
- handleUserSet ( store . getState ( ) ) ;
514
+ __handleUserSet ( store . getState ( ) ) ;
519
515
} ) ;
520
516
expect ( store . temporal . getState ( ) . pastStates . length ) . toBe ( 1 ) ;
521
517
} ) ;
522
518
523
519
it ( 'should only update if the the status is tracking' , ( ) => {
524
- const { __internal } =
520
+ const { __handleUserSet } =
525
521
store . temporal . getState ( ) as TemporalStateWithInternals < MyState > ;
526
- const { handleUserSet } = __internal ;
527
522
act ( ( ) => {
528
- handleUserSet ( store . getState ( ) ) ;
523
+ __handleUserSet ( store . getState ( ) ) ;
529
524
} ) ;
530
525
expect ( store . temporal . getState ( ) . pastStates . length ) . toBe ( 1 ) ;
531
526
act ( ( ) => {
532
527
store . temporal . getState ( ) . pause ( ) ;
533
- handleUserSet ( store . getState ( ) ) ;
528
+ __handleUserSet ( store . getState ( ) ) ;
534
529
} ) ;
535
530
expect ( store . temporal . getState ( ) . pastStates . length ) . toBe ( 1 ) ;
536
531
act ( ( ) => {
537
532
store . temporal . getState ( ) . resume ( ) ;
538
- handleUserSet ( store . getState ( ) ) ;
533
+ __handleUserSet ( store . getState ( ) ) ;
539
534
} ) ;
540
535
} ) ;
541
536
0 commit comments