1- import { flushSync } from 'svelte' ;
1+ import { flushSync , tick } from 'svelte' ;
22import { test } from '../../test' ;
33
44// This test counts mutations on hydration
@@ -16,7 +16,12 @@ export default test({
1616
1717 html : `
1818 <main id="main" class="browser">
19- <div class="custom svelte-1cjqok6 foo bar"></div>
19+ <div class="custom svelte-1cjqok6 foo bar" title="a title"></div>
20+ <span class="svelte-1cjqok6 foo bar"></span>
21+ <b class="custom foo bar"></b>
22+ <i class="foo bar"></i>
23+
24+ <div class="custom svelte-1cjqok6 foo bar" title="a title"></div>
2025 <span class="svelte-1cjqok6 foo bar"></span>
2126 <b class="custom foo bar"></b>
2227 <i class="foo bar"></i>
@@ -25,19 +30,97 @@ export default test({
2530
2631 ssrHtml : `
2732 <main id="main">
28- <div class="custom svelte-1cjqok6 foo bar"></div>
33+ <div class="custom svelte-1cjqok6 foo bar" title="a title"></div>
34+ <span class="svelte-1cjqok6 foo bar"></span>
35+ <b class="custom foo bar"></b>
36+ <i class="foo bar"></i>
37+
38+ <div class="custom svelte-1cjqok6 foo bar" title="a title"></div>
2939 <span class="svelte-1cjqok6 foo bar"></span>
3040 <b class="custom foo bar"></b>
3141 <i class="foo bar"></i>
3242 </main>
3343 ` ,
3444
35- async test ( { assert, component, instance } ) {
45+ async test ( { target , assert, component, instance } ) {
3646 flushSync ( ) ;
47+ tick ( ) ;
3748 assert . deepEqual ( instance . get_and_clear_mutations ( ) , [ 'MAIN' ] ) ;
3849
3950 component . foo = false ;
4051 flushSync ( ) ;
41- assert . deepEqual ( instance . get_and_clear_mutations ( ) , [ 'DIV' , 'SPAN' , 'B' , 'I' ] ) ;
52+ tick ( ) ;
53+ assert . deepEqual (
54+ instance . get_and_clear_mutations ( ) ,
55+ [ 'DIV' , 'SPAN' , 'B' , 'I' , 'DIV' , 'SPAN' , 'B' , 'I' ] ,
56+ 'first mutation'
57+ ) ;
58+
59+ assert . htmlEqual (
60+ target . innerHTML ,
61+ `
62+ <main id="main" class="browser">
63+ <div class="custom svelte-1cjqok6 bar" title="a title"></div>
64+ <span class="svelte-1cjqok6 bar"></span>
65+ <b class="custom bar"></b>
66+ <i class="bar"></i>
67+
68+ <div class="custom svelte-1cjqok6 bar" title="a title"></div>
69+ <span class="svelte-1cjqok6 bar"></span>
70+ <b class="custom bar"></b>
71+ <i class="bar"></i>
72+ </main>
73+ `
74+ ) ;
75+
76+ component . foo = true ;
77+ flushSync ( ) ;
78+ assert . deepEqual (
79+ instance . get_and_clear_mutations ( ) ,
80+ [ 'DIV' , 'SPAN' , 'B' , 'I' , 'DIV' , 'SPAN' , 'B' , 'I' ] ,
81+ 'second mutation'
82+ ) ;
83+
84+ assert . htmlEqual (
85+ target . innerHTML ,
86+ `
87+ <main id="main" class="browser">
88+ <div class="custom svelte-1cjqok6 bar foo" title="a title"></div>
89+ <span class="svelte-1cjqok6 bar foo"></span>
90+ <b class="custom bar foo"></b>
91+ <i class="bar foo"></i>
92+
93+ <div class="custom svelte-1cjqok6 bar foo" title="a title"></div>
94+ <span class="svelte-1cjqok6 bar foo"></span>
95+ <b class="custom bar foo"></b>
96+ <i class="bar foo"></i>
97+ </main>
98+ `
99+ ) ;
100+
101+ component . classname = 'another' ;
102+ flushSync ( ) ;
103+ assert . deepEqual (
104+ instance . get_and_clear_mutations ( ) ,
105+ [ 'DIV' , 'B' , 'DIV' , 'B' ] ,
106+ 'class mutation'
107+ ) ;
108+
109+ assert . htmlEqual (
110+ target . innerHTML ,
111+ `
112+ <main id="main" class="browser">
113+ <div class="another svelte-1cjqok6 foo bar" title="a title"></div>
114+ <span class="svelte-1cjqok6 bar foo"></span>
115+ <b class="another foo bar"></b>
116+ <i class="bar foo"></i>
117+
118+ <div class="another svelte-1cjqok6 foo bar" title="a title"></div>
119+ <span class="svelte-1cjqok6 bar foo"></span>
120+ <b class="another foo bar"></b>
121+ <i class="bar foo"></i>
122+ </main>
123+ `
124+ ) ;
42125 }
43126} ) ;
0 commit comments