1
1
import { $ , component$ , noSerialize } from '@qwik.dev/core' ;
2
- import { describe , expect , it } from 'vitest' ;
2
+ import { describe , expect , it , vi } from 'vitest' ;
3
3
import { _fnSignal , _wrapProp } from '../internal' ;
4
4
import { EffectPropData , type Signal } from '../signal/signal' ;
5
5
import {
@@ -863,7 +863,7 @@ describe('shared-serialization', () => {
863
863
(27 chars)"
864
864
` ) ;
865
865
} ) ;
866
- it ( 'should not use SerializeSymbol if not function' , async ( ) => {
866
+ it ( 'should not use SerializerSymbol if not function' , async ( ) => {
867
867
const obj = { hi : 'orig' , [ SerializerSymbol ] : 'hey' } ;
868
868
const state = await serialize ( obj ) ;
869
869
expect ( dumpState ( state ) ) . toMatchInlineSnapshot ( `
@@ -875,6 +875,33 @@ describe('shared-serialization', () => {
875
875
(22 chars)"
876
876
` ) ;
877
877
} ) ;
878
+ it ( 'should unwrap promises from SerializerSymbol' , async ( ) => {
879
+ class Foo {
880
+ hi = 'promise' ;
881
+ async [ SerializerSymbol ] ( ) {
882
+ return Promise . resolve ( this . hi ) ;
883
+ }
884
+ }
885
+ const state = await serialize ( new Foo ( ) ) ;
886
+ expect ( dumpState ( state ) ) . toMatchInlineSnapshot ( `
887
+ "
888
+ 0 String "promise"
889
+ (13 chars)"
890
+ ` ) ;
891
+ } ) ;
892
+ } ) ;
893
+ it ( 'should throw rejected promises from SerializerSymbol' , async ( ) => {
894
+ const consoleSpy = vi . spyOn ( console , 'error' ) ;
895
+
896
+ class Foo {
897
+ hi = 'promise' ;
898
+ async [ SerializerSymbol ] ( ) {
899
+ throw 'oh no' ;
900
+ }
901
+ }
902
+ await expect ( serialize ( new Foo ( ) ) ) . rejects . toThrow ( 'Q52' ) ;
903
+ expect ( consoleSpy ) . toHaveBeenCalledWith ( 'oh no' ) ;
904
+ consoleSpy . mockRestore ( ) ;
878
905
} ) ;
879
906
} ) ;
880
907
0 commit comments