catalog-graph: move SVG mocks to test setup

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-04-06 10:30:11 +02:00
parent efe33862b4
commit cb9a5677d5
5 changed files with 14 additions and 36 deletions
@@ -39,13 +39,6 @@ describe('<CatalogGraphCard/>', () => {
let catalog: jest.Mocked<CatalogApi>;
let apis: TestApiRegistry;
beforeAll(() => {
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
value: () => ({ width: 100, height: 100 }),
configurable: true,
});
});
beforeEach(() => {
entity = {
apiVersion: 'a',
@@ -40,21 +40,6 @@ describe('<CatalogGraphPage/>', () => {
let wrapper: JSX.Element;
let catalog: jest.Mocked<CatalogApi>;
beforeAll(() => {
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
value: () => ({ width: 100, height: 100 }),
configurable: true,
});
Object.defineProperty(window.SVGElement.prototype, 'viewBox', {
value: { baseVal: { x: 0, y: 0, width: 100, height: 100 } },
configurable: true,
});
Object.defineProperty(window.MouseEvent.prototype, 'view', {
value: window,
configurable: true,
});
});
beforeEach(() => {
const entityC = {
apiVersion: 'a',
@@ -19,13 +19,6 @@ import { CustomNode } from './CustomNode';
import userEvent from '@testing-library/user-event';
describe('<CustomNode />', () => {
beforeAll(() => {
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
value: () => ({ width: 100, height: 100 }),
configurable: true,
});
});
test('renders node', async () => {
const { getByText } = await renderInTestApp(
<svg xmlns="http://www.w3.org/2000/svg">
@@ -33,13 +33,6 @@ describe('<EntityRelationsGraph/>', () => {
let catalog: jest.Mocked<CatalogApi>;
const CUSTOM_TEST_ID = 'custom-test-id';
beforeAll(() => {
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
value: () => ({ width: 100, height: 100 }),
configurable: true,
});
});
beforeEach(() => {
const entities: { [ref: string]: Entity } = {
'b:d/c': {
+14
View File
@@ -14,3 +14,17 @@
* limitations under the License.
*/
import '@testing-library/jest-dom';
// Common mocks needed for SVG and D3 rendering
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
value: () => ({ width: 100, height: 100 }),
configurable: true,
});
Object.defineProperty(window.SVGElement.prototype, 'viewBox', {
value: { baseVal: { x: 0, y: 0, width: 100, height: 100 } },
configurable: true,
});
Object.defineProperty(window.MouseEvent.prototype, 'view', {
value: window,
configurable: true,
});