| 970 | } |
| 971 | |
| 972 | function expectStickyStyles(element: any, zIndex: string, directions: PositionDirections = {}) { |
| 973 | expect(element.style.position).toContain('sticky'); |
| 974 | expect(element.style.zIndex).withContext(`Expected zIndex to be ${zIndex}`).toBe(zIndex); |
| 975 | |
| 976 | ['top', 'bottom', 'left', 'right'].forEach(d => { |
| 977 | const directionValue = directions[d]; |
| 978 | |
| 979 | if (!directionValue) { |
| 980 | // If no expected position for this direction, must either be unset or empty string |
| 981 | // If no expected position for this direction, must either be unset or empty string |
| 982 | expect(element.style[d] || 'unset') |
| 983 | .withContext(`Expected ${d} to be unset`) |
| 984 | .toBe('unset'); |
| 985 | return; |
| 986 | } |
| 987 | |
| 988 | const expectationMessage = `Expected direction ${d} to be ${directionValue}`; |
| 989 | |
| 990 | // If the direction contains `px`, we parse the number to be able to avoid deviations |
| 991 | // caused by individual browsers. |
| 992 | if (directionValue.includes('px')) { |
| 993 | expect(Math.round(parseInt(element.style[d]))) |
| 994 | .withContext(expectationMessage) |
| 995 | .toBe(Math.round(parseInt(directionValue))); |
| 996 | } else { |
| 997 | expect(element.style[d]).withContext(expectationMessage).toBe(directionValue); |
| 998 | } |
| 999 | }); |
| 1000 | } |
| 1001 | |
| 1002 | function expectStickyBorderClass(element: any, directions: {[key: string]: boolean} = {}) { |
| 1003 | ['top', 'bottom', 'left', 'right'].forEach(d => { |