Skip to content

Commit

Permalink
fix(tests): minor fixes for unit tests; removed element from config
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa8626 committed Sep 14, 2022
1 parent 31384a5 commit 2f95c3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
27 changes: 8 additions & 19 deletions src/__tests__/media/html5.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ describe('media/html5', () => {
});
});

afterEach(() => {
jest.resetAllMocks();
});

it('can only accept video/audio tags', () => {
try {
const p = new HTML5Media(document.createElement('div') as unknown as HTMLMediaElement);
Expand Down Expand Up @@ -75,8 +79,6 @@ describe('media/html5', () => {
const loadSpy = jest.spyOn(video, 'load');
videoPlayer.load();
expect(loadSpy).toHaveBeenCalled();
loadSpy.mockReset();
loadSpy.mockRestore();
});

it('attempts to play a stalled media source for 30 seconds; after that, dispatches error', () => {
Expand All @@ -92,9 +94,6 @@ describe('media/html5', () => {
expect(clearSpy).not.toHaveBeenCalled();
jest.advanceTimersByTime(35000);
expect(clearSpy).toHaveBeenCalled();

clearSpy.mockReset();
clearSpy.mockRestore();
});

it('detects when DVR media is being set (mobile devices setting HLS source)', () => {
Expand All @@ -115,9 +114,6 @@ describe('media/html5', () => {
videoPlayer.element.dispatchEvent(addEvent('loadeddata'));
expect(seekableSpy).toHaveBeenCalled();
expect(video.getAttribute('op-dvr__enabled')).toEqual('true');

seekableSpy.mockReset();
seekableSpy.mockRestore();
});

it.skip('reads ID3 tags from streaming (mobile devices setting HLS source)', () => {
Expand All @@ -141,20 +137,16 @@ describe('media/html5', () => {
video.textTracks[1].dispatchEvent(addEvent('cuechange'));
expect(addTrackSpy).toHaveBeenCalledTimes(2);
expect(dispatchSpy.mock.calls[0][0]).toEqual('metadataready');

addTrackSpy.mockReset();
addTrackSpy.mockRestore();
dispatchSpy.mockReset();
dispatchSpy.mockRestore();
});

it('dispatches different errors', () => {
const video = document.createElement('video') as HTMLMediaElement;
videoPlayer = new HTML5Media(video);
const errorSpy = jest.spyOn(video, 'dispatchEvent');

videoPlayer.src = { src: 'https://example.com/blahblah.mp4', type: 'video/mp4' };
videoPlayer.element.onerror = (): void => {
console.error(`Error with media: ${videoPlayer.element?.error?.code}`);
};
video.dispatchEvent(addEvent('error'));
expect(errorSpy.mock.calls[1][0].type).toEqual('playererror');
});

it('can destroy all events associated with it when calling `destroy`', () => {
Expand All @@ -173,8 +165,5 @@ describe('media/html5', () => {
expect(removeEventListenerSpy.mock.calls[1][0]).toEqual('stalled');
expect(removeEventListenerSpy.mock.calls[2][0]).toEqual('error');
expect(removeEventListenerSpy.mock.calls[3][0]).toEqual('loadeddata');

removeEventListenerSpy.mockReset();
removeEventListenerSpy.mockRestore();
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
},
"files": ["./global.d.ts"],
"include": ["./src/**/*.ts"],
"exclude": ["node_modules", "ts-dist", "dist", "src/__tests__", "webpack.config.js"]
"exclude": ["node_modules", "ts-dist", "dist", "webpack.config.js"]
}

0 comments on commit 2f95c3d

Please sign in to comment.