Skip to content

How to mock MediaRecorder API in Jest #10789

@joshpeng1999

Description

@joshpeng1999

Hi there, I am trying to create a web application with React and I am currently using jest to test my React app. However, there is a feature where I am using the MediaRecorder Api to record a media stream in the web application, so when I write a simple test to check if that component has rendered using jest, it fails because it tells me: "ReferenceError: MediaRecorder is not defined" in the application at
let mediaRecorder = new MediaRecorder(stream, options);.
I hear that jsdom doesn't have the mediarecorderAPI so I was trying to mock it, but I am super stuck on how to mock the MediaRecorder object or create a fake MediaRecorder object with a fake constructor that does nothing. If anyone has an idea on how to do it, please let me know 🙏

And Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions