Skip to content

Commit

Permalink
Mock useLocation to fix ColumnsBlockView.test
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleybl committed Dec 20, 2022
1 parent 6c1dddf commit e153a48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ColumnsBlock/ColumnsBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getSides = (v) => {
};

const ColumnsBlockView = (props) => {
const location = useLocation() || {};
const location = useLocation();
const { gridSizes } = config.blocks.blocksConfig[COLUMNSBLOCK];
const { data = {}, gridSize = 12, gridCols = [] } = props.data;
const metadata = props.metadata || props.properties;
Expand Down
12 changes: 10 additions & 2 deletions src/ColumnsBlock/ColumnsBlockView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import ColumnsBlockView from './ColumnsBlockView';

const mockStore = configureStore();

// const blockId = '1234';

const blocks = {
'1234': {
'@type': 'columnsBlock',
Expand Down Expand Up @@ -57,6 +55,16 @@ const TextView = ({ data }) => {
return data.text;
};

jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
useLocation: () => ({
pathname: "/",
hash: "",
search: "",
state: undefined
})
}));

test('renders 2 columns', async () => {
installColumnsBlock(config);
config.blocks.blocksConfig.text = {
Expand Down

0 comments on commit e153a48

Please sign in to comment.