@@ -13,6 +13,8 @@ const {
13
13
isReactive,
14
14
defineComponent,
15
15
onMounted,
16
+ set,
17
+ del,
16
18
} = require ( '../src' )
17
19
const { sleep } = require ( './helpers/utils' )
18
20
@@ -896,6 +898,42 @@ describe('setup', () => {
896
898
expect ( vm . $el . textContent ) . toBe ( '2' )
897
899
} )
898
900
901
+ // #683 #603 #580
902
+ it ( 'should update directly when adding attributes to a reactive object' , async ( ) => {
903
+ const vm = new Vue ( {
904
+ template : '<div><button @click="add"/>{{ obj.a }}</div>' ,
905
+ setup ( ) {
906
+ const obj = reactive ( { } )
907
+ const add = ( ) => {
908
+ set ( obj , 'a' , 'new property' )
909
+ }
910
+ return { obj, add }
911
+ } ,
912
+ } ) . $mount ( )
913
+
914
+ expect ( vm . $el . textContent ) . toBe ( '' )
915
+ await vm . $el . querySelector ( 'button' ) . click ( )
916
+ expect ( vm . $el . textContent ) . toBe ( 'new property' )
917
+ } )
918
+
919
+ // #683 #603 #580
920
+ it ( 'should update directly when deleting attributes from a reactive object' , async ( ) => {
921
+ const vm = new Vue ( {
922
+ template : '<div><button @click="deleting"/>{{ obj.a }}</div>' ,
923
+ setup ( ) {
924
+ const obj = reactive ( { a : 'hello' } )
925
+ const deleting = ( ) => {
926
+ del ( obj , 'a' )
927
+ }
928
+ return { obj, deleting }
929
+ } ,
930
+ } ) . $mount ( )
931
+
932
+ expect ( vm . $el . textContent ) . toBe ( 'hello' )
933
+ await vm . $el . querySelector ( 'button' ) . click ( )
934
+ expect ( vm . $el . textContent ) . toBe ( '' )
935
+ } )
936
+
899
937
// #524
900
938
it ( 'should work with reactive arrays.' , async ( ) => {
901
939
const opts = {
0 commit comments