@@ -16,6 +16,14 @@ import type { BadgeParams, ContributionCalendar, StreakStats, MonthlyStats } fro
1616import { hexColor } from './sanitizer' ;
1717import { themes } from './themes' ;
1818
19+ function assertValidSVG ( svgString : string ) : void {
20+ const doc = new DOMParser ( ) . parseFromString ( svgString , 'image/svg+xml' ) ;
21+
22+ const parserError = doc . querySelector ( 'parsererror' ) ;
23+
24+ expect ( parserError ) . toBeNull ( ) ;
25+ }
26+
1927describe ( 'generateSVG' , ( ) => {
2028 const mockStats : StreakStats = {
2129 currentStreak : 5 ,
@@ -50,6 +58,8 @@ describe('generateSVG', () => {
5058 mockCalendar
5159 ) ;
5260
61+ assertValidSVG ( svg ) ;
62+
5363 expect ( svg ) . not . toContain ( 'CURRENT_STREAK' ) ;
5464 expect ( svg ) . not . toContain ( 'ANNUAL_SYNC_TOTAL' ) ;
5565 expect ( svg ) . not . toContain ( 'PEAK_STREAK' ) ;
@@ -70,6 +80,8 @@ describe('generateSVG', () => {
7080 mockCalendar
7181 ) ;
7282
83+ assertValidSVG ( svg ) ;
84+
7385 expect ( svg ) . toContain ( 'CURRENT_STREAK' ) ;
7486 expect ( svg ) . toContain ( 'ANNUAL_SYNC_TOTAL' ) ;
7587 expect ( svg ) . toContain ( 'PEAK_STREAK' ) ;
@@ -78,6 +90,8 @@ describe('generateSVG', () => {
7890 it ( 'uses default typography when no font is passed' , ( ) => {
7991 const svg = generateSVG ( mockStats , { user : 'avi' } as unknown as BadgeParams , mockCalendar ) ;
8092
93+ assertValidSVG ( svg ) ;
94+
8195 expect ( svg ) . toContain ( 'Syncopate' ) ;
8296 expect ( svg ) . toContain ( 'Space Grotesk' ) ;
8397 } ) ;
@@ -89,6 +103,8 @@ describe('generateSVG', () => {
89103 mockCalendar
90104 ) ;
91105
106+ assertValidSVG ( svg ) ;
107+
92108 expect ( svg ) . toContain ( 'JetBrains Mono' ) ;
93109 } ) ;
94110
@@ -99,6 +115,8 @@ describe('generateSVG', () => {
99115 mockCalendar
100116 ) ;
101117
118+ assertValidSVG ( svg ) ;
119+
102120 expect ( svg ) . toContain ( 'rx="0"' ) ;
103121 } ) ;
104122
0 commit comments