@lightningjs/ui-components-test-utils
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "@lightningjs/ui-components-test-utils", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Helpful Jest unit test utilities for LightningJS applications utilizing the Lightning-UI-Components package.", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
"devDependencies": { | ||
"@lightningjs/ui-components-theme-base": "^1.0.1", | ||
"@lightningjs/ui-components-theme-base": "^1.0.2", | ||
"jest": "^29.3.1", | ||
@@ -29,3 +29,3 @@ "jest-environment-jsdom": "^29.3.1", | ||
"dependencies": { | ||
"@lightningjs/ui-components": "^2.3.0" | ||
"@lightningjs/ui-components": "^2.5.0" | ||
}, | ||
@@ -32,0 +32,0 @@ "publishConfig": { |
@@ -21,3 +21,3 @@ /** | ||
import { updateManager, context } from '@lightningjs/ui-components'; | ||
import jest from 'jest-mock'; | ||
import { jest } from '@jest/globals'; | ||
import BaseTheme from '@lightningjs/ui-components-theme-base'; | ||
@@ -216,6 +216,11 @@ | ||
// output a different value of certain properties in the list array if matched | ||
if (getBoolean.test(key)) { | ||
// contains !! --> output value as boolean of if is truthy/falsey | ||
key = key.substring(2, key.length); | ||
props[key] = !!element[key]; | ||
} else if (isFunction.test(key)) { | ||
// contains () | ||
// if that function exists on the element, invoke it and output the return value | ||
// else omit that key from the output | ||
key = key.substring(0, key.length - 2); | ||
@@ -226,2 +231,3 @@ if (typeof element[key] === 'function') { | ||
} else { | ||
// doesn't match either Regex --> output the actual value of that property on the element | ||
props[key] = element[key]; | ||
@@ -228,0 +234,0 @@ } |
@@ -21,6 +21,57 @@ /** | ||
// Helper function to extract the width and height dimensions from a src string | ||
const extractWidthHeight = src => { | ||
const dimensions = src.split('_')[1]; | ||
return { | ||
width: dimensions.split('x')[0], | ||
height: dimensions.split('x')[1] | ||
}; | ||
}; | ||
export default class LightningUIEnvironment extends JSDOMEnvironment { | ||
async setup() { | ||
super.setup(); | ||
// remove unnecessary console.error messages from image retrieval errors/broken images | ||
if (process.env.CI) { | ||
this.global.console = { | ||
...this.global.console, | ||
error: () => {} | ||
}; | ||
} | ||
// Mock up apis that are not supported in jsdom | ||
this.global.Image = class extends this.global.window.Image { | ||
constructor(width, height) { | ||
super(width, height); | ||
// mocking this reset function to fix the issue where tests were claiming this was not a function | ||
this.removeAttribute = () => { | ||
if (this.src) { | ||
this.src = null; | ||
} | ||
}; | ||
setTimeout(() => { | ||
if (this.src) { | ||
// checking for error first as that seems to be the case in WebPlatform | ||
if ( | ||
typeof this.onerror === 'function' && | ||
(this.src.endsWith('brokenImage') || this.src.endsWith('Error')) | ||
) { | ||
this.onerror(); | ||
} else if ( | ||
typeof this.onload === 'function' && | ||
!this.src.endsWith('Error') | ||
) { | ||
if (this.src.includes('_') && this.src.includes('x')) { | ||
const { width, height } = extractWidthHeight(this.src); | ||
this.width = width; | ||
this.height = height; | ||
} | ||
this.onload(); | ||
} | ||
} | ||
}, 500); | ||
} | ||
}; | ||
this.global.window.FontFace = function () { | ||
@@ -27,0 +78,0 @@ this.load = () => Promise.resolve(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59417
17
745
3