Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-testing-library": "^7.15.4",
"eslint-plugin-theme-colors": "file:eslint-rules/eslint-plugin-theme-colors",
"fetch-mock": "^11.1.5",
"fetch-mock": "^12.6.0",
"fork-ts-checker-webpack-plugin": "^9.1.0",
"history": "^5.3.0",
"html-webpack-plugin": "^5.6.6",
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@types/prop-types": "^15.7.15",
"@types/rison": "0.1.0",
"@types/seedrandom": "^3.0.8",
"fetch-mock": "^11.1.4",
"fetch-mock": "^12.6.0",
"jest-mock-console": "^2.0.0",
"resize-observer-polyfill": "1.5.1",
"timezone-mock": "1.3.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ import { ImageLoader, type BackgroundPosition } from './ImageLoader';
global.URL.createObjectURL = jest.fn(() => '/local_url');
const blob = new Blob([], { type: 'image/png' });

beforeAll(() => {
fetchMock.mockGlobal();
});

afterAll(() => {
fetchMock.hardReset();
});

fetchMock.get(
'/thumbnail',
'glob:*/thumbnail',
{ body: blob, headers: { 'Content-Type': 'image/png' } },
{
sendAsJson: false,
},
{ name: 'thumbnail' },
);

describe('ImageLoader', () => {
Expand All @@ -44,7 +50,7 @@ describe('ImageLoader', () => {
return render(<ImageLoader {...props} />);
};

afterEach(() => fetchMock.resetHistory());
afterEach(() => fetchMock.clearHistory());

it('is a valid element', async () => {
setup();
Expand All @@ -57,7 +63,7 @@ describe('ImageLoader', () => {
'src',
'/fallback',
);
expect(fetchMock.calls(/thumbnail/)).toHaveLength(1);
expect(fetchMock.callHistory.calls(/thumbnail/)).toHaveLength(1);
expect(global.URL.createObjectURL).toHaveBeenCalled();
expect(await screen.findByTestId('image-loader')).toHaveAttribute(
'src',
Expand All @@ -66,13 +72,14 @@ describe('ImageLoader', () => {
});

it('displays fallback image when response is not an image', async () => {
fetchMock.once('/thumbnail2', {});
setup({ src: '/thumbnail2' });
fetchMock.once('glob:*/thumbnail2', {}, { name: 'thumbnail2' });

setup({ src: 'glob:*/thumbnail2' });
expect(screen.getByTestId('image-loader')).toHaveAttribute(
'src',
'/fallback',
);
expect(fetchMock.calls(/thumbnail2/)).toHaveLength(1);
expect(fetchMock.callHistory.calls(/thumbnail2/)).toHaveLength(1);
expect(await screen.findByTestId('image-loader')).toHaveAttribute(
'src',
'/fallback',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import { SliceIdAndOrFormData } from '../../../src/chart/clients/ChartClient';

configureTranslation();

beforeAll(() => fetchMock.mockGlobal());
afterAll(() => fetchMock.hardReset());

describe('ChartClient', () => {
let chartClient: ChartClient;

Expand All @@ -50,7 +53,7 @@ describe('ChartClient', () => {
chartClient = new ChartClient();
});

afterEach(() => fetchMock.restore());
afterEach(() => fetchMock.removeRoutes().clearHistory());

describe('new ChartClient(config)', () => {
it('creates a client without argument', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import fetchMock from 'fetch-mock';
import { SupersetClient, SupersetClientClass } from '@superset-ui/core';
import { LOGIN_GLOB } from './fixtures/constants';

beforeAll(() => fetchMock.mockGlobal());
afterAll(() => fetchMock.hardReset());

describe('SupersetClient', () => {
beforeAll(() => fetchMock.get(LOGIN_GLOB, { result: '' }));
beforeAll(() => fetchMock.get(LOGIN_GLOB, { result: '1234' }));

afterAll(() => fetchMock.restore());
afterAll(() => fetchMock.removeRoutes().clearHistory());

afterEach(() => SupersetClient.reset());

Expand Down Expand Up @@ -108,9 +111,11 @@ describe('SupersetClient', () => {
mockDeleteUrl,
];
networkCalls.map((url: string) =>
expect(fetchMock.calls(url)[0][1]?.headers).toStrictEqual({
Accept: 'application/json',
'X-CSRFToken': '1234',
expect(
fetchMock.callHistory.calls(url)[0].options?.headers,
).toStrictEqual({
accept: 'application/json',
'x-csrftoken': '1234',
}),
);

Expand All @@ -137,6 +142,6 @@ describe('SupersetClient', () => {
authenticatedSpy.mockRestore();
csrfSpy.mockRestore();

fetchMock.reset();
fetchMock.clearHistory().removeRoutes();
});
});
Loading
Loading