How to use stringifyClass method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

class.js

Source: class.js Github

copy
1/* @flow */
2
3import { isDef, isObject } from 'shared/util'
4
5export function genClassForVnode (vnode: VNodeWithData): string {
6  let data = vnode.data
7  let parentNode = vnode
8  let childNode = vnode
9  while (isDef(childNode.componentInstance)) {
10    childNode = childNode.componentInstance._vnode
11    if (childNode && childNode.data) {
12      data = mergeClassData(childNode.data, data)
13    }
14  }
15  while (isDef(parentNode = parentNode.parent)) {
16    if (parentNode && parentNode.data) {
17      data = mergeClassData(data, parentNode.data)
18    }
19  }
20  return renderClass(data.staticClass, data.class)
21}
22
23function mergeClassData (child: VNodeData, parent: VNodeData): {
24  staticClass: string,
25  class: any
26} {
27  return {
28    staticClass: concat(child.staticClass, parent.staticClass),
29    class: isDef(child.class)
30      ? [child.class, parent.class]
31      : parent.class
32  }
33}
34
35export function renderClass (
36  staticClass: ?string,
37  dynamicClass: any
38): string {
39  if (isDef(staticClass) || isDef(dynamicClass)) {
40    return concat(staticClass, stringifyClass(dynamicClass))
41  }
42  /* istanbul ignore next */
43  return ''
44}
45
46export function concat (a: ?string, b: ?string): string {
47  return a ? b ? (a + ' ' + b) : a : (b || '')
48}
49
50export function stringifyClass (value: any): string {
51  if (Array.isArray(value)) {
52    return stringifyArray(value)
53  }
54  if (isObject(value)) {
55    return stringifyObject(value)
56  }
57  if (typeof value === 'string') {
58    return value
59  }
60  /* istanbul ignore next */
61  return ''
62}
63
64function stringifyArray (value: Array<any>): string {
65  let res = ''
66  let stringified
67  for (let i = 0, l = value.length; i < l; i++) {
68    if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') {
69      if (res) res += ' '
70      res += stringified
71    }
72  }
73  return res
74}
75
76function stringifyObject (value: Object): string {
77  let res = ''
78  for (const key in value) {
79    if (value[key]) {
80      if (res) res += ' '
81      res += key
82    }
83  }
84  return res
85}
86
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)