diff --git a/package.json b/package.json index 9e173c299..9c50f9994 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,19 @@ "coverageReporters": [ "json" ], + "collectCoverageFrom": [ + "packages/src/**/*.{ts,tsx}", + "!node_modules/**", + "!packages/**/esm/**", + "!packages/**/lib/**", + "!packages/**/node_modules/**", + "!packages/vx-demo/**", + "!packages/vx-vx/**" + ], + "testPathIgnorePatterns" : [ + "/packages/vx-demo", + "/packages/vx-vx" + ], "coverageThreshold": { "global": { "branches": 0, diff --git a/packages/vx-annotation/test/LinePathAnnotation.test.tsx b/packages/vx-annotation/test/LinePathAnnotation.test.tsx index bda70f8f6..c4b2e2850 100644 --- a/packages/vx-annotation/test/LinePathAnnotation.test.tsx +++ b/packages/vx-annotation/test/LinePathAnnotation.test.tsx @@ -65,4 +65,15 @@ describe('', () => { ), ).toBe(true); }); + + test('it should have default x and y accessors', () => { + const point = new Point({ x: 0, y: 0 }); + const points = [point]; + const wrapper = shallow(); + const linepath = wrapper.childAt(0).props(); + const x = linepath.x(point); + const y = linepath.y(point); + expect(x).toEqual(point.x); + expect(y).toEqual(point.y); + }); }); diff --git a/packages/vx-bounds/test/withBoundingRects.test.ts b/packages/vx-bounds/test/withBoundingRects.test.ts deleted file mode 100644 index 86efcead9..000000000 --- a/packages/vx-bounds/test/withBoundingRects.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { withBoundingRects } from '../src'; - -// const expectedRectShape = expect.objectContaining({ -// top: expect.any(Number), -// right: expect.any(Number), -// bottom: expect.any(Number), -// left: expect.any(Number), -// width: expect.any(Number), -// height: expect.any(Number), -// }); - -describe('withBoundingRects()', () => { - // beforeAll(() => { - // // mock getBoundingClientRect - // Element.prototype.getBoundingClientRect = jest.fn(() => ({ - // width: 100, - // height: 100, - // top: 0, - // left: 0, - // bottom: 0, - // right: 0, - // })); - // }); - - test('it should be defined', () => { - expect(withBoundingRects).toBeDefined(); - }); - - // test('it should pass rect, parentRect, and getRect props to the wrapped component', () => { - // const Component = () =>
; - // const HOC = withBoundingRects(Component); - // const wrapper = mount(); - // const RenderedComponent = wrapper.find(Component); - - // expect( - // Element.prototype.getBoundingClientRect, - // ).toHaveBeenCalled(); - // expect(RenderedComponent.prop('rect')).toEqual(expectedRectShape); - // expect(RenderedComponent.prop('parentRect')).toEqual( - // expectedRectShape, - // ); - // expect(typeof RenderedComponent.prop('getRects')).toBe( - // 'function', - // ); - // }); - - // test('it should pass additional props to the wrapped component', () => { - // const Component = () =>
; - // const HOC = withBoundingRects(Component); - // const wrapper = mount(); - // const RenderedComponent = wrapper.find(Component); - // expect(RenderedComponent.prop('bananas')).toBe('are yellow'); - // }); -}); diff --git a/packages/vx-bounds/test/withBoundingRects.test.tsx b/packages/vx-bounds/test/withBoundingRects.test.tsx new file mode 100644 index 000000000..e3695c4df --- /dev/null +++ b/packages/vx-bounds/test/withBoundingRects.test.tsx @@ -0,0 +1,80 @@ +import * as React from 'react'; +import { mount } from 'enzyme'; +import { withBoundingRects } from '../src'; + +const expectedRectShape = expect.objectContaining({ + top: expect.any(Number), + right: expect.any(Number), + bottom: expect.any(Number), + left: expect.any(Number), + width: expect.any(Number), + height: expect.any(Number), +}); + +const emptyRect = { + top: 0, + right: 0, + bottom: 0, + left: 0, + width: 0, + height: 0, +}; + +describe('withBoundingRects()', () => { + beforeAll(() => { + // mock getBoundingClientRect + Element.prototype.getBoundingClientRect = jest.fn(() => ({ + width: 100, + height: 100, + top: 0, + left: 0, + bottom: 0, + right: 0, + x: 0, + y: 0, + toJSON: jest.fn(), + })); + }); + + test('it should be defined', () => { + expect(withBoundingRects).toBeDefined(); + }); + + test('it should pass rect, parentRect, and getRect props to the wrapped component', () => { + const Component = () =>
; + const HOC = withBoundingRects(Component); + const wrapper = mount(); + const RenderedComponent = wrapper.find(Component); + + expect(Element.prototype.getBoundingClientRect).toHaveBeenCalled(); + expect(RenderedComponent.prop('rect')).toEqual(expectedRectShape); + expect(RenderedComponent.prop('parentRect')).toEqual(expectedRectShape); + expect(typeof RenderedComponent.prop('getRects')).toBe('function'); + }); + + test('it should pass additional props to the wrapped component', () => { + const Component = () =>
; + const HOC = withBoundingRects(Component); + // @ts-ignore + const wrapper = mount(); + const RenderedComponent = wrapper.find(Component); + expect(RenderedComponent.prop('bananas')).toBe('are yellow'); + }); + + test('it should return default empty state if no node', () => { + const Component = () => null; + const HOC = withBoundingRects(Component); + const wrapper = mount(); + const RenderedComponent = wrapper.find(Component); + expect(RenderedComponent.prop('rect')).toBeUndefined(); + expect(RenderedComponent.prop('parentRect')).toBeUndefined(); + }); + + test('it should set rect and parentRect to empty state if no getBoundingClient()', () => { + const Component = () => <>{''}; + const HOC = withBoundingRects(Component); + const wrapper = mount(); + const RenderedComponent = wrapper.find(Component); + expect(RenderedComponent.prop('rect')).toEqual(emptyRect); + }); +});