mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(api): remove emulateMedia method (#6084)
It has been deprecated for a while. In the next breaking release let's remove it. BREAKING CHANGE: swap to `emulateMediaType` instead.
This commit is contained in:
@@ -146,55 +146,7 @@ describe('Emulation', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.emulateMedia [deprecated]', function () {
|
||||
/* emulateMedia is deprecated in favour of emulateMediaType but we
|
||||
* don't want to remove it from Puppeteer just yet. We can't check
|
||||
* that emulateMedia === emulateMediaType because when running tests
|
||||
* with COVERAGE=1 the methods get rewritten. So instead we
|
||||
* duplicate the tests for emulateMediaType and ensure they pass
|
||||
* when calling the deprecated emulateMedia method.
|
||||
*
|
||||
* If you update these tests, you should update emulateMediaType's
|
||||
* tests, and vice-versa.
|
||||
*/
|
||||
itFailsFirefox('should work', async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(
|
||||
true
|
||||
);
|
||||
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(
|
||||
false
|
||||
);
|
||||
// @ts-expect-error this method is deprecated so we don't declare it
|
||||
await page.emulateMedia('print');
|
||||
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(
|
||||
false
|
||||
);
|
||||
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);
|
||||
// @ts-expect-error this method is deprecated so we don't declare it
|
||||
await page.emulateMedia(null);
|
||||
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(
|
||||
true
|
||||
);
|
||||
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(
|
||||
false
|
||||
);
|
||||
});
|
||||
it('should throw in case of bad argument', async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
let error = null;
|
||||
// @ts-expect-error this method is deprecated so we don't declare it
|
||||
await page.emulateMedia('bad').catch((error_) => (error = error_));
|
||||
expect(error.message).toBe('Unsupported media type: bad');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.emulateMediaType', function () {
|
||||
/* NOTE! Updating these tests? Update the emulateMedia tests above
|
||||
* too (and see the big comment for why we have these duplicated).
|
||||
*/
|
||||
itFailsFirefox('should work', async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user