-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: increase code coverage #784
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9a2e450
chore: ignore vx-demo, vx-vx code coverage
hshoff 89b4a01
test(vx-annotation): 100% coverage
hshoff a778369
test(vx-bounds): 100% coverage
hshoff 529c3de
test(vx-bounds): remove unused import
hshoff 5878124
test(vx-bounds): fix lint
hshoff e0597bc
chore(jest): fix collectCoverageFrom
hshoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = () => <div />; | ||
const HOC = withBoundingRects(Component); | ||
const wrapper = mount(<HOC />); | ||
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 = () => <div />; | ||
const HOC = withBoundingRects(Component); | ||
// @ts-ignore | ||
const wrapper = mount(<HOC bananas="are yellow" />); | ||
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(<HOC />); | ||
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(<HOC />); | ||
const RenderedComponent = wrapper.find(Component); | ||
expect(RenderedComponent.prop('rect')).toEqual(emptyRect); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 wasn't sure how to mock the RenderComponent.node.parentNode to not have |
||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use
it(...)
function instead oftest(...)
too so it will read more likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, i don't have a preference