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 8ca6c15 commit d8ba2fc
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('increases over time', () => {
const loading = mountWithAppProvider(<Loading />);

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

loading.update();

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

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 d8ba2fc

Please sign in to comment.