Skip to content

Commit

Permalink
fix(HTMLMediaElement): mock setter for 'muted' attributes
Browse files Browse the repository at this point in the history
This is mainly an issue in test environments. React treats 'muted' as a
property and sets it after the test environment has been torn down,
resulting in console warnings [1].

Fix this by mocking the setter property to do nothing. This doesn't pose
any issue in test environments.

[1]: testing-library/react-testing-library#470
  • Loading branch information
zwliew committed Apr 1, 2021
1 parent f4fbc41 commit 3c7fe71
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions frontend/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ import { Crypto } from '@peculiar/webcrypto'
// import API mocking utilities from Mock Service Worker
import { server } from './test-utils'

// Enable API mocking before tests.
beforeAll(() => server.listen())
beforeAll(() => {
// Enable API mocking before tests.
server.listen()

// Workaround for issue with 'muted' property not being treated as a default attribute
// see: https://github.com/testing-library/react-testing-library/issues/470
Object.defineProperty(HTMLMediaElement.prototype, 'muted', {
set: jest.fn(),
})
})

// Fake timers using Jest
beforeEach(() => jest.useFakeTimers())
Expand Down

0 comments on commit 3c7fe71

Please sign in to comment.