2020-08-04 02:30:37 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2020-08-20 07:32:12 +03:00
|
|
|
|
2021-05-06 17:08:22 +03:00
|
|
|
import { test as it, expect } from './pageTest';
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work for primitives', async ({ page }) => {
|
2020-08-04 02:30:37 +03:00
|
|
|
const numberHandle = await page.evaluateHandle(() => 2);
|
2021-08-06 21:37:36 +03:00
|
|
|
expect(numberHandle.toString()).toBe('2');
|
2020-08-04 02:30:37 +03:00
|
|
|
const stringHandle = await page.evaluateHandle(() => 'a');
|
2021-08-06 21:37:36 +03:00
|
|
|
expect(stringHandle.toString()).toBe('a');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2021-08-06 21:37:36 +03:00
|
|
|
it('should work for complicated objects', async ({ page, browserName }) => {
|
2020-08-04 02:30:37 +03:00
|
|
|
const aHandle = await page.evaluateHandle(() => window);
|
2021-08-06 21:37:36 +03:00
|
|
|
if (browserName !== 'firefox')
|
|
|
|
expect(aHandle.toString()).toBe('Window');
|
|
|
|
else
|
|
|
|
expect(aHandle.toString()).toBe('JSHandle@object');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2021-08-06 21:37:36 +03:00
|
|
|
it('should work for promises', async ({ page }) => {
|
2020-08-04 02:30:37 +03:00
|
|
|
// wrap the promise in an object, otherwise we will await.
|
2021-09-27 19:58:08 +03:00
|
|
|
const wrapperHandle = await page.evaluateHandle(() => ({ b: Promise.resolve(123) }));
|
2020-08-04 02:30:37 +03:00
|
|
|
const bHandle = await wrapperHandle.getProperty('b');
|
2021-08-06 21:37:36 +03:00
|
|
|
expect(bHandle.toString()).toBe('Promise');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2021-12-30 05:51:28 +03:00
|
|
|
it('should work with different subtypes #smoke', async ({ page, browserName }) => {
|
2021-08-06 21:37:36 +03:00
|
|
|
expect((await page.evaluateHandle('(function(){})')).toString()).toContain('function');
|
|
|
|
expect((await page.evaluateHandle('12')).toString()).toBe('12');
|
|
|
|
expect((await page.evaluateHandle('true')).toString()).toBe('true');
|
|
|
|
expect((await page.evaluateHandle('undefined')).toString()).toBe('undefined');
|
|
|
|
expect((await page.evaluateHandle('"foo"')).toString()).toBe('foo');
|
|
|
|
expect((await page.evaluateHandle('Symbol()')).toString()).toBe('Symbol()');
|
|
|
|
expect((await page.evaluateHandle('new Map()')).toString()).toContain('Map');
|
|
|
|
expect((await page.evaluateHandle('new Set()')).toString()).toContain('Set');
|
|
|
|
expect((await page.evaluateHandle('[]')).toString()).toContain('Array');
|
|
|
|
expect((await page.evaluateHandle('null')).toString()).toBe('null');
|
2020-08-04 02:30:37 +03:00
|
|
|
expect((await page.evaluateHandle('document.body')).toString()).toBe('JSHandle@node');
|
2021-08-06 21:37:36 +03:00
|
|
|
expect((await page.evaluateHandle('new WeakMap()')).toString()).toBe('WeakMap');
|
|
|
|
expect((await page.evaluateHandle('new WeakSet()')).toString()).toBe('WeakSet');
|
|
|
|
expect((await page.evaluateHandle('new Error()')).toString()).toContain('Error');
|
|
|
|
expect((await page.evaluateHandle('new Proxy({}, {})')).toString()).toBe('Proxy');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with previewable subtypes', async ({ page, browserName }) => {
|
|
|
|
it.skip(browserName === 'firefox');
|
|
|
|
expect((await page.evaluateHandle('/foo/')).toString()).toBe('/foo/');
|
|
|
|
expect((await page.evaluateHandle('new Date(0)')).toString()).toContain('GMT');
|
|
|
|
expect((await page.evaluateHandle('new Int32Array()')).toString()).toContain('Int32Array');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|