summaryrefslogtreecommitdiff
path: root/spec/frontend/lib/utils/css_utils_spec.js
blob: dcaeb075c93796691f1f907aecb3becbd7e007c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { getCssClassDimensions } from '~/lib/utils/css_utils';

describe('getCssClassDimensions', () => {
  const mockDimensions = { width: 1, height: 2 };
  let actual;

  beforeEach(() => {
    jest.spyOn(Element.prototype, 'getBoundingClientRect').mockReturnValue(mockDimensions);
    actual = getCssClassDimensions('foo bar');
  });

  it('returns the measured width and height', () => {
    expect(actual).toEqual(mockDimensions);
  });

  it('measures an element with the given classes', () => {
    expect(Element.prototype.getBoundingClientRect).toHaveBeenCalledTimes(1);

    const [tempElement] = Element.prototype.getBoundingClientRect.mock.contexts;
    expect([...tempElement.classList]).toEqual(['foo', 'bar']);
  });
});