How to use getBrowserWindowSize method in Mocha

Best JavaScript code snippet using mocha

Run Mocha automation tests on LambdaTest cloud grid

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

init.js

Source: init.js Github

copy
1/* Set everything up
2 * ------------------------
3 * @author:    Caleb Nii Tetteh Tsuru Addy
4 * @date:      15th July, 2020 
5 * @email:     [email protected] 
6 * @twitter:   @cnttaddy
7 * @github :   https://github.com/niitettehtsuru/SpaceFlap
8 * @codepen:   https://codepen.io/niitettehtsuru/pen/vYLVLBd
9 * @license:   GNU General Public License v3.0 
10 */ 
11let 
12curve,
13backgroundColor = 0;//black
14function getBrowserWindowSize()//get the width and height of the browser window 
15{
16    let win = window,
17    doc = document,
18    offset = 20,//
19    docElem = doc.documentElement,
20    body = doc.getElementsByTagName('body')[0],
21    browserWindowWidth = win.innerWidth || docElem.clientWidth || body.clientWidth,
22    browserWindowHeight = win.innerHeight|| docElem.clientHeight|| body.clientHeight;  
23    return {width:browserWindowWidth-offset,height:browserWindowHeight-offset}; 
24} 
25function onWindowResize()//called every time the window gets resized. 
26{  
27    let browserWindowSize = getBrowserWindowSize(); 
28    resizeCanvas(browserWindowSize.width,browserWindowSize.height);  
29    curve.resize(browserWindowSize.width,browserWindowSize.height); 
30}
31//gets the height of the curve, assuming that the the window was in 
32//fullscreen mode and is now reduced to it's present dimensions
33function getMaxHeight()
34{ 
35    let maxHeight = 60; 
36    let fullScreenHeight = 644;//assumed browser window height of device  
37    let dy  = height/fullScreenHeight;//percentage change in browser window height   
38    maxHeight *= dy; 
39    return maxHeight;   
40}
41function setNewCurve()
42{
43    let browserWindowSize = getBrowserWindowSize();  
44    createCanvas(browserWindowSize.width,browserWindowSize.height);  
45    let data = 
46    {        
47        //position the curve in the center of the screen
48        xCoord: width/2,
49        yCoord: height/2,
50        //other params
51        screenWidth: width,
52        screenHeight: height,
53        maxHeight: getMaxHeight(),
54        color: 'white'
55    };
56    curve = new Curve(data);  
57}  
58function setup() 
59{
60    let browserWindowSize = getBrowserWindowSize();  
61    createCanvas(browserWindowSize.width,browserWindowSize.height);  
62    let data = 
63    {        
64        //position the curve in the center of the screen
65        xCoord: width/2,
66        yCoord: height/2,
67        //other params
68        screenWidth: width,
69        screenHeight: height, 
70        maxHeight: getMaxHeight(),
71        color: 'white'
72    };
73    curve = new Curve(data);  
74    window.addEventListener('resize',onWindowResize);
75    document.addEventListener('click',(event)=>//when canvas is clicked,
76    {    
77        setNewCurve();//start the animation all over
78    });
79    background(backgroundColor);//black 
80} 
81function draw() 
82{     
83    smooth();   
84    background(backgroundColor); 
85    curve.update();
86    curve.draw();  
87}
Full Screen

blazorSizeResizeModule.js

Source: blazorSizeResizeModule.js Github

copy
1import { ResizeListener } from './blazorSizeResize.js';
2let instance = new ResizeListener();
3export function listenForResize(dotnetRef, options) {
4    instance.listenForResize(dotnetRef, options);
5}
6export function cancelListener() {
7    instance.cancelListener();
8}
9export function matchMedia(query) {
10    return instance.matchMedia(query);
11}
12export function getBrowserWindowSize() {
13    return instance.getBrowserWindowSize();
14}
15
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 Mocha 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)