diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index 700652a0171d3..9777651427545 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -280,7 +280,6 @@ module.exports = { 'theme-colors/no-literal-colors': 0, 'translation-vars/no-template-vars': 0, 'no-restricted-imports': 0, - 'jest/no-alias-methods': 0, 'react/no-void-elements': 0, }, }, @@ -371,7 +370,6 @@ module.exports = { 'react-prefer-function-component/react-prefer-function-component': 1, 'prettier/prettier': 'error', // disabling some things that come with the eslint 7->8 upgrade. Will address these in a separate PR - 'jest/no-alias-methods': 0, 'react/no-unknown-property': 0, 'react/no-void-elements': 0, 'react/function-component-definition': [ diff --git a/superset-frontend/packages/superset-ui-core/src/hooks/useChangeEffect/useChangeEffect.test.ts b/superset-frontend/packages/superset-ui-core/src/hooks/useChangeEffect/useChangeEffect.test.ts index 32c984e48769b..1c1a96125b92e 100644 --- a/superset-frontend/packages/superset-ui-core/src/hooks/useChangeEffect/useChangeEffect.test.ts +++ b/superset-frontend/packages/superset-ui-core/src/hooks/useChangeEffect/useChangeEffect.test.ts @@ -24,8 +24,8 @@ test('call callback the first time with undefined and value', () => { renderHook(props => useChangeEffect(props.value, props.callback), { initialProps: { value: 'value', callback }, }); - expect(callback).toBeCalledTimes(1); - expect(callback).nthCalledWith(1, undefined, 'value'); + expect(callback).toHaveBeenCalledTimes(1); + expect(callback).toHaveBeenNthCalledWith(1, undefined, 'value'); }); test('do not call callback 2 times if the value do not change', () => { @@ -37,7 +37,7 @@ test('do not call callback 2 times if the value do not change', () => { }, ); hook.rerender({ value: 'value', callback }); - expect(callback).toBeCalledTimes(1); + expect(callback).toHaveBeenCalledTimes(1); }); test('call callback whenever the value changes', () => { @@ -49,6 +49,6 @@ test('call callback whenever the value changes', () => { }, ); hook.rerender({ value: 'value-2', callback }); - expect(callback).toBeCalledTimes(2); - expect(callback).nthCalledWith(2, 'value', 'value-2'); + expect(callback).toHaveBeenCalledTimes(2); + expect(callback).toHaveBeenNthCalledWith(2, 'value', 'value-2'); }); diff --git a/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidMount/useComponentDidMount.test.ts b/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidMount/useComponentDidMount.test.ts index 6d7d6cd71282a..7edf9e723296b 100644 --- a/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidMount/useComponentDidMount.test.ts +++ b/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidMount/useComponentDidMount.test.ts @@ -22,7 +22,7 @@ import { useComponentDidMount } from './useComponentDidMount'; test('the effect should only be executed on the first render', () => { const effect = jest.fn(); const hook = renderHook(() => useComponentDidMount(effect)); - expect(effect).toBeCalledTimes(1); + expect(effect).toHaveBeenCalledTimes(1); hook.rerender(); - expect(effect).toBeCalledTimes(1); + expect(effect).toHaveBeenCalledTimes(1); }); diff --git a/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidUpdate/useComponentDidUpdate.test.ts b/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidUpdate/useComponentDidUpdate.test.ts index a1615ec2793c0..1c191b07beae0 100644 --- a/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidUpdate/useComponentDidUpdate.test.ts +++ b/superset-frontend/packages/superset-ui-core/src/hooks/useComponentDidUpdate/useComponentDidUpdate.test.ts @@ -24,8 +24,8 @@ test('the effect should not be executed on the first render', () => { const hook = renderHook(props => useComponentDidUpdate(props.effect), { initialProps: { effect }, }); - expect(effect).toBeCalledTimes(0); + expect(effect).toHaveBeenCalledTimes(0); const changedEffect = jest.fn(); hook.rerender({ effect: changedEffect }); - expect(changedEffect).toBeCalledTimes(1); + expect(changedEffect).toHaveBeenCalledTimes(1); }); diff --git a/superset-frontend/packages/superset-ui-core/test/color/LabelsColorMapSingleton.test.ts b/superset-frontend/packages/superset-ui-core/test/color/LabelsColorMapSingleton.test.ts index b93a416e7ffaa..17efe6692f3b5 100644 --- a/superset-frontend/packages/superset-ui-core/test/color/LabelsColorMapSingleton.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/color/LabelsColorMapSingleton.test.ts @@ -192,7 +192,7 @@ describe('LabelsColorMap', () => { labelsColorMap.updateColorMap(categoricalNamespace, 'testColors'); const colorMap = labelsColorMap.getColorMap(); expect(Object.fromEntries(colorMap)).not.toEqual({}); - expect(getAnalogousColorsSpy).not.toBeCalled(); + expect(getAnalogousColorsSpy).not.toHaveBeenCalled(); }); it('should use analagous colors', () => { @@ -207,7 +207,7 @@ describe('LabelsColorMap', () => { labelsColorMap.updateColorMap(categoricalNamespace, 'testColors'); const colorMap = labelsColorMap.getColorMap(); expect(Object.fromEntries(colorMap)).not.toEqual({}); - expect(getAnalogousColorsSpy).toBeCalled(); + expect(getAnalogousColorsSpy).toHaveBeenCalled(); }); }); diff --git a/superset-frontend/packages/superset-ui-core/test/models/Registry.test.ts b/superset-frontend/packages/superset-ui-core/test/models/Registry.test.ts index 6f2067eec3129..7b3f2d1f89ebd 100644 --- a/superset-frontend/packages/superset-ui-core/test/models/Registry.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/models/Registry.test.ts @@ -396,31 +396,31 @@ describe('Registry', () => { it('calls the listener when a value is registered', () => { registry.registerValue('foo', 'bar'); - expect(listener).toBeCalledWith(['foo']); + expect(listener).toHaveBeenCalledWith(['foo']); }); it('calls the listener when a loader is registered', () => { registry.registerLoader('foo', () => 'bar'); - expect(listener).toBeCalledWith(['foo']); + expect(listener).toHaveBeenCalledWith(['foo']); }); it('calls the listener when a value is overridden', () => { registry.registerValue('foo', 'bar'); listener.mockClear(); registry.registerValue('foo', 'baz'); - expect(listener).toBeCalledWith(['foo']); + expect(listener).toHaveBeenCalledWith(['foo']); }); it('calls the listener when a value is removed', () => { registry.registerValue('foo', 'bar'); listener.mockClear(); registry.remove('foo'); - expect(listener).toBeCalledWith(['foo']); + expect(listener).toHaveBeenCalledWith(['foo']); }); it('does not call the listener when a value is not actually removed', () => { registry.remove('foo'); - expect(listener).not.toBeCalled(); + expect(listener).not.toHaveBeenCalled(); }); it('calls the listener when registry is cleared', () => { @@ -428,13 +428,13 @@ describe('Registry', () => { registry.registerLoader('fluz', () => 'baz'); listener.mockClear(); registry.clear(); - expect(listener).toBeCalledWith(['foo', 'fluz']); + expect(listener).toHaveBeenCalledWith(['foo', 'fluz']); }); it('removes listeners correctly', () => { registry.removeListener(listener); registry.registerValue('foo', 'bar'); - expect(listener).not.toBeCalled(); + expect(listener).not.toHaveBeenCalled(); }); describe('with a broken listener', () => { @@ -456,10 +456,10 @@ describe('Registry', () => { registry.addListener(lastListener); registry.registerValue('foo', 'bar'); - expect(listener).toBeCalledWith(['foo']); - expect(errorListener).toBeCalledWith(['foo']); - expect(lastListener).toBeCalledWith(['foo']); - expect(console.error).toBeCalled(); + expect(listener).toHaveBeenCalledWith(['foo']); + expect(errorListener).toHaveBeenCalledWith(['foo']); + expect(lastListener).toHaveBeenCalledWith(['foo']); + expect(console.error).toHaveBeenCalled(); }); }); }); diff --git a/superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts b/superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts index 4fe70f9188158..4918da15866c0 100644 --- a/superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/query/buildQueryContext.test.ts @@ -138,7 +138,7 @@ describe('buildQueryContext', () => { }, () => [{}], ); - expect(spyNormalizeTimeColumn).toBeCalled(); + expect(spyNormalizeTimeColumn).toHaveBeenCalled(); spyNormalizeTimeColumn.mockRestore(); }); }); diff --git a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts index af0d6f5915524..2aa78faeed267 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts @@ -80,7 +80,7 @@ describe('TranslatorSingleton', () => { expect(t('second')).toEqual('second'); resetTranslation(); expect(t('second')).toEqual('second'); - expect(console.warn).toBeCalledTimes(2); + expect(console.warn).toHaveBeenCalledTimes(2); restoreConsole(); }); }); diff --git a/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts b/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts index 9e36f541e1cd9..915fe0cc4234f 100644 --- a/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts +++ b/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts @@ -294,7 +294,7 @@ describe('comms', () => { }); port2.start(); - await expect(ours.get('someMethod')).rejects.toThrowError( + await expect(ours.get('someMethod')).rejects.toThrow( 'Unexpected response message', ); }); diff --git a/superset-frontend/src/SqlLab/components/ShareSqlLabQuery/ShareSqlLabQuery.test.tsx b/superset-frontend/src/SqlLab/components/ShareSqlLabQuery/ShareSqlLabQuery.test.tsx index a1251e8bcfa4e..b30fa4e6ff3ce 100644 --- a/superset-frontend/src/SqlLab/components/ShareSqlLabQuery/ShareSqlLabQuery.test.tsx +++ b/superset-frontend/src/SqlLab/components/ShareSqlLabQuery/ShareSqlLabQuery.test.tsx @@ -127,7 +127,7 @@ describe('ShareSqlLabQuery', () => { const storeQuerySpy = jest.spyOn(utils, 'storeQuery'); userEvent.click(button); expect(storeQuerySpy.mock.calls).toHaveLength(1); - expect(storeQuerySpy).toBeCalledWith(expected); + expect(storeQuerySpy).toHaveBeenCalledWith(expected); storeQuerySpy.mockRestore(); }); @@ -142,7 +142,7 @@ describe('ShareSqlLabQuery', () => { const storeQuerySpy = jest.spyOn(utils, 'storeQuery'); userEvent.click(button); expect(storeQuerySpy.mock.calls).toHaveLength(1); - expect(storeQuerySpy).toBeCalledWith(expected); + expect(storeQuerySpy).toHaveBeenCalledWith(expected); storeQuerySpy.mockRestore(); }); }); diff --git a/superset-frontend/src/components/CronPicker/CronPicker.test.tsx b/superset-frontend/src/components/CronPicker/CronPicker.test.tsx index 9eef6f21f459b..48203a2dc8863 100644 --- a/superset-frontend/src/components/CronPicker/CronPicker.test.tsx +++ b/superset-frontend/src/components/CronPicker/CronPicker.test.tsx @@ -28,7 +28,7 @@ test('Should send correct props to ReactCronPicker', () => { myCustomProp: 'myCustomProp', }; render(); - expect(spy).toBeCalledWith( + expect(spy).toHaveBeenCalledWith( expect.objectContaining({ className: expect.any(String), locale: expect.anything(), diff --git a/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx b/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx index aa9cac748b06f..44d0bff0e04bd 100644 --- a/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx +++ b/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx @@ -219,9 +219,9 @@ test('Refresh should work', async () => { await waitFor(() => { expect(fetchMock.calls(databaseApiRoute).length).toBe(1); expect(fetchMock.calls(schemaApiRoute).length).toBe(1); - expect(props.handleError).toBeCalledTimes(0); - expect(props.onDbChange).toBeCalledTimes(0); - expect(props.onSchemaChange).toBeCalledTimes(0); + expect(props.handleError).toHaveBeenCalledTimes(0); + expect(props.onDbChange).toHaveBeenCalledTimes(0); + expect(props.onSchemaChange).toHaveBeenCalledTimes(0); }); // click schema reload @@ -230,9 +230,9 @@ test('Refresh should work', async () => { await waitFor(() => { expect(fetchMock.calls(databaseApiRoute).length).toBe(1); expect(fetchMock.calls(schemaApiRoute).length).toBe(2); - expect(props.handleError).toBeCalledTimes(0); - expect(props.onDbChange).toBeCalledTimes(0); - expect(props.onSchemaChange).toBeCalledTimes(0); + expect(props.handleError).toHaveBeenCalledTimes(0); + expect(props.onDbChange).toHaveBeenCalledTimes(0); + expect(props.onSchemaChange).toHaveBeenCalledTimes(0); }); }); diff --git a/superset-frontend/src/components/DeleteModal/DeleteModal.test.tsx b/superset-frontend/src/components/DeleteModal/DeleteModal.test.tsx index ae966f48ed263..7e9b3c439ebba 100644 --- a/superset-frontend/src/components/DeleteModal/DeleteModal.test.tsx +++ b/superset-frontend/src/components/DeleteModal/DeleteModal.test.tsx @@ -45,8 +45,8 @@ test('Calling "onHide"', () => { }; const modal = ; render(modal); - expect(props.onHide).toBeCalledTimes(0); - expect(props.onConfirm).toBeCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(0); + expect(props.onConfirm).toHaveBeenCalledTimes(0); // type "del" in the input userEvent.type(screen.getByTestId('delete-modal-input'), 'del'); @@ -55,8 +55,8 @@ test('Calling "onHide"', () => { // close the modal expect(screen.getByText('×')).toBeVisible(); userEvent.click(screen.getByText('×')); - expect(props.onHide).toBeCalledTimes(1); - expect(props.onConfirm).toBeCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(1); + expect(props.onConfirm).toHaveBeenCalledTimes(0); // confirm input has been cleared expect(screen.getByTestId('delete-modal-input')).toHaveValue(''); @@ -71,19 +71,19 @@ test('Calling "onConfirm" only after typing "delete" in the input', () => { open: true, }; render(); - expect(props.onHide).toBeCalledTimes(0); - expect(props.onConfirm).toBeCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(0); + expect(props.onConfirm).toHaveBeenCalledTimes(0); expect(screen.getByTestId('delete-modal-input')).toBeVisible(); - expect(props.onConfirm).toBeCalledTimes(0); + expect(props.onConfirm).toHaveBeenCalledTimes(0); // do not execute "onConfirm" if you have not typed "delete" userEvent.click(screen.getByText('Delete')); - expect(props.onConfirm).toBeCalledTimes(0); + expect(props.onConfirm).toHaveBeenCalledTimes(0); // execute "onConfirm" if you have typed "delete" userEvent.type(screen.getByTestId('delete-modal-input'), 'delete'); userEvent.click(screen.getByText('Delete')); - expect(props.onConfirm).toBeCalledTimes(1); + expect(props.onConfirm).toHaveBeenCalledTimes(1); // confirm input has been cleared expect(screen.getByTestId('delete-modal-input')).toHaveValue(''); diff --git a/superset-frontend/src/components/FaveStar/FaveStar.test.tsx b/superset-frontend/src/components/FaveStar/FaveStar.test.tsx index 028edde2e4e57..9bccc4b7c9833 100644 --- a/superset-frontend/src/components/FaveStar/FaveStar.test.tsx +++ b/superset-frontend/src/components/FaveStar/FaveStar.test.tsx @@ -37,20 +37,20 @@ test('render right content', async () => { screen.getByRole('img', { name: 'favorite-selected' }), ).toBeInTheDocument(); - expect(props.saveFaveStar).toBeCalledTimes(0); + expect(props.saveFaveStar).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(props.saveFaveStar).toBeCalledTimes(1); - expect(props.saveFaveStar).toBeCalledWith(props.itemId, true); + expect(props.saveFaveStar).toHaveBeenCalledTimes(1); + expect(props.saveFaveStar).toHaveBeenCalledWith(props.itemId, true); rerender(); expect( await findByRole('img', { name: 'favorite-unselected' }), ).toBeInTheDocument(); - expect(props.saveFaveStar).toBeCalledTimes(1); + expect(props.saveFaveStar).toHaveBeenCalledTimes(1); userEvent.click(screen.getByRole('button')); - expect(props.saveFaveStar).toBeCalledTimes(2); - expect(props.saveFaveStar).toBeCalledWith(props.itemId, false); + expect(props.saveFaveStar).toHaveBeenCalledTimes(2); + expect(props.saveFaveStar).toHaveBeenCalledWith(props.itemId, false); }); test('render content on tooltip', async () => { @@ -87,9 +87,9 @@ test('Call fetchFaveStar on first render and on itemId change', async () => { expect( await findByRole('img', { name: 'favorite-unselected' }), ).toBeInTheDocument(); - expect(props.fetchFaveStar).toBeCalledTimes(1); - expect(props.fetchFaveStar).toBeCalledWith(props.itemId); + expect(props.fetchFaveStar).toHaveBeenCalledTimes(1); + expect(props.fetchFaveStar).toHaveBeenCalledWith(props.itemId); rerender(); - expect(props.fetchFaveStar).toBeCalledTimes(2); + expect(props.fetchFaveStar).toHaveBeenCalledTimes(2); }); diff --git a/superset-frontend/src/components/ListView/ListView.test.tsx b/superset-frontend/src/components/ListView/ListView.test.tsx index ad76ad8c7a6cf..dd5b6de2a3241 100644 --- a/superset-frontend/src/components/ListView/ListView.test.tsx +++ b/superset-frontend/src/components/ListView/ListView.test.tsx @@ -61,7 +61,7 @@ test('redirects to first page when page index is invalid', async () => { }); await waitFor(() => { expect(window.location.search).toEqual('?pageIndex=0'); - expect(fetchData).toBeCalledTimes(2); + expect(fetchData).toHaveBeenCalledTimes(2); expect(fetchData).toHaveBeenCalledWith( expect.objectContaining({ pageIndex: 9 }), ); diff --git a/superset-frontend/src/components/Pagination/Ellipsis.test.tsx b/superset-frontend/src/components/Pagination/Ellipsis.test.tsx index 81c7301fa9ead..1caf0ae555a82 100644 --- a/superset-frontend/src/components/Pagination/Ellipsis.test.tsx +++ b/superset-frontend/src/components/Pagination/Ellipsis.test.tsx @@ -24,15 +24,15 @@ import { Ellipsis } from './Ellipsis'; test('Ellipsis - click when the button is enabled', () => { const click = jest.fn(); render(); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(1); + expect(click).toHaveBeenCalledTimes(1); }); test('Ellipsis - click when the button is disabled', () => { const click = jest.fn(); render(); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); }); diff --git a/superset-frontend/src/components/Pagination/Item.test.tsx b/superset-frontend/src/components/Pagination/Item.test.tsx index 08622f9def6cd..096053656e0db 100644 --- a/superset-frontend/src/components/Pagination/Item.test.tsx +++ b/superset-frontend/src/components/Pagination/Item.test.tsx @@ -28,9 +28,9 @@ test('Item - click when the item is not active', () => {
, ); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(1); + expect(click).toHaveBeenCalledTimes(1); expect(screen.getByTestId('test')).toBeInTheDocument(); }); @@ -41,8 +41,8 @@ test('Item - click when the item is active', () => {
, ); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); expect(screen.getByTestId('test')).toBeInTheDocument(); }); diff --git a/superset-frontend/src/components/Pagination/Next.test.tsx b/superset-frontend/src/components/Pagination/Next.test.tsx index bf675749cdea1..b50efb2da6ff0 100644 --- a/superset-frontend/src/components/Pagination/Next.test.tsx +++ b/superset-frontend/src/components/Pagination/Next.test.tsx @@ -24,15 +24,15 @@ import { Next } from './Next'; test('Next - click when the button is enabled', () => { const click = jest.fn(); render(); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(1); + expect(click).toHaveBeenCalledTimes(1); }); test('Next - click when the button is disabled', () => { const click = jest.fn(); render(); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); }); diff --git a/superset-frontend/src/components/Pagination/Prev.test.tsx b/superset-frontend/src/components/Pagination/Prev.test.tsx index e414fa48a84e5..8339a57e6ccd1 100644 --- a/superset-frontend/src/components/Pagination/Prev.test.tsx +++ b/superset-frontend/src/components/Pagination/Prev.test.tsx @@ -24,15 +24,15 @@ import { Prev } from './Prev'; test('Prev - click when the button is enabled', () => { const click = jest.fn(); render(); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(1); + expect(click).toHaveBeenCalledTimes(1); }); test('Prev - click when the button is disabled', () => { const click = jest.fn(); render(); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button')); - expect(click).toBeCalledTimes(0); + expect(click).toHaveBeenCalledTimes(0); }); diff --git a/superset-frontend/src/dashboard/components/FiltersBadge/DetailsPanel/DetailsPanel.test.tsx b/superset-frontend/src/dashboard/components/FiltersBadge/DetailsPanel/DetailsPanel.test.tsx index 6419d9e2ad6d3..460adbd81092f 100644 --- a/superset-frontend/src/dashboard/components/FiltersBadge/DetailsPanel/DetailsPanel.test.tsx +++ b/superset-frontend/src/dashboard/components/FiltersBadge/DetailsPanel/DetailsPanel.test.tsx @@ -123,10 +123,10 @@ test('Should render "appliedCrossFilterIndicators"', async () => { screen.getByRole('button', { name: 'Clinical Stage' }), ).toBeInTheDocument(); - expect(props.onHighlightFilterSource).toBeCalledTimes(0); + expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'Clinical Stage' })); - expect(props.onHighlightFilterSource).toBeCalledTimes(1); - expect(props.onHighlightFilterSource).toBeCalledWith([ + expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(1); + expect(props.onHighlightFilterSource).toHaveBeenCalledWith([ 'ROOT_ID', 'TABS-wUKya7eQ0Z', 'TAB-BCIJF4NvgQ', @@ -153,10 +153,10 @@ test('Should render "appliedIndicators"', async () => { expect(await screen.findByText('Applied filters (1)')).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'Country' })).toBeInTheDocument(); - expect(props.onHighlightFilterSource).toBeCalledTimes(0); + expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'Country' })); - expect(props.onHighlightFilterSource).toBeCalledTimes(1); - expect(props.onHighlightFilterSource).toBeCalledWith([ + expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(1); + expect(props.onHighlightFilterSource).toHaveBeenCalledWith([ 'ROOT_ID', 'TABS-wUKya7eQ0Z', 'TAB-BCIJF4NvgQ', diff --git a/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/FilterIndicator.test.tsx b/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/FilterIndicator.test.tsx index 79340f41e72d3..563adfa8b8f69 100644 --- a/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/FilterIndicator.test.tsx +++ b/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/FilterIndicator.test.tsx @@ -51,9 +51,9 @@ test('Should call "onClick"', () => { const props = createProps(); render(); - expect(props.onClick).toBeCalledTimes(0); + expect(props.onClick).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'Vaccine Approach' })); - expect(props.onClick).toBeCalledTimes(1); + expect(props.onClick).toHaveBeenCalledTimes(1); }); test('Should render "value"', () => { diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 79f9cdf308824..4c9f7bd0139bd 100644 --- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx @@ -315,10 +315,10 @@ test('should NOT render the fave icon on anonymous user', () => { setup(anonymousUserProps); expect(() => screen.getByRole('img', { name: 'favorite-unselected' }), - ).toThrowError('Unable to find'); - expect(() => - screen.getByRole('img', { name: 'favorite-selected' }), - ).toThrowError('Unable to find'); + ).toThrow('Unable to find'); + expect(() => screen.getByRole('img', { name: 'favorite-selected' })).toThrow( + 'Unable to find', + ); }); test('should fave', async () => { diff --git a/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.jsx b/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.jsx index 297c78a2c55c2..0d8421f2522ba 100644 --- a/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.jsx +++ b/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.jsx @@ -143,7 +143,7 @@ describe.skip('PropertiesModal', () => { const spy = jest.spyOn(Modal, 'error'); expect(() => modalInstance.onColorSchemeChange('THIS_WILL_NOT_WORK'), - ).toThrowError('A valid color scheme is required'); + ).toThrow('A valid color scheme is required'); expect(spy).toHaveBeenCalled(); }); }); diff --git a/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx b/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx index 7025b94f1693c..37ad242b8d813 100644 --- a/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx +++ b/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx @@ -181,7 +181,7 @@ test('should render - FeatureFlag disabled', async () => { expect(screen.getAllByRole('textbox')).toHaveLength(4); expect(screen.getByRole('combobox')).toBeInTheDocument(); - expect(spyColorSchemeControlWrapper).toBeCalledWith( + expect(spyColorSchemeControlWrapper).toHaveBeenCalledWith( expect.objectContaining({ colorScheme: 'supersetColors' }), {}, ); @@ -222,7 +222,7 @@ test('should render - FeatureFlag enabled', async () => { expect(screen.getAllByRole('textbox')).toHaveLength(4); expect(screen.getAllByRole('combobox')).toHaveLength(3); - expect(spyColorSchemeControlWrapper).toBeCalledWith( + expect(spyColorSchemeControlWrapper).toHaveBeenCalledWith( expect.objectContaining({ colorScheme: 'supersetColors' }), {}, ); @@ -255,11 +255,11 @@ test('should close modal', async () => { await screen.findByTestId('dashboard-edit-properties-form'), ).toBeInTheDocument(); - expect(props.onHide).not.toBeCalled(); + expect(props.onHide).not.toHaveBeenCalled(); userEvent.click(screen.getByRole('button', { name: 'Cancel' })); - expect(props.onHide).toBeCalledTimes(1); + expect(props.onHide).toHaveBeenCalledTimes(1); userEvent.click(screen.getByRole('button', { name: 'Close' })); - expect(props.onHide).toBeCalledTimes(2); + expect(props.onHide).toHaveBeenCalledTimes(2); }); test('submitting with onlyApply:false', async () => { @@ -293,13 +293,13 @@ test('submitting with onlyApply:false', async () => { await screen.findByTestId('dashboard-edit-properties-form'), ).toBeInTheDocument(); - expect(props.onHide).not.toBeCalled(); - expect(props.onSubmit).not.toBeCalled(); + expect(props.onHide).not.toHaveBeenCalled(); + expect(props.onSubmit).not.toHaveBeenCalled(); userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSubmit).toBeCalledTimes(1); - expect(props.onSubmit).toBeCalledWith({ + expect(props.onSubmit).toHaveBeenCalledTimes(1); + expect(props.onSubmit).toHaveBeenCalledWith({ certificationDetails: 'Sample certification', certifiedBy: 'John Doe', colorScheme: 'supersetColors', @@ -332,12 +332,12 @@ test('submitting with onlyApply:true', async () => { await screen.findByTestId('dashboard-edit-properties-form'), ).toBeInTheDocument(); - expect(props.onHide).not.toBeCalled(); - expect(props.onSubmit).not.toBeCalled(); + expect(props.onHide).not.toHaveBeenCalled(); + expect(props.onSubmit).not.toHaveBeenCalled(); userEvent.click(screen.getByRole('button', { name: 'Apply' })); await waitFor(() => { - expect(props.onSubmit).toBeCalledTimes(1); + expect(props.onSubmit).toHaveBeenCalledTimes(1); }); }); diff --git a/superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx b/superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx index f67d3076a1022..6dc0023b0cb8e 100644 --- a/superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx +++ b/superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx @@ -444,33 +444,33 @@ test('Correct actions to "SliceHeaderControls"', () => { const props = createProps(); render(, { useRedux: true, useRouter: true }); - expect(props.toggleExpandSlice).toBeCalledTimes(0); + expect(props.toggleExpandSlice).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('toggleExpandSlice')); - expect(props.toggleExpandSlice).toBeCalledTimes(1); + expect(props.toggleExpandSlice).toHaveBeenCalledTimes(1); - expect(props.forceRefresh).toBeCalledTimes(0); + expect(props.forceRefresh).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('forceRefresh')); - expect(props.forceRefresh).toBeCalledTimes(1); + expect(props.forceRefresh).toHaveBeenCalledTimes(1); - expect(props.logExploreChart).toBeCalledTimes(0); + expect(props.logExploreChart).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('exploreChart')); - expect(props.logExploreChart).toBeCalledTimes(1); + expect(props.logExploreChart).toHaveBeenCalledTimes(1); - expect(props.exportCSV).toBeCalledTimes(0); + expect(props.exportCSV).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('exportCSV')); - expect(props.exportCSV).toBeCalledTimes(1); + expect(props.exportCSV).toHaveBeenCalledTimes(1); - expect(props.addSuccessToast).toBeCalledTimes(0); + expect(props.addSuccessToast).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('addSuccessToast')); - expect(props.addSuccessToast).toBeCalledTimes(1); + expect(props.addSuccessToast).toHaveBeenCalledTimes(1); - expect(props.addDangerToast).toBeCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('addDangerToast')); - expect(props.addDangerToast).toBeCalledTimes(1); + expect(props.addDangerToast).toHaveBeenCalledTimes(1); - expect(props.handleToggleFullSize).toBeCalledTimes(0); + expect(props.handleToggleFullSize).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('handleToggleFullSize')); - expect(props.handleToggleFullSize).toBeCalledTimes(1); + expect(props.handleToggleFullSize).toHaveBeenCalledTimes(1); }); test('Add extension to SliceHeader', () => { diff --git a/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.test.tsx b/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.test.tsx index 92a7563fc8dc8..cca28d4e45914 100644 --- a/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.test.tsx +++ b/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.test.tsx @@ -180,21 +180,21 @@ test('Should render default props', () => { test('Should "export to CSV"', async () => { const props = createProps(); renderWrapper(props); - expect(props.exportCSV).toBeCalledTimes(0); + expect(props.exportCSV).toHaveBeenCalledTimes(0); userEvent.hover(screen.getByText('Download')); userEvent.click(await screen.findByText('Export to .CSV')); - expect(props.exportCSV).toBeCalledTimes(1); - expect(props.exportCSV).toBeCalledWith(371); + expect(props.exportCSV).toHaveBeenCalledTimes(1); + expect(props.exportCSV).toHaveBeenCalledWith(371); }); test('Should "export to Excel"', async () => { const props = createProps(); renderWrapper(props); - expect(props.exportXLSX).toBeCalledTimes(0); + expect(props.exportXLSX).toHaveBeenCalledTimes(0); userEvent.hover(screen.getByText('Download')); userEvent.click(await screen.findByText('Export to Excel')); - expect(props.exportXLSX).toBeCalledTimes(1); - expect(props.exportXLSX).toBeCalledWith(371); + expect(props.exportXLSX).toHaveBeenCalledTimes(1); + expect(props.exportXLSX).toHaveBeenCalledWith(371); }); test('Export full CSV is under featureflag', async () => { @@ -214,11 +214,11 @@ test('Should "export full CSV"', async () => { }; const props = createProps('table'); renderWrapper(props); - expect(props.exportFullCSV).toBeCalledTimes(0); + expect(props.exportFullCSV).toHaveBeenCalledTimes(0); userEvent.hover(screen.getByText('Download')); userEvent.click(await screen.findByText('Export to full .CSV')); - expect(props.exportFullCSV).toBeCalledTimes(1); - expect(props.exportFullCSV).toBeCalledWith(371); + expect(props.exportFullCSV).toHaveBeenCalledTimes(1); + expect(props.exportFullCSV).toHaveBeenCalledWith(371); }); test('Should not show export full CSV if report is not table', async () => { @@ -248,11 +248,11 @@ test('Should "export full Excel"', async () => { }; const props = createProps('table'); renderWrapper(props); - expect(props.exportFullXLSX).toBeCalledTimes(0); + expect(props.exportFullXLSX).toHaveBeenCalledTimes(0); userEvent.hover(screen.getByText('Download')); userEvent.click(await screen.findByText('Export to full Excel')); - expect(props.exportFullXLSX).toBeCalledTimes(1); - expect(props.exportFullXLSX).toBeCalledWith(371); + expect(props.exportFullXLSX).toHaveBeenCalledTimes(1); + expect(props.exportFullXLSX).toHaveBeenCalledWith(371); }); test('Should not show export full Excel if report is not table', async () => { @@ -268,29 +268,29 @@ test('Should not show export full Excel if report is not table', async () => { test('Should "Show chart description"', () => { const props = createProps(); renderWrapper(props); - expect(props.toggleExpandSlice).toBeCalledTimes(0); + expect(props.toggleExpandSlice).toHaveBeenCalledTimes(0); userEvent.click(screen.getByText('Show chart description')); - expect(props.toggleExpandSlice).toBeCalledTimes(1); - expect(props.toggleExpandSlice).toBeCalledWith(371); + expect(props.toggleExpandSlice).toHaveBeenCalledTimes(1); + expect(props.toggleExpandSlice).toHaveBeenCalledWith(371); }); test('Should "Force refresh"', () => { const props = createProps(); renderWrapper(props); - expect(props.forceRefresh).toBeCalledTimes(0); + expect(props.forceRefresh).toHaveBeenCalledTimes(0); userEvent.click(screen.getByText('Force refresh')); - expect(props.forceRefresh).toBeCalledTimes(1); - expect(props.forceRefresh).toBeCalledWith(371, 26); - expect(props.addSuccessToast).toBeCalledTimes(1); + expect(props.forceRefresh).toHaveBeenCalledTimes(1); + expect(props.forceRefresh).toHaveBeenCalledWith(371, 26); + expect(props.addSuccessToast).toHaveBeenCalledTimes(1); }); test('Should "Enter fullscreen"', () => { const props = createProps(); renderWrapper(props); - expect(props.handleToggleFullSize).toBeCalledTimes(0); + expect(props.handleToggleFullSize).toHaveBeenCalledTimes(0); userEvent.click(screen.getByText('Enter fullscreen')); - expect(props.handleToggleFullSize).toBeCalledTimes(1); + expect(props.handleToggleFullSize).toHaveBeenCalledTimes(1); }); test('Drill to detail modal is under featureflag', () => { diff --git a/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx b/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx index 28802cc6072a3..5b6d9a7553847 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx @@ -116,7 +116,7 @@ test('Render tab (no content)', () => { useDnd: true, }); expect(screen.getByText('🚀 Aspiring Developers')).toBeInTheDocument(); - expect(EditableTitle).toBeCalledTimes(1); + expect(EditableTitle).toHaveBeenCalledTimes(1); expect(getByTestId('dragdroppable-object')).toBeInTheDocument(); }); @@ -129,7 +129,7 @@ test('Render tab (no content) editMode:true', () => { useDnd: true, }); expect(screen.getByText('🚀 Aspiring Developers')).toBeInTheDocument(); - expect(EditableTitle).toBeCalledTimes(1); + expect(EditableTitle).toHaveBeenCalledTimes(1); expect(getByTestId('dragdroppable-object')).toBeInTheDocument(); }); @@ -222,12 +222,12 @@ test('Edit table title', () => { useDnd: true, }); - expect(EditableTitle).toBeCalledTimes(1); + expect(EditableTitle).toHaveBeenCalledTimes(1); expect(getByTestId('dragdroppable-object')).toBeInTheDocument(); - expect(props.updateComponents).not.toBeCalled(); + expect(props.updateComponents).not.toHaveBeenCalled(); userEvent.click(screen.getByText('🚀 Aspiring Developers')); - expect(props.updateComponents).toBeCalled(); + expect(props.updateComponents).toHaveBeenCalled(); }); test('Render tab (with content)', () => { @@ -237,7 +237,7 @@ test('Render tab (with content)', () => { useRedux: true, useDnd: true, }); - expect(DashboardComponent).toBeCalledTimes(2); + expect(DashboardComponent).toHaveBeenCalledTimes(2); expect(DashboardComponent).toHaveBeenNthCalledWith( 1, expect.objectContaining({ @@ -316,7 +316,7 @@ test('Render tab (with content) editMode:true', () => { useRedux: true, useDnd: true, }); - expect(DashboardComponent).toBeCalledTimes(2); + expect(DashboardComponent).toHaveBeenCalledTimes(2); expect(DashboardComponent).toHaveBeenNthCalledWith( 1, expect.objectContaining({ @@ -369,14 +369,14 @@ test('Should call "handleDrop" and "handleTopDropTargetDrop"', () => { }, ); - expect(props.handleComponentDrop).not.toBeCalled(); + expect(props.handleComponentDrop).not.toHaveBeenCalled(); userEvent.click(getAllByTestId('MockDroppable')[0]); - expect(props.handleComponentDrop).toBeCalledTimes(1); - expect(props.onDropOnTab).not.toBeCalled(); + expect(props.handleComponentDrop).toHaveBeenCalledTimes(1); + expect(props.onDropOnTab).not.toHaveBeenCalled(); rerender(); userEvent.click(getAllByTestId('MockDroppable')[1]); - expect(props.onDropOnTab).toBeCalledTimes(1); - expect(props.handleComponentDrop).toBeCalledTimes(2); + expect(props.onDropOnTab).toHaveBeenCalledTimes(1); + expect(props.handleComponentDrop).toHaveBeenCalledTimes(2); }); test('Render tab content with no children, editMode: true, canEdit: true', () => { diff --git a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadAsImage.test.tsx b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadAsImage.test.tsx index 0242bd0091571..7e9d9226df7ab 100644 --- a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadAsImage.test.tsx +++ b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadAsImage.test.tsx @@ -47,15 +47,15 @@ test('Should call download image on click', async () => { const props = createProps(); renderComponent(); await waitFor(() => { - expect(downloadAsImage).toBeCalledTimes(0); - expect(props.addDangerToast).toBeCalledTimes(0); + expect(downloadAsImage).toHaveBeenCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); }); userEvent.click(screen.getByRole('button', { name: 'Download as Image' })); await waitFor(() => { - expect(downloadAsImage).toBeCalledTimes(1); - expect(props.addDangerToast).toBeCalledTimes(0); + expect(downloadAsImage).toHaveBeenCalledTimes(1); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); }); }); diff --git a/superset-frontend/src/dashboard/components/menu/HoverMenu.test.tsx b/superset-frontend/src/dashboard/components/menu/HoverMenu.test.tsx index b58afd12e71ed..b3c033e82d602 100644 --- a/superset-frontend/src/dashboard/components/menu/HoverMenu.test.tsx +++ b/superset-frontend/src/dashboard/components/menu/HoverMenu.test.tsx @@ -33,8 +33,8 @@ test('should call onHover when mouse enters and leaves', () => { const hoverMenu = screen.getByTestId('hover-menu'); userEvent.hover(hoverMenu); - expect(onHover).toBeCalledWith({ isHovered: true }); + expect(onHover).toHaveBeenCalledWith({ isHovered: true }); userEvent.unhover(hoverMenu); - expect(onHover).toBeCalledWith({ isHovered: false }); + expect(onHover).toHaveBeenCalledWith({ isHovered: false }); }); diff --git a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx index 6b8ad4fe2d5c5..8420847acab4d 100644 --- a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx +++ b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/ShareMenuItems.test.tsx @@ -96,20 +96,20 @@ test('Click on "Copy dashboard URL" and succeed', async () => { ); await waitFor(() => { - expect(spy).toBeCalledTimes(0); - expect(props.addSuccessToast).toBeCalledTimes(0); - expect(props.addDangerToast).toBeCalledTimes(0); + expect(spy).toHaveBeenCalledTimes(0); + expect(props.addSuccessToast).toHaveBeenCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); }); userEvent.click(screen.getByRole('button', { name: 'Copy dashboard URL' })); await waitFor(async () => { - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); const value = await spy.mock.calls[0][0](); expect(value).toBe('http://localhost/superset/dashboard/p/123/'); - expect(props.addSuccessToast).toBeCalledTimes(1); - expect(props.addSuccessToast).toBeCalledWith('Copied to clipboard!'); - expect(props.addDangerToast).toBeCalledTimes(0); + expect(props.addSuccessToast).toHaveBeenCalledTimes(1); + expect(props.addSuccessToast).toHaveBeenCalledWith('Copied to clipboard!'); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); }); }); @@ -124,20 +124,20 @@ test('Click on "Copy dashboard URL" and fail', async () => { ); await waitFor(() => { - expect(spy).toBeCalledTimes(0); - expect(props.addSuccessToast).toBeCalledTimes(0); - expect(props.addDangerToast).toBeCalledTimes(0); + expect(spy).toHaveBeenCalledTimes(0); + expect(props.addSuccessToast).toHaveBeenCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); }); userEvent.click(screen.getByRole('button', { name: 'Copy dashboard URL' })); await waitFor(async () => { - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); const value = await spy.mock.calls[0][0](); expect(value).toBe('http://localhost/superset/dashboard/p/123/'); - expect(props.addSuccessToast).toBeCalledTimes(0); - expect(props.addDangerToast).toBeCalledTimes(1); - expect(props.addDangerToast).toBeCalledWith( + expect(props.addSuccessToast).toHaveBeenCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(1); + expect(props.addDangerToast).toHaveBeenCalledWith( 'Sorry, something went wrong. Try again later.', ); }); @@ -153,7 +153,7 @@ test('Click on "Share dashboard by email" and succeed', async () => { ); await waitFor(() => { - expect(props.addDangerToast).toBeCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); expect(window.location.href).toBe(''); }); @@ -162,7 +162,7 @@ test('Click on "Share dashboard by email" and succeed', async () => { ); await waitFor(() => { - expect(props.addDangerToast).toBeCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); expect(window.location.href).toBe( 'mailto:?Subject=Superset%20dashboard%20COVID%20Vaccine%20Dashboard%20&Body=Check%20out%20this%20dashboard%3A%20http%3A%2F%2Flocalhost%2Fsuperset%2Fdashboard%2Fp%2F123%2F', ); @@ -184,7 +184,7 @@ test('Click on "Share dashboard by email" and fail', async () => { ); await waitFor(() => { - expect(props.addDangerToast).toBeCalledTimes(0); + expect(props.addDangerToast).toHaveBeenCalledTimes(0); expect(window.location.href).toBe(''); }); @@ -194,8 +194,8 @@ test('Click on "Share dashboard by email" and fail', async () => { await waitFor(() => { expect(window.location.href).toBe(''); - expect(props.addDangerToast).toBeCalledTimes(1); - expect(props.addDangerToast).toBeCalledWith( + expect(props.addDangerToast).toHaveBeenCalledTimes(1); + expect(props.addDangerToast).toHaveBeenCalledWith( 'Sorry, something went wrong. Try again later.', ); }); diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx index 1a1c6361f8ce9..163a12dc30a76 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx @@ -84,12 +84,12 @@ test('Should call "setFields" when "datasetId" changes', () => { const { rerender } = render(, { useRedux: true, }); - expect(props.form.setFields).not.toBeCalled(); + expect(props.form.setFields).not.toHaveBeenCalled(); props.datasetId = 456; rerender(); - expect(props.form.setFields).toBeCalled(); + expect(props.form.setFields).toHaveBeenCalled(); }); test('Should call "getClientErrorObject" when api returns an error', async () => { @@ -98,12 +98,12 @@ test('Should call "getClientErrorObject" when api returns an error', async () => props.datasetId = 789; const spy = jest.spyOn(uiCore, 'getClientErrorObject'); - expect(spy).not.toBeCalled(); + expect(spy).not.toHaveBeenCalled(); render(, { useRedux: true, }); await waitFor(() => { - expect(spy).toBeCalled(); + expect(spy).toHaveBeenCalled(); }); }); diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/utils.test.ts b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/utils.test.ts index 60ae8b8e5f45d..10ab8cf27f848 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/utils.test.ts +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/utils.test.ts @@ -18058,7 +18058,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in initiallyExcludedCharts, () => 'Fake title', ); - }).not.toThrowError(); + }).not.toThrow(); }); it('Avoids runtime error with invalid inputs', () => { @@ -18073,7 +18073,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in initiallyExcludedCharts, () => 'Fake title', ); - }).not.toThrowError(); + }).not.toThrow(); expect(() => { buildTree( @@ -18086,7 +18086,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in initiallyExcludedCharts, () => 'Fake title', ); - }).not.toThrowError(); + }).not.toThrow(); expect(() => { buildTree( @@ -18099,7 +18099,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in initiallyExcludedCharts, () => 'Fake title', ); - }).not.toThrowError(); + }).not.toThrow(); expect(() => { buildTree( @@ -18112,7 +18112,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in initiallyExcludedCharts, () => 'Fake title', ); - }).not.toThrowError(); + }).not.toThrow(); expect(() => { buildTree( @@ -18125,7 +18125,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in initiallyExcludedCharts, () => 'Fake title', ); - }).not.toThrowError(); + }).not.toThrow(); expect(() => { buildTree( @@ -18138,6 +18138,6 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in null, () => 'Fake title', ); - }).not.toThrowError(); + }).not.toThrow(); }); }); diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.test.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.test.tsx index 93d31990ad5f9..3d5aa374bb531 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.test.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.test.tsx @@ -159,11 +159,11 @@ test('Clicking on checkbox', () => { (getControlItems as jest.Mock).mockReturnValue(createControlItems()); const controlItemsMap = getControlItemsMap(props); renderControlItems(controlItemsMap); - expect(props.forceUpdate).not.toBeCalled(); - expect(setNativeFilterFieldValues).not.toBeCalled(); + expect(props.forceUpdate).not.toHaveBeenCalled(); + expect(setNativeFilterFieldValues).not.toHaveBeenCalled(); userEvent.click(screen.getByRole('checkbox')); - expect(setNativeFilterFieldValues).toBeCalled(); - expect(props.forceUpdate).toBeCalled(); + expect(setNativeFilterFieldValues).toHaveBeenCalled(); + expect(props.forceUpdate).toHaveBeenCalled(); }); test('Clicking on checkbox when resetConfig:false', () => { @@ -173,9 +173,9 @@ test('Clicking on checkbox when resetConfig:false', () => { ]); const controlItemsMap = getControlItemsMap(props); renderControlItems(controlItemsMap); - expect(props.forceUpdate).not.toBeCalled(); - expect(setNativeFilterFieldValues).not.toBeCalled(); + expect(props.forceUpdate).not.toHaveBeenCalled(); + expect(setNativeFilterFieldValues).not.toHaveBeenCalled(); userEvent.click(screen.getByRole('checkbox')); - expect(props.forceUpdate).toBeCalled(); - expect(setNativeFilterFieldValues).not.toBeCalled(); + expect(props.forceUpdate).toHaveBeenCalled(); + expect(setNativeFilterFieldValues).not.toHaveBeenCalled(); }); diff --git a/superset-frontend/src/dashboard/reducers/dashboardFilters.test.js b/superset-frontend/src/dashboard/reducers/dashboardFilters.test.js index a629e631937cd..a13db364cfb2f 100644 --- a/superset-frontend/src/dashboard/reducers/dashboardFilters.test.js +++ b/superset-frontend/src/dashboard/reducers/dashboardFilters.test.js @@ -131,6 +131,6 @@ describe('dashboardFilters reducer', () => { // when UPDATE_DASHBOARD_FILTERS_SCOPE is changed, applicable filters to a chart // might be changed. - expect(activeDashboardFilters.buildActiveFilters).toBeCalled(); + expect(activeDashboardFilters.buildActiveFilters).toHaveBeenCalled(); }); }); diff --git a/superset-frontend/src/explore/components/Control.test.tsx b/superset-frontend/src/explore/components/Control.test.tsx index 13fb156567045..ba08cf62da096 100644 --- a/superset-frontend/src/explore/components/Control.test.tsx +++ b/superset-frontend/src/explore/components/Control.test.tsx @@ -76,9 +76,9 @@ test('call setControlValue if isVisible is false', async () => { default: false, }), ); - expect(defaultProps.actions.setControlValue).not.toBeCalled(); + expect(defaultProps.actions.setControlValue).not.toHaveBeenCalled(); rerender(setup({ isVisible: false, default: false })); await waitFor(() => - expect(defaultProps.actions.setControlValue).toBeCalled(), + expect(defaultProps.actions.setControlValue).toHaveBeenCalled(), ); }); diff --git a/superset-frontend/src/explore/components/DataTableControl/FilterInput.test.tsx b/superset-frontend/src/explore/components/DataTableControl/FilterInput.test.tsx index 5cdb7a2a36d98..7108351be646b 100644 --- a/superset-frontend/src/explore/components/DataTableControl/FilterInput.test.tsx +++ b/superset-frontend/src/explore/components/DataTableControl/FilterInput.test.tsx @@ -30,8 +30,8 @@ test('Render a FilterInput', async () => { render(); expect(await screen.findByRole('textbox')).toBeInTheDocument(); - expect(onChangeHandler).toBeCalledTimes(0); + expect(onChangeHandler).toHaveBeenCalledTimes(0); userEvent.type(screen.getByRole('textbox'), 'test'); - expect(onChangeHandler).toBeCalledTimes(4); + expect(onChangeHandler).toHaveBeenCalledTimes(4); }); diff --git a/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanelItem.test.tsx b/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanelItem.test.tsx index 2fd4021868fe7..3ec64bf3266dd 100644 --- a/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanelItem.test.tsx +++ b/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanelItem.test.tsx @@ -124,8 +124,8 @@ test('can collapse metrics and columns', () => { { useDnd: true }, ); fireEvent.click(getByRole('button')); - expect(mockData.onCollapseMetricsChange).toBeCalled(); - expect(mockData.onCollapseColumnsChange).not.toBeCalled(); + expect(mockData.onCollapseMetricsChange).toHaveBeenCalled(); + expect(mockData.onCollapseColumnsChange).not.toHaveBeenCalled(); const startIndexOfColumnSection = mockData.metricSlice.length + 3; rerender( @@ -136,7 +136,7 @@ test('can collapse metrics and columns', () => { />, ); fireEvent.click(getByRole('button')); - expect(mockData.onCollapseColumnsChange).toBeCalled(); + expect(mockData.onCollapseColumnsChange).toHaveBeenCalled(); rerender( { render(, { useRedux: true, }); - expect(props.actions.redirectSQLLab).toBeCalledTimes(0); + expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(0); userEvent.click(screen.getByLabelText('Menu actions trigger')); userEvent.click( screen.getByRole('menuitem', { name: 'Edit chart properties' }), @@ -309,14 +309,14 @@ describe('Additional actions tests', () => { useRedux: true, }); - expect(getChartDataRequest).toBeCalledTimes(0); + expect(getChartDataRequest).toHaveBeenCalledTimes(0); userEvent.click(screen.getByLabelText('Menu actions trigger')); - expect(getChartDataRequest).toBeCalledTimes(0); + expect(getChartDataRequest).toHaveBeenCalledTimes(0); const menuItem = screen.getByText('View query').parentElement!; userEvent.click(menuItem); - await waitFor(() => expect(getChartDataRequest).toBeCalledTimes(1)); + await waitFor(() => expect(getChartDataRequest).toHaveBeenCalledTimes(1)); }); test('Should call onOpenInEditor when click on "Run in SQL Lab"', async () => { @@ -326,12 +326,12 @@ describe('Additional actions tests', () => { }); expect(await screen.findByText('Save')).toBeInTheDocument(); - expect(props.actions.redirectSQLLab).toBeCalledTimes(0); + expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(0); userEvent.click(screen.getByLabelText('Menu actions trigger')); - expect(props.actions.redirectSQLLab).toBeCalledTimes(0); + expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('menuitem', { name: 'Run in SQL Lab' })); - expect(props.actions.redirectSQLLab).toBeCalledTimes(1); + expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(1); }); describe('Download', () => { @@ -354,16 +354,16 @@ describe('Additional actions tests', () => { useRedux: true, }); - expect(spy).toBeCalledTimes(0); + expect(spy).toHaveBeenCalledTimes(0); userEvent.click(screen.getByLabelText('Menu actions trigger')); - expect(spy).toBeCalledTimes(0); + expect(spy).toHaveBeenCalledTimes(0); userEvent.hover(screen.getByText('Download')); const downloadAsImageElement = await screen.findByText('Download as image'); userEvent.click(downloadAsImageElement); - expect(spy).toBeCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(1); }); test('Should not export to CSV if canDownload=false', async () => { diff --git a/superset-frontend/src/explore/components/PropertiesModal/PropertiesModal.test.tsx b/superset-frontend/src/explore/components/PropertiesModal/PropertiesModal.test.tsx index fcdd6478d964a..a9855dc0e5813 100644 --- a/superset-frontend/src/explore/components/PropertiesModal/PropertiesModal.test.tsx +++ b/superset-frontend/src/explore/components/PropertiesModal/PropertiesModal.test.tsx @@ -171,14 +171,14 @@ test('"Close" button should call "onHide"', async () => { renderModal(props); await waitFor(() => { - expect(props.onHide).toBeCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(0); }); userEvent.click(screen.getByRole('button', { name: 'Close' })); await waitFor(() => { - expect(props.onHide).toBeCalledTimes(1); - expect(props.onSave).toBeCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(1); + expect(props.onSave).toHaveBeenCalledTimes(0); }); }); @@ -229,14 +229,14 @@ test('"Cancel" button should call "onHide"', async () => { renderModal(props); await waitFor(() => { - expect(props.onHide).toBeCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(0); }); userEvent.click(screen.getByRole('button', { name: 'Cancel' })); await waitFor(() => { - expect(props.onHide).toBeCalledTimes(1); - expect(props.onSave).toBeCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(1); + expect(props.onSave).toHaveBeenCalledTimes(0); }); }); @@ -244,16 +244,16 @@ test('"Save" button should call only "onSave"', async () => { const props = createProps(); renderModal(props); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(0); - expect(props.onHide).toBeCalledTimes(0); + expect(props.onSave).toHaveBeenCalledTimes(0); + expect(props.onHide).toHaveBeenCalledTimes(0); expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled(); }); userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(1); - expect(props.onHide).toBeCalledTimes(1); + expect(props.onSave).toHaveBeenCalledTimes(1); + expect(props.onHide).toHaveBeenCalledTimes(1); }); }); @@ -289,7 +289,7 @@ test('"Name" should not be empty', async () => { userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(0); + expect(props.onSave).toHaveBeenCalledTimes(0); }); }); @@ -307,8 +307,8 @@ test('"Name" should not be empty when saved', async () => { userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(1); - expect(props.onSave).toBeCalledWith( + expect(props.onSave).toHaveBeenCalledTimes(1); + expect(props.onSave).toHaveBeenCalledWith( expect.objectContaining({ slice_name: 'Test chart new name' }), ); }); @@ -328,8 +328,8 @@ test('"Cache timeout" should not be empty when saved', async () => { userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(1); - expect(props.onSave).toBeCalledWith( + expect(props.onSave).toHaveBeenCalledTimes(1); + expect(props.onSave).toHaveBeenCalledWith( expect.objectContaining({ cache_timeout: '1000' }), ); }); @@ -349,8 +349,8 @@ test('"Description" should not be empty when saved', async () => { userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(1); - expect(props.onSave).toBeCalledWith( + expect(props.onSave).toHaveBeenCalledTimes(1); + expect(props.onSave).toHaveBeenCalledWith( expect.objectContaining({ description: 'Test description' }), ); }); @@ -370,8 +370,8 @@ test('"Certified by" should not be empty when saved', async () => { userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(1); - expect(props.onSave).toBeCalledWith( + expect(props.onSave).toHaveBeenCalledTimes(1); + expect(props.onSave).toHaveBeenCalledWith( expect.objectContaining({ certified_by: 'Test certified by' }), ); }); @@ -393,8 +393,8 @@ test('"Certification details" should not be empty when saved', async () => { userEvent.click(screen.getByRole('button', { name: 'Save' })); await waitFor(() => { - expect(props.onSave).toBeCalledTimes(1); - expect(props.onSave).toBeCalledWith( + expect(props.onSave).toHaveBeenCalledTimes(1); + expect(props.onSave).toHaveBeenCalledWith( expect.objectContaining({ certification_details: 'Test certification details', }), diff --git a/superset-frontend/src/explore/components/controls/CollectionControl/CollectionControl.test.tsx b/superset-frontend/src/explore/components/controls/CollectionControl/CollectionControl.test.tsx index 008d97b7778ad..332cccadac49f 100644 --- a/superset-frontend/src/explore/components/controls/CollectionControl/CollectionControl.test.tsx +++ b/superset-frontend/src/explore/components/controls/CollectionControl/CollectionControl.test.tsx @@ -108,9 +108,12 @@ test('Should have add button', async () => { expect( await screen.findByRole('button', { name: 'plus-large' }), ).toBeInTheDocument(); - expect(props.onChange).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'plus-large' })); - expect(props.onChange).toBeCalledWith([{ key: 'hrYAZ5iBH' }, undefined]); + expect(props.onChange).toHaveBeenCalledWith([ + { key: 'hrYAZ5iBH' }, + undefined, + ]); }); test('Should have remove button', async () => { @@ -120,9 +123,9 @@ test('Should have remove button', async () => { expect( await screen.findByRole('button', { name: 'remove-item' }), ).toBeInTheDocument(); - expect(props.onChange).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'remove-item' })); - expect(props.onChange).toBeCalledWith([]); + expect(props.onChange).toHaveBeenCalledWith([]); }); test('Should have SortableDragger icon', async () => { @@ -136,7 +139,7 @@ test('Should call Control component', async () => { render(); expect(await screen.findByTestId('TestControl')).toBeInTheDocument(); - expect(props.onChange).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); userEvent.click(screen.getByTestId('TestControl')); - expect(props.onChange).toBeCalledWith([{ key: 'hrYAZ5iBH' }]); + expect(props.onChange).toHaveBeenCalledWith([{ key: 'hrYAZ5iBH' }]); }); diff --git a/superset-frontend/src/explore/components/controls/MetricControl/AdhocMetricEditPopover/AdhocMetricEditPopover.test.tsx b/superset-frontend/src/explore/components/controls/MetricControl/AdhocMetricEditPopover/AdhocMetricEditPopover.test.tsx index 1aa7e3acaa49e..c891c1b8ee3da 100644 --- a/superset-frontend/src/explore/components/controls/MetricControl/AdhocMetricEditPopover/AdhocMetricEditPopover.test.tsx +++ b/superset-frontend/src/explore/components/controls/MetricControl/AdhocMetricEditPopover/AdhocMetricEditPopover.test.tsx @@ -117,16 +117,16 @@ test('Should render correct elements for disallow ad-hoc metrics', () => { test('Clicking on "Close" should call onClose', () => { const props = createProps(); render(); - expect(props.onClose).toBeCalledTimes(0); + expect(props.onClose).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'Close' })); - expect(props.onClose).toBeCalledTimes(1); + expect(props.onClose).toHaveBeenCalledTimes(1); }); test('Clicking on "Save" should call onChange and onClose', async () => { const props = createProps(); render(); - expect(props.onChange).toBeCalledTimes(0); - expect(props.onClose).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); + expect(props.onClose).toHaveBeenCalledTimes(0); userEvent.click( screen.getByRole('combobox', { name: 'Select saved metrics', @@ -134,38 +134,38 @@ test('Clicking on "Save" should call onChange and onClose', async () => { ); await selectOption('sum'); userEvent.click(screen.getByRole('button', { name: 'Save' })); - expect(props.onChange).toBeCalledTimes(1); - expect(props.onClose).toBeCalledTimes(1); + expect(props.onChange).toHaveBeenCalledTimes(1); + expect(props.onClose).toHaveBeenCalledTimes(1); }); test('Clicking on "Save" should not call onChange and onClose', () => { const props = createProps(); render(); - expect(props.onChange).toBeCalledTimes(0); - expect(props.onClose).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); + expect(props.onClose).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'Save' })); - expect(props.onChange).toBeCalledTimes(0); - expect(props.onClose).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); + expect(props.onClose).toHaveBeenCalledTimes(0); }); test('Clicking on "Save" should call onChange and onClose for new metric', () => { const props = createProps(); render(); - expect(props.onChange).toBeCalledTimes(0); - expect(props.onClose).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); + expect(props.onClose).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'Save' })); - expect(props.onChange).toBeCalledTimes(1); - expect(props.onClose).toBeCalledTimes(1); + expect(props.onChange).toHaveBeenCalledTimes(1); + expect(props.onClose).toHaveBeenCalledTimes(1); }); test('Clicking on "Save" should call onChange and onClose for new title', () => { const props = createProps(); render(); - expect(props.onChange).toBeCalledTimes(0); - expect(props.onClose).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); + expect(props.onClose).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', { name: 'Save' })); - expect(props.onChange).toBeCalledTimes(1); - expect(props.onClose).toBeCalledTimes(1); + expect(props.onChange).toHaveBeenCalledTimes(1); + expect(props.onClose).toHaveBeenCalledTimes(1); }); test('Should switch to tab:Simple', () => { @@ -180,11 +180,11 @@ test('Should switch to tab:Simple', () => { screen.queryByRole('tabpanel', { name: 'Simple' }), ).not.toBeInTheDocument(); - expect(props.getCurrentTab).toBeCalledTimes(1); + expect(props.getCurrentTab).toHaveBeenCalledTimes(1); const tab = screen.getByRole('tab', { name: 'Simple' }).parentElement!; userEvent.click(tab); - expect(props.getCurrentTab).toBeCalledTimes(2); + expect(props.getCurrentTab).toHaveBeenCalledTimes(2); expect( screen.queryByRole('tabpanel', { name: 'Saved' }), @@ -218,11 +218,11 @@ test('Should switch to tab:Custom SQL', () => { screen.queryByRole('tabpanel', { name: 'Custom SQL' }), ).not.toBeInTheDocument(); - expect(props.getCurrentTab).toBeCalledTimes(1); + expect(props.getCurrentTab).toHaveBeenCalledTimes(1); const tab = screen.getByRole('tab', { name: 'Custom SQL' }).parentElement!; userEvent.click(tab); - expect(props.getCurrentTab).toBeCalledTimes(2); + expect(props.getCurrentTab).toHaveBeenCalledTimes(2); expect( screen.queryByRole('tabpanel', { name: 'Saved' }), diff --git a/superset-frontend/src/explore/components/controls/SelectAsyncControl/SelectAsyncControl.test.tsx b/superset-frontend/src/explore/components/controls/SelectAsyncControl/SelectAsyncControl.test.tsx index b1f475caf5721..46e353b4968d2 100644 --- a/superset-frontend/src/explore/components/controls/SelectAsyncControl/SelectAsyncControl.test.tsx +++ b/superset-frontend/src/explore/components/controls/SelectAsyncControl/SelectAsyncControl.test.tsx @@ -91,9 +91,9 @@ test('Should send correct props to Select component - value props', async () => test('Should send correct props to Select component - function onChange multi:true', async () => { const props = createProps(); render(, { useRedux: true }); - expect(props.onChange).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); userEvent.click(await screen.findByText('onChange')); - expect(props.onChange).toBeCalledTimes(1); + expect(props.onChange).toHaveBeenCalledTimes(1); }); test('Should send correct props to Select component - function onChange multi:false', async () => { @@ -101,7 +101,7 @@ test('Should send correct props to Select component - function onChange multi:fa render(, { useRedux: true, }); - expect(props.onChange).toBeCalledTimes(0); + expect(props.onChange).toHaveBeenCalledTimes(0); userEvent.click(await screen.findByText('onChange')); - expect(props.onChange).toBeCalledTimes(1); + expect(props.onChange).toHaveBeenCalledTimes(1); }); diff --git a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx index 7fdf59b78665d..e91e187ac0459 100644 --- a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx +++ b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx @@ -247,7 +247,7 @@ describe('VizTypeControl', () => { const visualizations = screen.getByTestId(getTestId('viz-row')); userEvent.click(within(visualizations).getByText('Bar Chart')); - expect(defaultProps.onChange).not.toBeCalled(); + expect(defaultProps.onChange).not.toHaveBeenCalled(); userEvent.dblClick(within(visualizations).getByText('Line Chart')); expect(defaultProps.onChange).toHaveBeenCalledWith( diff --git a/superset-frontend/src/explore/components/controls/withAsyncVerification.test.tsx b/superset-frontend/src/explore/components/controls/withAsyncVerification.test.tsx index 4f464361e1f31..dfb7319f65ee5 100644 --- a/superset-frontend/src/explore/components/controls/withAsyncVerification.test.tsx +++ b/superset-frontend/src/explore/components/controls/withAsyncVerification.test.tsx @@ -94,8 +94,8 @@ describe('VerifiedMetricsControl', () => { expect(wrapper.find(MetricsControl).length).toBe(1); - expect(verifier).toBeCalledTimes(1); - expect(verifier).toBeCalledWith( + expect(verifier).toHaveBeenCalledTimes(1); + expect(verifier).toHaveBeenCalledWith( expect.objectContaining({ savedMetrics: props.savedMetrics }), ); @@ -104,8 +104,8 @@ describe('VerifiedMetricsControl', () => { wrapper.setProps({ validMetric: ['abc'] }); }); - expect(verifier).toBeCalledTimes(2); - expect(verifier).toBeCalledWith( + expect(verifier).toHaveBeenCalledTimes(2); + expect(verifier).toHaveBeenCalledWith( expect.objectContaining({ validMetric: ['abc'] }), ); }); @@ -123,8 +123,8 @@ describe('VerifiedMetricsControl', () => { child.props().onChange?.(['abc']); expect(child.length).toBe(1); - expect(mockOnChange).toBeCalledTimes(1); - expect(mockOnChange).toBeCalledWith(['abc'], { + expect(mockOnChange).toHaveBeenCalledTimes(1); + expect(mockOnChange).toHaveBeenCalledWith(['abc'], { actions: defaultProps.actions, columns: defaultProps.columns, datasourceType: defaultProps.datasourceType, diff --git a/superset-frontend/src/explore/exploreUtils/exploreUtils.test.jsx b/superset-frontend/src/explore/exploreUtils/exploreUtils.test.jsx index b39468841bd1b..7e0a556d744e2 100644 --- a/superset-frontend/src/explore/exploreUtils/exploreUtils.test.jsx +++ b/superset-frontend/src/explore/exploreUtils/exploreUtils.test.jsx @@ -195,7 +195,7 @@ describe('exploreUtils', () => { const v1RequestPayload = buildV1ChartDataPayload({ formData: { ...formData, viz_type: 'my_custom_viz' }, }); - expect(v1RequestPayload).hasOwnProperty('queries'); + expect(v1RequestPayload.hasOwnProperty('queries')).toBeTruthy(); }); }); @@ -289,7 +289,7 @@ describe('exploreUtils', () => { exploreChart({ formData: { ...formData, viz_type: 'my_custom_viz' }, }); - expect(postFormSpy).toBeCalledTimes(1); + expect(postFormSpy).toHaveBeenCalledTimes(1); }); }); }); diff --git a/superset-frontend/src/explore/exploreUtils/shouldUseLegacyApi.test.ts b/superset-frontend/src/explore/exploreUtils/shouldUseLegacyApi.test.ts index adf42af3e84ca..f2e5b3157c7b9 100644 --- a/superset-frontend/src/explore/exploreUtils/shouldUseLegacyApi.test.ts +++ b/superset-frontend/src/explore/exploreUtils/shouldUseLegacyApi.test.ts @@ -23,11 +23,11 @@ test('Should return false', () => { const spy = jest.spyOn(Core, 'getChartMetadataRegistry'); const get = jest.fn(); spy.mockReturnValue({ get } as any); - expect(get).toBeCalledTimes(0); + expect(get).toHaveBeenCalledTimes(0); const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' }); expect(useLegacyApi).toBe(false); - expect(get).toBeCalledTimes(1); - expect(get).toBeCalledWith('name_test'); + expect(get).toHaveBeenCalledTimes(1); + expect(get).toHaveBeenCalledWith('name_test'); }); test('Should return true', () => { @@ -35,11 +35,11 @@ test('Should return true', () => { const get = jest.fn(); get.mockReturnValue({ useLegacyApi: true }); spy.mockReturnValue({ get } as any); - expect(get).toBeCalledTimes(0); + expect(get).toHaveBeenCalledTimes(0); const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' }); expect(useLegacyApi).toBe(true); - expect(get).toBeCalledTimes(1); - expect(get).toBeCalledWith('name_test'); + expect(get).toHaveBeenCalledTimes(1); + expect(get).toHaveBeenCalledWith('name_test'); }); test('Should return false when useLegacyApi:false', () => { @@ -47,9 +47,9 @@ test('Should return false when useLegacyApi:false', () => { const get = jest.fn(); get.mockReturnValue({ useLegacyApi: false }); spy.mockReturnValue({ get } as any); - expect(get).toBeCalledTimes(0); + expect(get).toHaveBeenCalledTimes(0); const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' }); expect(useLegacyApi).toBe(false); - expect(get).toBeCalledTimes(1); - expect(get).toBeCalledWith('name_test'); + expect(get).toHaveBeenCalledTimes(1); + expect(get).toHaveBeenCalledWith('name_test'); }); diff --git a/superset-frontend/src/utils/cacheWrapper.test.ts b/superset-frontend/src/utils/cacheWrapper.test.ts index f53d925e55d83..2d39a3b85dfd4 100644 --- a/superset-frontend/src/utils/cacheWrapper.test.ts +++ b/superset-frontend/src/utils/cacheWrapper.test.ts @@ -37,8 +37,8 @@ describe('cacheWrapper', () => { const returnedValue = wrappedFn(1, 2); expect(returnedValue).toEqual(fnResult); - expect(fn).toBeCalledTimes(1); - expect(fn).toBeCalledWith(1, 2); + expect(fn).toHaveBeenCalledTimes(1); + expect(fn).toHaveBeenCalledWith(1, 2); }); describe('subsequent calls', () => { @@ -48,14 +48,14 @@ describe('cacheWrapper', () => { expect(returnedValue1).toEqual(fnResult); expect(returnedValue2).toEqual(fnResult); - expect(fn).toBeCalledTimes(1); + expect(fn).toHaveBeenCalledTimes(1); }); it('fn is called multiple times for different arguments', () => { wrappedFn(1, 2); wrappedFn(1, 3); - expect(fn).toBeCalledTimes(2); + expect(fn).toHaveBeenCalledTimes(2); }); }); @@ -77,7 +77,7 @@ describe('cacheWrapper', () => { wrappedFn(1, 2); wrappedFn(1, 3); - expect(fn).toBeCalledTimes(1); + expect(fn).toHaveBeenCalledTimes(1); }); }); }); diff --git a/superset-websocket/spec/index.test.ts b/superset-websocket/spec/index.test.ts index 1643c9f6ac8b1..20a399d395c61 100644 --- a/superset-websocket/spec/index.test.ts +++ b/superset-websocket/spec/index.test.ts @@ -94,10 +94,10 @@ describe('server', () => { response as unknown as http.ServerResponse, ); - expect(writeHeadMock).toBeCalledTimes(1); + expect(writeHeadMock).toHaveBeenCalledTimes(1); expect(writeHeadMock).toHaveBeenLastCalledWith(200); - expect(endMock).toBeCalledTimes(1); + expect(endMock).toHaveBeenCalledTimes(1); expect(endMock).toHaveBeenLastCalledWith('OK'); }); @@ -123,10 +123,10 @@ describe('server', () => { response as unknown as http.ServerResponse, ); - expect(writeHeadMock).toBeCalledTimes(1); + expect(writeHeadMock).toHaveBeenCalledTimes(1); expect(writeHeadMock).toHaveBeenLastCalledWith(404); - expect(endMock).toBeCalledTimes(1); + expect(endMock).toHaveBeenCalledTimes(1); expect(endMock).toHaveBeenLastCalledWith('Not Found'); }); }); @@ -200,16 +200,16 @@ describe('server', () => { const sendMock = jest.spyOn(ws, 'send'); const socketInstance = { ws: ws, channel: channelId, pongTs: Date.now() }; - expect(statsdIncrementMock).toBeCalledTimes(0); + expect(statsdIncrementMock).toHaveBeenCalledTimes(0); server.trackClient(channelId, socketInstance); - expect(statsdIncrementMock).toBeCalledTimes(1); + expect(statsdIncrementMock).toHaveBeenCalledTimes(1); expect(statsdIncrementMock).toHaveBeenNthCalledWith( 1, 'ws_connected_client', ); server.processStreamResults(streamReturnValue); - expect(statsdIncrementMock).toBeCalledTimes(1); + expect(statsdIncrementMock).toHaveBeenCalledTimes(1); const message1 = `{"id":"1615426152415-0","channel_id":"${channelId}","job_id":"c9b99965-8f1e-4ce5-aa43-d6fc94d6a510","user_id":"1","status":"done","errors":[],"result_url":"/superset/explore_json/data/ejr-37281682b1282cdb8f25e0de0339b386"}`; const message2 = `{"id":"1615426152516-0","channel_id":"${channelId}","job_id":"f1e5bb1f-f2f1-4f21-9b2f-c9b91dcc9b59","user_id":"1","status":"done","errors":[],"result_url":"/api/v1/chart/data/qc-64e8452dc9907dd77746cb75a19202de"}`; @@ -221,9 +221,9 @@ describe('server', () => { const ws = new wsMock('localhost'); const sendMock = jest.spyOn(ws, 'send'); - expect(statsdIncrementMock).toBeCalledTimes(0); + expect(statsdIncrementMock).toHaveBeenCalledTimes(0); server.processStreamResults(streamReturnValue); - expect(statsdIncrementMock).toBeCalledTimes(0); + expect(statsdIncrementMock).toHaveBeenCalledTimes(0); expect(sendMock).not.toHaveBeenCalled(); }); @@ -236,16 +236,16 @@ describe('server', () => { const cleanChannelMock = jest.spyOn(server, 'cleanChannel'); const socketInstance = { ws: ws, channel: channelId, pongTs: Date.now() }; - expect(statsdIncrementMock).toBeCalledTimes(0); + expect(statsdIncrementMock).toHaveBeenCalledTimes(0); server.trackClient(channelId, socketInstance); - expect(statsdIncrementMock).toBeCalledTimes(1); + expect(statsdIncrementMock).toHaveBeenCalledTimes(1); expect(statsdIncrementMock).toHaveBeenNthCalledWith( 1, 'ws_connected_client', ); server.processStreamResults(streamReturnValue); - expect(statsdIncrementMock).toBeCalledTimes(2); + expect(statsdIncrementMock).toHaveBeenCalledTimes(2); expect(statsdIncrementMock).toHaveBeenNthCalledWith( 2, 'ws_client_send_error',