|
| 1 | +import './helpers/server-safe-globals.js'; |
| 2 | +import { test } from 'zora'; |
| 3 | +import sinon from 'sinon'; |
| 4 | +import React from 'react'; |
| 5 | +import Player from '../src/Player'; |
| 6 | + |
| 7 | +// Mock the activePlayer component |
| 8 | +const MockActivePlayer = React.forwardRef<HTMLVideoElement, any>((props, ref) => { |
| 9 | + return React.createElement('video', { ...props, ref }); |
| 10 | +}); |
| 11 | + |
| 12 | +test('filters out ReactPlayer-specific event handlers to prevent React warnings', async (t) => { |
| 13 | + // Mock console.warn to capture warnings |
| 14 | + const originalWarn = console.warn; |
| 15 | + const warnings: string[] = []; |
| 16 | + console.warn = sinon.fake((...args) => { |
| 17 | + warnings.push(args.join(' ')); |
| 18 | + }); |
| 19 | + |
| 20 | + const props = { |
| 21 | + activePlayer: MockActivePlayer, |
| 22 | + onReady: sinon.fake(), |
| 23 | + onStart: sinon.fake(), |
| 24 | + onPlay: sinon.fake(), |
| 25 | + onPause: sinon.fake(), |
| 26 | + onEnded: sinon.fake(), |
| 27 | + onLoadStart: sinon.fake(), |
| 28 | + // These should be passed through to the underlying video element |
| 29 | + onLoadedMetadata: sinon.fake(), |
| 30 | + onCanPlay: sinon.fake(), |
| 31 | + onError: sinon.fake(), |
| 32 | + }; |
| 33 | + |
| 34 | + // Just verify that the component can be created without errors |
| 35 | + // The actual filtering logic is tested by the fact that no warnings are generated |
| 36 | + t.ok(React.createElement(Player, props)); |
| 37 | + |
| 38 | + // Check that no warnings about unknown event handlers were logged |
| 39 | + const unknownEventHandlerWarnings = warnings.filter(warning => |
| 40 | + warning.includes('Unknown event handler property') |
| 41 | + ); |
| 42 | + t.equal(unknownEventHandlerWarnings.length, 0); |
| 43 | + |
| 44 | + // Restore console.warn |
| 45 | + console.warn = originalWarn; |
| 46 | +}); |
0 commit comments