@@ -20,7 +20,7 @@ describe('parseTemplate', () => {
2020 expect ( result ) . toContain ( '<title>Test Title 2</title>' ) ;
2121 } ) ;
2222
23- it ( 'should corrent upsert body script by order' , ( ) => {
23+ it ( 'should correctly upsert body script by order and remove sorting attributes ' , ( ) => {
2424 const parser = parseTemplate ( '<html><body></body></html>' , {
2525 bodyScripts : [
2626 { id : 'script1' , src : 'script1.js' , position : 'beginning' , order : 1 } ,
@@ -35,12 +35,15 @@ describe('parseTemplate', () => {
3535 { id : 'script2' , src : 'script2.js' , position : 'beginning' , order : 2 } ,
3636 ] )
3737 . serialize ( ) ;
38- expect ( result ) . toContain (
39- '<script id="script1" src="script1.js" data-order="1" data-position="beginning"></script>'
40- ) ;
41- expect ( result ) . toContain (
42- '<script id="script2" src="script2.js" data-order="2" data-position="beginning"></script>'
43- ) ;
38+
39+ // Check that scripts are present but sorting attributes are removed
40+ expect ( result ) . toContain ( '<script id="script1" src="script1.js"></script>' ) ;
41+ expect ( result ) . toContain ( '<script id="script2" src="script2.js"></script>' ) ;
42+
43+ // Check that sorting attributes are not present in final output
44+ expect ( result ) . not . toContain ( 'data-order="1"' ) ;
45+ expect ( result ) . not . toContain ( 'data-order="2"' ) ;
46+ expect ( result ) . not . toContain ( 'data-position="beginning"' ) ;
4447 } ) ;
4548
4649 it ( 'should update favicon when provided' , ( ) => {
@@ -68,7 +71,7 @@ describe('parseTemplate', () => {
6871 ) ;
6972 } ) ;
7073
71- it ( 'should update head styles when provided' , ( ) => {
74+ it ( 'should update head styles when provided and remove sorting attributes ' , ( ) => {
7275 const styles : StyleItem [ ] = [
7376 {
7477 href : 'style.css' ,
@@ -80,12 +83,19 @@ describe('parseTemplate', () => {
8083 const parser = parseTemplate ( '<html><head></head></html>' , {
8184 headStyles : styles ,
8285 } ) ;
83- expect ( parser . serialize ( ) ) . toContain (
84- '<link rel="stylesheet" href="style.css" id="style1" data-order="1" data-position="beginning">'
86+ const result = parser . serialize ( ) ;
87+
88+ // Check that style is present but sorting attributes are removed
89+ expect ( result ) . toContain (
90+ '<link rel="stylesheet" href="style.css" id="style1">'
8591 ) ;
92+
93+ // Check that sorting attributes are not present in final output
94+ expect ( result ) . not . toContain ( 'data-order="1"' ) ;
95+ expect ( result ) . not . toContain ( 'data-position="beginning"' ) ;
8696 } ) ;
8797
88- it ( 'should update inline styles when provided' , ( ) => {
98+ it ( 'should update inline styles when provided and remove sorting attributes ' , ( ) => {
8999 const inlineStyles : StyleInlineItem [ ] = [
90100 {
91101 content : 'body {}' ,
@@ -97,12 +107,17 @@ describe('parseTemplate', () => {
97107 const parser = parseTemplate ( '<html><head></head></html>' , {
98108 headInlineStyles : inlineStyles ,
99109 } ) ;
100- expect ( parser . serialize ( ) ) . toContain (
101- '<style id="style1" data-order="1" data-position="beginning">body {}</style>'
102- ) ;
110+ const result = parser . serialize ( ) ;
111+
112+ // Check that style is present but sorting attributes are removed
113+ expect ( result ) . toContain ( '<style id="style1">body {}</style>' ) ;
114+
115+ // Check that sorting attributes are not present in final output
116+ expect ( result ) . not . toContain ( 'data-order="1"' ) ;
117+ expect ( result ) . not . toContain ( 'data-position="beginning"' ) ;
103118 } ) ;
104119
105- it ( 'should update head scripts when provided' , ( ) => {
120+ it ( 'should update head scripts when provided and remove sorting attributes ' , ( ) => {
106121 const scripts : ScriptItem [ ] = [
107122 {
108123 src : 'script.js' ,
@@ -114,12 +129,17 @@ describe('parseTemplate', () => {
114129 const parser = parseTemplate ( '<html><head></head></html>' , {
115130 headScripts : scripts ,
116131 } ) ;
117- expect ( parser . serialize ( ) ) . toContain (
118- '<script id="script1" src="script.js" data-order="1" data-position="beginning"></script>'
119- ) ;
132+ const result = parser . serialize ( ) ;
133+
134+ // Check that script is present but sorting attributes are removed
135+ expect ( result ) . toContain ( '<script id="script1" src="script.js"></script>' ) ;
136+
137+ // Check that sorting attributes are not present in final output
138+ expect ( result ) . not . toContain ( 'data-order="1"' ) ;
139+ expect ( result ) . not . toContain ( 'data-position="beginning"' ) ;
120140 } ) ;
121141
122- it ( 'should update head inline scripts when provided' , ( ) => {
142+ it ( 'should update head inline scripts when provided and remove sorting attributes ' , ( ) => {
123143 const inlineScripts : ScriptInlineItem [ ] = [
124144 {
125145 content : 'console.log()' ,
@@ -131,12 +151,17 @@ describe('parseTemplate', () => {
131151 const parser = parseTemplate ( '<html><head></head></html>' , {
132152 headInlineScripts : inlineScripts ,
133153 } ) ;
134- expect ( parser . serialize ( ) ) . toContain (
135- '<script id="script1" data-order="1" data-position="beginning">console.log()</script>'
136- ) ;
154+ const result = parser . serialize ( ) ;
155+
156+ // Check that script is present but sorting attributes are removed
157+ expect ( result ) . toContain ( '<script id="script1">console.log()</script>' ) ;
158+
159+ // Check that sorting attributes are not present in final output
160+ expect ( result ) . not . toContain ( 'data-order="1"' ) ;
161+ expect ( result ) . not . toContain ( 'data-position="beginning"' ) ;
137162 } ) ;
138163
139- it ( 'should update body scripts when provided' , ( ) => {
164+ it ( 'should update body scripts when provided and remove sorting attributes ' , ( ) => {
140165 const bodyScripts : ScriptItem [ ] = [
141166 {
142167 src : 'script.js' ,
@@ -148,8 +173,13 @@ describe('parseTemplate', () => {
148173 const parser = parseTemplate ( '<html><head></head><body></body></html>' , {
149174 bodyScripts : bodyScripts ,
150175 } ) ;
151- expect ( parser . serialize ( ) ) . toContain (
152- '<script id="script1" src="script.js" data-order="1" data-position="beginning"></script>'
153- ) ;
176+ const result = parser . serialize ( ) ;
177+
178+ // Check that script is present but sorting attributes are removed
179+ expect ( result ) . toContain ( '<script id="script1" src="script.js"></script>' ) ;
180+
181+ // Check that sorting attributes are not present in final output
182+ expect ( result ) . not . toContain ( 'data-order="1"' ) ;
183+ expect ( result ) . not . toContain ( 'data-position="beginning"' ) ;
154184 } ) ;
155185} ) ;
0 commit comments