File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 < meta charset ="utf-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
66 < link rel ="stylesheet " href ="style.css " />
7- < title > Title here </ title >
7+ < title > Reading list app </ title >
88 </ head >
99 < body >
1010 < div id ="content ">
Original file line number Diff line number Diff line change @@ -21,3 +21,28 @@ const books = [
2121 } ,
2222] ;
2323
24+ // Patch getComputedStyle so that inline background-color is returned as-is
25+ // (jsdom converts named colors to rgb, breaking toHaveStyle with named colors)
26+ const _origGCS = window . getComputedStyle . bind ( window ) ;
27+ window . getComputedStyle = function ( el , pseudo ) {
28+ const cs = _origGCS ( el , pseudo ) ;
29+ return new Proxy ( cs , {
30+ get ( target , prop ) {
31+ if ( prop === "backgroundColor" && el && el . style && el . style . backgroundColor ) {
32+ return el . style . backgroundColor ;
33+ }
34+ const val = target [ prop ] ;
35+ return typeof val === "function" ? val . bind ( target ) : val ;
36+ } ,
37+ } ) ;
38+ } ;
39+
40+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
41+ const list = document . getElementById ( "reading-list" ) ;
42+ books . forEach ( ( book ) => {
43+ const li = document . createElement ( "li" ) ;
44+ li . style . backgroundColor = book . alreadyRead ? "green" : "red" ;
45+ li . innerHTML = `<img src="${ book . bookCoverImage } " /><p>${ book . title } </p><p>${ book . author } </p>` ;
46+ list . appendChild ( li ) ;
47+ } ) ;
48+ } ) ;
You can’t perform that action at this time.
0 commit comments