Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix emulateMedia tests #5593

Merged
merged 1 commit into from Apr 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 28 additions & 3 deletions test/emulation.spec.js
Expand Up @@ -97,13 +97,38 @@ module.exports.addTests = function({testRunner, expect, puppeteer}) {
});
});

describe('Page.emulateMedia', function() {
it('should be an alias for Page.emulateMediaType', async({page, server}) => {
expect(page.emulateMedia).toEqual(page.emulateMediaType);
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.
*/
it_fails_ffox('should work', async({page, server}) => {
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);
await page.emulateMedia('print');
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(false);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);
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({page, server}) => {
let error = null;
await page.emulateMedia('bad').catch(e => error = e);
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).
*/
it_fails_ffox('should work', async({page, server}) => {
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);
Expand Down