11import { $ , component$ , noSerialize } from '@qwik.dev/core' ;
2- import { describe , expect , it } from 'vitest' ;
2+ import { describe , expect , it , vi } from 'vitest' ;
33import { _fnSignal , _wrapProp } from '../internal' ;
44import { EffectPropData , type Signal } from '../signal/signal' ;
55import {
@@ -863,7 +863,7 @@ describe('shared-serialization', () => {
863863 (27 chars)"
864864 ` ) ;
865865 } ) ;
866- it ( 'should not use SerializeSymbol if not function' , async ( ) => {
866+ it ( 'should not use SerializerSymbol if not function' , async ( ) => {
867867 const obj = { hi : 'orig' , [ SerializerSymbol ] : 'hey' } ;
868868 const state = await serialize ( obj ) ;
869869 expect ( dumpState ( state ) ) . toMatchInlineSnapshot ( `
@@ -875,6 +875,33 @@ describe('shared-serialization', () => {
875875 (22 chars)"
876876 ` ) ;
877877 } ) ;
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 ( ) ;
878905 } ) ;
879906} ) ;
880907
0 commit comments