Skip to content

Commit

Permalink
updating test for strict mode and non strict mode consistency
Browse files Browse the repository at this point in the history
the previous expect was relying on the fact that ButtonGroup first measurement happened before we mock the widths and positions of the buttons + buttongroups. That doesnt work well in strict mode and didnt feel reflective of browser behavior so I removed that expect
  • Loading branch information
LFDanLu committed Jan 5, 2023
1 parent 982c966 commit 0c72b09
Showing 1 changed file with 0 additions and 9 deletions.
9 changes: 0 additions & 9 deletions packages/@react-spectrum/buttongroup/test/ButtonGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ describe('ButtonGroup', function () {
describe('resizing', () => {
it('goes vertical if there is not enough room after buttongroup gets a new size', () => {
let setUp = ({buttonGroup, button1, button2, button3}) => {
// can't do anything about first render, so this starts with the resize
jest.spyOn(buttonGroup, 'offsetWidth', 'get').mockImplementationOnce(() => 88).mockImplementation(() => 90);
jest.spyOn(button1, 'offsetLeft', 'get').mockImplementation(() => 0);
jest.spyOn(button1, 'offsetWidth', 'get').mockImplementation(() => 30);
Expand All @@ -138,14 +137,6 @@ describe('ButtonGroup', function () {
let {getByTestId} = render(<ButtonGroupWithRefs setUp={setUp} />);
let buttonGroup = getByTestId(buttonGroupId);

if (process.env.STRICT_MODE) {
// If strict mode, render cycle happens twice which means a 2nd useLayoutEffect is triggered -> mock widths are now already set since
// ButtonGroupWithRefs's useEffect has already run
expect(buttonGroup).toHaveAttribute('class', expect.stringContaining('spectrum-ButtonGroup--vertical'));
} else {
expect(buttonGroup).not.toHaveAttribute('class', expect.stringContaining('spectrum-ButtonGroup--vertical'));
}

// ResizeObserver not actually implemented in jsdom, so rely on the fallback to window resize listener
act(() => {window.dispatchEvent(new Event('resize'));});
expect(buttonGroup).toHaveAttribute('class', expect.stringContaining('spectrum-ButtonGroup--vertical'));
Expand Down

0 comments on commit 0c72b09

Please sign in to comment.