@@ -11,73 +11,65 @@ describe("All the styles should be applied", () => {
1111 const title = document . querySelector ( 'title' )
1212 const link = document . querySelector ( 'link' )
1313
14- test ( "The <img> tag has to be removed" , ( ) => {
15- document . querySelector (
16- "head"
17- ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
18- expect ( document . querySelector ( "img" ) ) . toBeFalsy ( ) ;
19- } ) ;
20- test ( "The <div> tag should exists" , ( ) => {
21- document . querySelector (
22- "head"
23- ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
24- expect ( document . querySelector ( "div" ) ) . toBeTruthy ( ) ;
25- } ) ;
26- test ( "the width in the div Tag should be '200px'" , ( ) => {
27- // get computed styles of any element you like
28- document . querySelector (
29- "head"
30- ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
31- const divTag = document . querySelector ( "div" ) ;
32- let idTagStyles = window . getComputedStyle ( divTag ) ;
33- expect ( idTagStyles [ "width" ] ) . toBe ( "200px" ) ;
34- } ) ;
35- test ( "the height in the div Tag should be '200px'" , ( ) => {
36- // get computed styles of any element you like
37- document . querySelector (
38- "head"
39- ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
40- const divTag = document . querySelector ( "div" ) ;
41- let idTagStyles = window . getComputedStyle ( divTag ) ;
42- expect ( idTagStyles [ "height" ] ) . toBe ( "200px" ) ;
43- } ) ;
44- test ( "the border radius in the div Tag should be '100%'" , ( ) => {
45- // get computed styles of any element you like
14+ const img = document . querySelector ( ".rounded" )
15+
16+ test ( "the img tag should exist" , ( ) => {
17+ expect ( img ) . toBeTruthy ( ) ;
18+ } )
19+
20+ test ( "the width in the img Tag should be equal to its height and vice versa" , ( ) => {
4621 document . querySelector (
4722 "head"
4823 ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
49- const divTag = document . querySelector ( "div" ) ;
50- let idTagStyles = window . getComputedStyle ( divTag ) ;
51- expect ( idTagStyles [ "border-radius" ] ) . toBe ( "100%" ) ;
24+
25+ let cssArray = document . styleSheets [ 0 ] . cssRules ;
26+
27+ let width = "" ;
28+ let height = "" ;
29+
30+ for ( let i = 0 ; i < cssArray . length ; i ++ ) {
31+ if ( cssArray [ i ] . selectorText === ".rounded" ) {
32+ width = cssArray [ i ] . style [ "width" ] ;
33+ height = cssArray [ i ] . style [ "height" ] ;
34+ }
35+ }
36+
37+ // checks if styles return empty string "" or undefined
38+ expect ( width ) . toBeTruthy ( ) ;
39+ expect ( height ) . toBeTruthy ( ) ;
40+
41+ expect ( width ) . toBe ( height ) ;
42+ expect ( height ) . toBe ( width ) ;
5243 } ) ;
53- test ( "the background position x in the div Tag should be 'center'" , ( ) => {
54- // get computed styles of any element you like
44+
45+ test ( "the border radius of the img Tag should be '100%'" , ( ) => {
5546 document . querySelector (
5647 "head"
5748 ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
58- const divTag = document . querySelector ( "div" ) ;
59- let idTagStyles = window . getComputedStyle ( divTag ) ;
60- expect ( idTagStyles [ "background-position-x "] ) . toBe ( "center " ) ;
49+
50+ let imgStyle = window . getComputedStyle ( img ) ;
51+ expect ( imgStyle [ "border-radius "] ) . toBe ( "100% " ) ;
6152 } ) ;
62- test ( "the background position y in the div Tag should be 'center'" , ( ) => {
63- // get computed styles of any element you like
53+
54+ test ( "the object-fit value of the img Tag should be 'cover'" , ( ) => {
6455 document . querySelector (
6556 "head"
6657 ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
67- const divTag = document . querySelector ( "div" ) ;
68- let idTagStyles = window . getComputedStyle ( divTag ) ;
69- expect ( idTagStyles [ "background-position-y "] ) . toBe ( "center " ) ;
58+
59+ let imgStyle = window . getComputedStyle ( img ) ;
60+ expect ( imgStyle [ "object-fit "] ) . toBe ( "cover " ) ;
7061 } ) ;
71- test ( "the background image in the div Tag should exists" , ( ) => {
72- // get computed styles of any element you like
62+
63+ test ( "the object-position value of the img Tag should be 'top'" , ( ) => {
7364 document . querySelector (
7465 "head"
7566 ) . innerHTML = `<style>${ css . toString ( ) } </style>` ;
76- const divTag = document . querySelector ( "div" ) ;
77- let idTagStyles = window . getComputedStyle ( divTag ) ;
78- expect ( idTagStyles [ "background-image "] ) . toBeTruthy ( ) ;
67+
68+ let imgStyle = window . getComputedStyle ( img ) ;
69+ expect ( imgStyle [ "object-position "] ) . toBe ( "top" ) ;
7970 } ) ;
80- test ( "You should not change the existing head tag elements" , ( ) => {
71+
72+ test ( "You should not change the existing head tag elements" , ( ) => {
8173 let head = document . querySelector ( 'head' )
8274 expect ( head ) . toBeTruthy ( )
8375
0 commit comments