123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import {reactHooks} from 'sentry-test/reactTestingLibrary';
- import {Client} from 'sentry/api';
- import useApi from 'sentry/utils/useApi';
- describe('useApi', function () {
- it('provides an api client', function () {
- const {result} = reactHooks.renderHook(useApi);
- expect(result.current).toBeInstanceOf(Client);
- });
- it('cancels pending API requests when unmounted', function () {
- const {result, unmount} = reactHooks.renderHook(useApi);
- jest.spyOn(result.current, 'clear');
- unmount();
- expect(result.current.clear).toHaveBeenCalled();
- });
- it('does not cancel inflights when persistInFlight is true', function () {
- const {result, unmount} = reactHooks.renderHook(useApi, {
- initialProps: {persistInFlight: true},
- });
- jest.spyOn(result.current, 'clear');
- unmount();
- expect(result.current.clear).not.toHaveBeenCalled();
- });
- it('uses pass through API when provided', function () {
- const myClient = new Client();
- const {unmount} = reactHooks.renderHook(useApi, {initialProps: {api: myClient}});
- jest.spyOn(myClient, 'clear');
- unmount();
- expect(myClient.clear).toHaveBeenCalled();
- });
- });
|