|
1 | 1 | import React, { useCallback } from 'react'; |
2 | | -import { render } from '@testing-library/react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
3 | 3 | import { useInView } from '../useInView'; |
4 | 4 | import { intersectionMockInstance, mockAllIsIntersecting } from '../test-utils'; |
5 | 5 | import { IntersectionOptions } from '../index'; |
@@ -257,3 +257,25 @@ test('should handle multiple hooks on the same element', () => { |
257 | 257 | expect(getByTestId('item-2').getAttribute('data-inview')).toBe('true'); |
258 | 258 | expect(getByTestId('item-3').getAttribute('data-inview')).toBe('true'); |
259 | 259 | }); |
| 260 | + |
| 261 | +test('should handle thresholds missing on observer instance', () => { |
| 262 | + render(<HookComponent options={{ threshold: [0.1, 1] }} />); |
| 263 | + const wrapper = screen.getByTestId('wrapper'); |
| 264 | + const instance = intersectionMockInstance(wrapper); |
| 265 | + // @ts-ignore |
| 266 | + instance.thresholds = undefined; |
| 267 | + mockAllIsIntersecting(true); |
| 268 | + |
| 269 | + screen.getByText('true'); |
| 270 | +}); |
| 271 | + |
| 272 | +test('should handle thresholds missing on observer instance with no threshold set', () => { |
| 273 | + render(<HookComponent />); |
| 274 | + const wrapper = screen.getByTestId('wrapper'); |
| 275 | + const instance = intersectionMockInstance(wrapper); |
| 276 | + // @ts-ignore |
| 277 | + instance.thresholds = undefined; |
| 278 | + mockAllIsIntersecting(true); |
| 279 | + |
| 280 | + screen.getByText('true'); |
| 281 | +}); |
0 commit comments