| 
									
										
										
										
											2020-08-03 16:30:37 -07: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-19 21:32:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-26 10:59:27 -07:00
										 |  |  | import { it, expect } from './fixtures'; | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  | it('should work for primitives', async ({page}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   const numberHandle = await page.evaluateHandle(() => 2); | 
					
						
							|  |  |  |   expect(numberHandle.toString()).toBe('JSHandle@2'); | 
					
						
							|  |  |  |   const stringHandle = await page.evaluateHandle(() => 'a'); | 
					
						
							|  |  |  |   expect(stringHandle.toString()).toBe('JSHandle@a'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  | it('should work for complicated objects', async ({page}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   const aHandle = await page.evaluateHandle(() => window); | 
					
						
							|  |  |  |   expect(aHandle.toString()).toBe('JSHandle@object'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  | it('should work for promises', async ({page}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   // wrap the promise in an object, otherwise we will await.
 | 
					
						
							|  |  |  |   const wrapperHandle = await page.evaluateHandle(() => ({b: Promise.resolve(123)})); | 
					
						
							|  |  |  |   const bHandle = await wrapperHandle.getProperty('b'); | 
					
						
							|  |  |  |   expect(bHandle.toString()).toBe('JSHandle@promise'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  | it('should work with different subtypes', async ({page, isWebKit}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   expect((await page.evaluateHandle('(function(){})')).toString()).toBe('JSHandle@function'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('12')).toString()).toBe('JSHandle@12'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('true')).toString()).toBe('JSHandle@true'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('undefined')).toString()).toBe('JSHandle@undefined'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('"foo"')).toString()).toBe('JSHandle@foo'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('Symbol()')).toString()).toBe('JSHandle@symbol'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('new Map()')).toString()).toBe('JSHandle@map'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('new Set()')).toString()).toBe('JSHandle@set'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('[]')).toString()).toBe('JSHandle@array'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('null')).toString()).toBe('JSHandle@null'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('/foo/')).toString()).toBe('JSHandle@regexp'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('document.body')).toString()).toBe('JSHandle@node'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('new Date()')).toString()).toBe('JSHandle@date'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('new WeakMap()')).toString()).toBe('JSHandle@weakmap'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('new WeakSet()')).toString()).toBe('JSHandle@weakset'); | 
					
						
							|  |  |  |   expect((await page.evaluateHandle('new Error()')).toString()).toBe('JSHandle@error'); | 
					
						
							|  |  |  |   // TODO(yurys): change subtype from array to typedarray in WebKit.
 | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  |   expect((await page.evaluateHandle('new Int32Array()')).toString()).toBe(isWebKit ? 'JSHandle@array' : 'JSHandle@typedarray'); | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   expect((await page.evaluateHandle('new Proxy({}, {})')).toString()).toBe('JSHandle@proxy'); | 
					
						
							|  |  |  | }); |