How to use getAngularVersion method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

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

preparePage.js

Source: preparePage.js Github

copy
1var getAngularVersion = require('../helpers/getAngularVersion')();
2
3module.exports = function(testName) {
4    return function(done) {
5        getAngularVersion.then(function(version) {
6            browser.get([testName, version].join('/'));
7            element(by.id('ngInspectorToggle')).click().then(done);
8        });
9    };
10};
11
Full Screen

root.component.js

Source: root.component.js Github

copy
1import { getAngularVersion } from "@net-piworks/angular-app-parcel";
2import { getAngularjsVersion } from "@net-piworks/angularjs-app";
3
4export default function Root(props) {
5  return (
6    <section>
7      <a href="angular2">Angular app {getAngularVersion()}</a> |{" "}
8      <a href="angularjs">Angular.js app {getAngularjsVersion()}</a>
9    </section>
10  );
11}
12
Full Screen

webapp-html-index-generator.test.js

Source: webapp-html-index-generator.test.js Github

copy
1const fs = require('fs');
2const path = require('path');
3const pkg = require('../../../package.json');
4const { fileService } = require('./file');
5const webappHtmlIndexGenerator = require('./webapp-html-index-generator');
6const webappHtmlIndexCustomisation = require('./webapp-html-index-customisation');
7const indexTemplate = fs.readFileSync(path.join(__dirname, '../../webapp/index-template.html'), 'utf-8');
8
9describe('Webapp HTML Index Generator', () => {
10  function mockConfig(){
11    return {
12      projects: [{engine: 'angular'}],
13      styles: ['https://some.lib.com/from/cdn.min.css', './dist/css/main.css'],
14      scripts: ['https://some.lib.com/from/cdn.min.js', 'dist/scripts/main.js']
15    };
16  }
17
18  function getAngularVersion(){
19    return pkg.devDependencies.angular.replace('^','');
20  }
21
22  beforeEach(() => {
23    fileService.readSync = jest.fn(() => indexTemplate);
24    fileService.write = jest.fn();
25    webappHtmlIndexCustomisation.init = jest.fn(param => param);
26    Date.now = jest.fn(() => 123);
27  });
28
29  it('should save a file named index.html', () => {
30    webappHtmlIndexGenerator.init(mockConfig());
31    expect(fileService.write.mock.calls[0][0]).toEqual(path.join(__dirname, '../../webapp/index.html'));
32  });
33
34  it('should include external assets on template', () => {
35    webappHtmlIndexGenerator.init(mockConfig());
36    expect(fileService.write.mock.calls[0][1]).toEqual(`<!DOCTYPE html>
37<html>
38  <head>
39    <meta charset="utf-8">
40    <title>{{ title }}</title>
41    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=yes">
42    <meta http-equiv="cache-control" content="no-cache">
43    <meta http-equiv="cache-control" content="max-age=0">
44    <meta http-equiv="expires" content="0">
45    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
46    <meta http-equiv="pragma" content="no-cache">
47    <link href="{{ faviconHref }}" rel="shortcut icon">
48    <link href="https://some.lib.com/from/cdn.min.css?t=123" rel="stylesheet">
49<link href="external/dist/css/main.css?t=123" rel="stylesheet">
50    <!-- inject:custom-styles -->
51  </head>
52  <body ng-app="pitsby-app">
53    <ui-view></ui-view>
54    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/${getAngularVersion()}/angular.js"></script>
55    <script src="https://some.lib.com/from/cdn.min.js?t=123"></script>
56<script src="external/dist/scripts/main.js?t=123"></script>
57  </body>
58</html>
59`);
60  });
61
62  it('should not include any external assets if no assets have been given', () => {
63    webappHtmlIndexGenerator.init();
64    expect(fileService.write.mock.calls[0][1]).toEqual(`<!DOCTYPE html>
65<html>
66  <head>
67    <meta charset="utf-8">
68    <title>{{ title }}</title>
69    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=yes">
70    <meta http-equiv="cache-control" content="no-cache">
71    <meta http-equiv="cache-control" content="max-age=0">
72    <meta http-equiv="expires" content="0">
73    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
74    <meta http-equiv="pragma" content="no-cache">
75    <link href="{{ faviconHref }}" rel="shortcut icon">
76
77    <!-- inject:custom-styles -->
78  </head>
79  <body ng-app="pitsby-app">
80    <ui-view></ui-view>
81    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/${getAngularVersion()}/angular.js"></script>
82
83  </body>
84</html>
85`);
86  });
87
88  it('should include Vue script tag if a vue project has been given', () => {
89    const config = mockConfig();
90    config.projects.push({engine: 'vue'});
91    webappHtmlIndexGenerator.init({ projects: config.projects });
92    expect(fileService.write.mock.calls[0][1]).toEqual(`<!DOCTYPE html>
93<html>
94  <head>
95    <meta charset="utf-8">
96    <title>{{ title }}</title>
97    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=yes">
98    <meta http-equiv="cache-control" content="no-cache">
99    <meta http-equiv="cache-control" content="max-age=0">
100    <meta http-equiv="expires" content="0">
101    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
102    <meta http-equiv="pragma" content="no-cache">
103    <link href="{{ faviconHref }}" rel="shortcut icon">
104
105    <!-- inject:custom-styles -->
106  </head>
107  <body ng-app="pitsby-app">
108    <ui-view></ui-view>
109    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/${getAngularVersion()}/angular.js"></script>
110    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
111  </body>
112</html>
113`);
114  });
115
116  it('should use Vue version 2.5.13 if no custom version has been given', () => {
117    const config = mockConfig();
118    config.projects.push({engine: 'vue'});
119    webappHtmlIndexGenerator.init({ projects: config.projects });
120    expect(fileService.write.mock.calls[0][1]).toEqual(`<!DOCTYPE html>
121<html>
122  <head>
123    <meta charset="utf-8">
124    <title>{{ title }}</title>
125    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=yes">
126    <meta http-equiv="cache-control" content="no-cache">
127    <meta http-equiv="cache-control" content="max-age=0">
128    <meta http-equiv="expires" content="0">
129    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
130    <meta http-equiv="pragma" content="no-cache">
131    <link href="{{ faviconHref }}" rel="shortcut icon">
132
133    <!-- inject:custom-styles -->
134  </head>
135  <body ng-app="pitsby-app">
136    <ui-view></ui-view>
137    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/${getAngularVersion()}/angular.js"></script>
138    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
139  </body>
140</html>
141`);
142  });
143
144  it('should use custom Vue version if custom version has been given', () => {
145    const config = mockConfig();
146    config.projects.push({engine: 'vue', version: '2.6.0'});
147    webappHtmlIndexGenerator.init({ projects: config.projects });
148    expect(fileService.write.mock.calls[0][1]).toEqual(`<!DOCTYPE html>
149<html>
150  <head>
151    <meta charset="utf-8">
152    <title>{{ title }}</title>
153    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=yes">
154    <meta http-equiv="cache-control" content="no-cache">
155    <meta http-equiv="cache-control" content="max-age=0">
156    <meta http-equiv="expires" content="0">
157    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
158    <meta http-equiv="pragma" content="no-cache">
159    <link href="{{ faviconHref }}" rel="shortcut icon">
160
161    <!-- inject:custom-styles -->
162  </head>
163  <body ng-app="pitsby-app">
164    <ui-view></ui-view>
165    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/${getAngularVersion()}/angular.js"></script>
166    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.0/vue.js"></script>
167  </body>
168</html>
169`);
170  });
171
172  it('should use React version 16.13.0 if no custom version has been given', () => {
173    webappHtmlIndexGenerator.init({ projects: [{engine: 'react'}] });
174    expect(fileService.write.mock.calls[0][1]).toEqual(`<!DOCTYPE html>
175<html>
176  <head>
177    <meta charset="utf-8">
178    <title>{{ title }}</title>
179    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=yes">
180    <meta http-equiv="cache-control" content="no-cache">
181    <meta http-equiv="cache-control" content="max-age=0">
182    <meta http-equiv="expires" content="0">
183    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
184    <meta http-equiv="pragma" content="no-cache">
185    <link href="{{ faviconHref }}" rel="shortcut icon">
186
187    <!-- inject:custom-styles -->
188  </head>
189  <body ng-app="pitsby-app">
190    <ui-view></ui-view>
191    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/${getAngularVersion()}/angular.js"></script>
192    <script crossorigin src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
193<script crossorigin src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
194  </body>
195</html>
196`);
197  });
198
199  it('should use custom React version if custom version has been given', () => {
200    webappHtmlIndexGenerator.init({ projects: [{engine: 'react', version: '16.8.0'}] });
201    expect(fileService.write.mock.calls[0][1]).toEqual(`<!DOCTYPE html>
202<html>
203  <head>
204    <meta charset="utf-8">
205    <title>{{ title }}</title>
206    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=yes">
207    <meta http-equiv="cache-control" content="no-cache">
208    <meta http-equiv="cache-control" content="max-age=0">
209    <meta http-equiv="expires" content="0">
210    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
211    <meta http-equiv="pragma" content="no-cache">
212    <link href="{{ faviconHref }}" rel="shortcut icon">
213
214    <!-- inject:custom-styles -->
215  </head>
216  <body ng-app="pitsby-app">
217    <ui-view></ui-view>
218    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/${getAngularVersion()}/angular.js"></script>
219    <script crossorigin src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
220<script crossorigin src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
221  </body>
222</html>
223`);
224  });
225
226  it('should handle customisation', () => {
227    const config = mockConfig();
228    config.custom = { windowTitle: 'Taslonic' };
229    webappHtmlIndexGenerator.init(config);
230    expect(typeof webappHtmlIndexCustomisation.init.mock.calls[0][0]).toEqual('string');
231    expect(webappHtmlIndexCustomisation.init.mock.calls[0][1]).toEqual({ windowTitle: 'Taslonic' });
232  });
233
234  it('should reject promise on write file error', () => {
235    const config = mockConfig();
236    const errorMock = 'some error';
237    fileService.write = jest.fn((filename, data, onSuccess, onError) => onError(errorMock));
238    webappHtmlIndexGenerator.init(config).then(() => {}, err => {
239      expect(err).toEqual(errorMock);
240    });
241  });
242});
243
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 Cypress 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)