@@ -11,73 +11,65 @@ describe("All the styles should be applied", () => {
11
11
const title = document . querySelector ( 'title' )
12
12
const link = document . querySelector ( 'link' )
13
13
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" , ( ) => {
46
21
document . querySelector (
47
22
"head"
48
23
) . 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 ) ;
52
43
} ) ;
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%'" , ( ) => {
55
46
document . querySelector (
56
47
"head"
57
48
) . 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% " ) ;
61
52
} ) ;
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'" , ( ) => {
64
55
document . querySelector (
65
56
"head"
66
57
) . 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 " ) ;
70
61
} ) ;
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'" , ( ) => {
73
64
document . querySelector (
74
65
"head"
75
66
) . 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" ) ;
79
70
} ) ;
80
- test ( "You should not change the existing head tag elements" , ( ) => {
71
+
72
+ test ( "You should not change the existing head tag elements" , ( ) => {
81
73
let head = document . querySelector ( 'head' )
82
74
expect ( head ) . toBeTruthy ( )
83
75
0 commit comments