Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 7a0e3bd

Browse files
committed
chore(test): move mockmodule_spec.js off of the control flow (#5002)
1 parent 6275ce2 commit 7a0e3bd

File tree

3 files changed

+60
-56
lines changed

3 files changed

+60
-56
lines changed

Diff for: spec/basic/mockmodule_spec.js

+56-53
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,102 @@
1-
describe('mock modules', function() {
1+
describe('mock modules', () => {
22
// A module to override the 'version' service. This function will be
33
// executed in the context of the application under test, so it may
44
// not refer to any local variables.
5-
var mockModuleA = function() {
6-
var newModule = angular.module('moduleA', []);
5+
const mockModuleA = () => {
6+
let newModule = angular.module('moduleA', []);
77
newModule.value('version', '2');
88
};
99

1010
// A second module overriding the 'version' service.
1111
// This module shows the use of a string for the load
1212
// function.
13-
var mockModuleB = `angular.module('moduleB', []).value('version', '3');`;
13+
const mockModuleB = `angular.module('moduleB', []).value('version', '3');`;
1414

1515
// A third module overriding the 'version' service. This function
1616
// references the additional arguments provided through addMockModule().
17-
var mockModuleC = function() {
17+
const mockModuleC = () => {
1818
var newModule = angular.module('moduleC', []);
1919
newModule.value('version', arguments[0] + arguments[1]);
2020
};
2121

22-
afterEach(function() {
22+
afterEach(() => {
2323
browser.clearMockModules();
2424
});
2525

26-
it('should override services via mock modules', function() {
26+
it('should override services via mock modules', async() => {
2727
browser.addMockModule('moduleA', mockModuleA);
2828

29-
browser.get('index.html');
29+
await browser.get('index.html');
3030

31-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
31+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
3232
});
3333

34-
it('should have the version of the last loaded module', function() {
34+
it('should have the version of the last loaded module', async() => {
3535
browser.addMockModule('moduleA', mockModuleA);
3636
browser.addMockModule('moduleB', mockModuleB);
3737

38-
browser.get('index.html');
38+
await browser.get('index.html');
3939

40-
expect(element(by.css('[app-version]')).getText()).toEqual('3');
40+
expect(await element(by.css('[app-version]')).getText()).toEqual('3');
4141
});
4242

43-
it('should use the latest module if two are added with the same name', function() {
43+
it('should use the latest module if two are added with the same name',
44+
async() => {
4445
browser.addMockModule('moduleA', mockModuleA);
4546

46-
var mockModuleA2 = function() {
47-
var newModule = angular.module('moduleA', []);
47+
let mockModuleA2 = () => {
48+
let newModule = angular.module('moduleA', []);
4849
newModule.value('version', '3');
4950
};
5051

5152
browser.addMockModule('moduleA', mockModuleA2);
5253

53-
browser.get('index.html');
54+
await browser.get('index.html');
5455

55-
expect(element(by.css('[app-version]')).getText()).toEqual('3');
56+
expect(await element(by.css('[app-version]')).getText()).toEqual('3');
5657
});
5758

58-
it('should have the version of the module A after deleting module B', function() {
59+
it('should have the version of the module A after deleting module B',
60+
async() => {
5961
browser.addMockModule('moduleA', mockModuleA);
6062
browser.addMockModule('moduleB', mockModuleB);
6163

6264
browser.removeMockModule('moduleB');
6365

64-
browser.get('index.html');
66+
await browser.get('index.html');
6567

66-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
68+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
6769
});
6870

69-
it('should remove duplicate mock modules', function () {
71+
it('should remove duplicate mock modules', async() => {
7072
browser.addMockModule('moduleA', mockModuleA);
7173
browser.addMockModule('moduleA', mockModuleA);
7274
browser.removeMockModule('moduleA');
7375

74-
browser.get('index.html');
76+
await browser.get('index.html');
7577

76-
expect(element(by.css('[app-version]')).getText()).toEqual('0.1');
78+
expect(await element(by.css('[app-version]')).getText()).toEqual('0.1');
7779
});
7880

79-
it('should be a noop to remove a module which does not exist', function() {
81+
it('should be a noop to remove a module which does not exist', async() => {
8082
browser.addMockModule('moduleA', mockModuleA);
8183
browser.removeMockModule('moduleB');
8284

83-
browser.get('index.html');
85+
await browser.get('index.html');
8486

85-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
87+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
8688
});
8789

88-
it('should have the version provided from parameters through Module C', function() {
90+
it('should have the version provided from parameters through Module C',
91+
async() => {
8992
browser.addMockModule('moduleC', mockModuleC, '42', 'beta');
9093

91-
browser.get('index.html');
94+
await browser.get('index.html');
9295

93-
expect(element(by.css('[app-version]')).getText()).toEqual('42beta');
96+
expect(await element(by.css('[app-version]')).getText()).toEqual('42beta');
9497
});
9598

96-
it('should retrieve a list of current mock modules', function() {
99+
it('should retrieve a list of current mock modules', () => {
97100
browser.addMockModule('moduleA', mockModuleA);
98101
browser.addMockModule('moduleC', mockModuleC, '2', 'B');
99102

@@ -103,20 +106,20 @@ describe('mock modules', function() {
103106
expect(browser.getRegisteredMockModules()[2]).toEqual(mockModuleC);
104107
});
105108

106-
it('should load mock modules after refresh', function() {
109+
it('should load mock modules after refresh', async() => {
107110
browser.addMockModule('moduleA', mockModuleA);
108111

109-
browser.get('index.html');
110-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
112+
await browser.get('index.html');
113+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
111114

112-
browser.navigate().refresh();
113-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
115+
await browser.navigate().refresh();
116+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
114117
});
115118

116119
// Back and forward do NOT work at the moment because of an issue
117120
// bootstrapping with Angular
118121
/*
119-
it('should load mock modules after navigating back and forward', function() {
122+
it('should load mock modules after navigating back and forward', () => {
120123
browser.addMockModule('moduleA', mockModuleA);
121124
122125
browser.get('index.html');
@@ -133,26 +136,26 @@ describe('mock modules', function() {
133136
});
134137
*/
135138

136-
it('should load mock modules after navigating back and forward from link', function() {
137-
browser.getCapabilities().then(function(caps) {
138-
if (caps.get('browserName') === 'safari') {
139-
// Safari can't handle navigation. Ignore this test.
140-
return;
141-
} else {
142-
browser.addMockModule('moduleA', mockModuleA);
139+
it('should load mock modules after navigating back and forward from link',
140+
async() => {
141+
const caps = await browser.getCapabilities();
142+
if (caps.get('browserName') === 'safari') {
143+
// Safari can't handle navigation. Ignore this test.
144+
return;
145+
} else {
146+
browser.addMockModule('moduleA', mockModuleA);
143147

144-
browser.get('index.html');
145-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
148+
await browser.get('index.html');
149+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
146150

147-
element(by.linkText('repeater')).click();
148-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
151+
await element(by.linkText('repeater')).click();
152+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
149153

150-
browser.navigate().back();
151-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
154+
await browser.navigate().back();
155+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
152156

153-
browser.navigate().forward();
154-
expect(element(by.css('[app-version]')).getText()).toEqual('2');
155-
}
156-
});
157+
await browser.navigate().forward();
158+
expect(await element(by.css('[app-version]')).getText()).toEqual('2');
159+
}
157160
});
158161
});

Diff for: spec/basicConf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ exports.config = {
1212
'basic/lib_spec.js',
1313
'basic/locators_spec.js'
1414
// 'basic/elements_spec.js',
15-
// 'basic/navigation_spec.js',
1615
// 'basic/handling_spec.js',
16+
// 'basic/mockmodule_spec.js',
17+
// 'basic/navigation_spec.js',
1718
],
1819

1920
// Exclude patterns are relative to this directory.

Diff for: spec/ciFullConf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ exports.config = {
1414
'basic/lib_spec.js',
1515
'basic/locators_spec.js'
1616
// 'basic/elements_spec.js',
17-
// 'basic/navigation_spec.js',
1817
// 'basic/handling_spec.js'
19-
// 'basic/elements_spec.js',
18+
// 'basic/mockmodule_spec.js',
19+
// 'basic/navigation_spec.js',
2020
],
2121

2222
// Exclude patterns are relative to this directory.

0 commit comments

Comments
 (0)