@@ -11,13 +11,14 @@ interface Dummy {
1111 template : `
1212 <div id="display-none" style="display:none">Hidden with display none</div>
1313 <div id="visibility-hidden" style="visibility:hidden">Hidden with visibility hidden</div>
14- <label>Hidden input element<input type="hidden"/></label>
14+ <label>Hidden input element<input type="hidden" /></label>
1515 <div hidden>Hidden by "hidden"-attribute</div>
1616 <div style="display:none"><div id="parent-display-none">Hidden by parent with display none</div></div>
1717 <div style="visibility:hidden"><div id="parent-visibility-hidden">Hidden by parent with display none</div></div>
1818 <div id="visible">Visible</div>
1919 <div id="classes" class="class-a class-b">Classes</div>
20- `
20+ <div id="styles" style="background-color: indianred; color: chocolate;"></div>
21+ ` ,
2122} )
2223export class MatchersComponent { }
2324
@@ -109,12 +110,34 @@ describe('Matchers', () => {
109110
110111 it ( 'should return true when expected is same as actual' , ( ) => {
111112 const actual : Dummy = { lorem : 'first' , ipsum : 'second' } ;
112- expect ( actual ) . toBePartial ( { ...actual } ) ;
113+ expect ( actual ) . toBePartial ( { ...actual } ) ;
113114 } ) ;
114115
115116 it ( 'should return false when expected is not partial of actual' , ( ) => {
116117 const actual : Dummy = { lorem : 'first' , ipsum : 'second' } ;
117118 expect ( actual ) . not . toBePartial ( { lorem : 'second' } ) ;
118119 } ) ;
119120 } ) ;
121+
122+ describe ( 'toHaveStyle' , ( ) => {
123+ it ( 'should return true when expected style exists on element' , ( ) => {
124+ const element = spectator . query ( '#styles' ) ;
125+ expect ( element ) . toHaveStyle ( { 'background-color' : 'indianred' } ) ;
126+ } ) ;
127+
128+ it ( 'should return true if all styles exist on element' , ( ) => {
129+ const element = spectator . query ( '#styles' ) ;
130+ expect ( element ) . toHaveStyle ( { 'background-color' : 'indianred' , color : 'chocolate' } ) ;
131+ } ) ;
132+
133+ it ( 'should return false if style exists on an element but has a different value than expected' , ( ) => {
134+ const element = spectator . query ( '#styles' ) ;
135+ expect ( element ) . not . toHaveStyle ( { color : 'blue' } ) ;
136+ } ) ;
137+
138+ it ( 'should return false when expected style does not exist on element' , ( ) => {
139+ const element = spectator . query ( '#styles' ) ;
140+ expect ( element ) . not . toHaveStyle ( { height : '100px' } ) ;
141+ } ) ;
142+ } ) ;
120143} ) ;
0 commit comments