Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sijad committed Nov 27, 2019
1 parent 07a6c05 commit 9c66eab
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/components/Frame/components/Loading/tests/Loading.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import React from 'react';
import {mountWithAppProvider} from 'test-utilities/legacy';
import {animationFrame} from '@shopify/jest-dom-mocks';
import {act} from 'react-dom/test-utils';
import {Loading} from '../Loading';

describe('<Loading />', () => {
const loading = mountWithAppProvider(<Loading />);
beforeEach(() => {
animationFrame.mock();
});

afterEach(() => {
animationFrame.restore();
});

it('does not increment more than threshold', () => {
const loading = mountWithAppProvider(<Loading />);

it('mounts', () => {
expect(loading.exists()).toBe(true);
for (let i = 0; i <= 100000; i++) {
act(() => animationFrame.runFrame());
}

loading.update();

expect(loading.find('.Level').prop('aria-valuenow')).toBe(99);
});

it('unmounts safely', () => {
it('cancels the animationFrame on unmount', () => {
const cancelAnimationFrameSpy = jest.spyOn(window, 'cancelAnimationFrame');
const loading = mountWithAppProvider(<Loading />);

expect(() => {
loading.unmount();
}).not.toThrow();

expect(cancelAnimationFrameSpy).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 9c66eab

Please sign in to comment.