1
- describe ( 'mock modules' , function ( ) {
1
+ describe ( 'mock modules' , ( ) => {
2
2
// A module to override the 'version' service. This function will be
3
3
// executed in the context of the application under test, so it may
4
4
// 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' , [ ] ) ;
7
7
newModule . value ( 'version' , '2' ) ;
8
8
} ;
9
9
10
10
// A second module overriding the 'version' service.
11
11
// This module shows the use of a string for the load
12
12
// function.
13
- var mockModuleB = `angular.module('moduleB', []).value('version', '3');` ;
13
+ const mockModuleB = `angular.module('moduleB', []).value('version', '3');` ;
14
14
15
15
// A third module overriding the 'version' service. This function
16
16
// references the additional arguments provided through addMockModule().
17
- var mockModuleC = function ( ) {
17
+ const mockModuleC = ( ) => {
18
18
var newModule = angular . module ( 'moduleC' , [ ] ) ;
19
19
newModule . value ( 'version' , arguments [ 0 ] + arguments [ 1 ] ) ;
20
20
} ;
21
21
22
- afterEach ( function ( ) {
22
+ afterEach ( ( ) => {
23
23
browser . clearMockModules ( ) ;
24
24
} ) ;
25
25
26
- it ( 'should override services via mock modules' , function ( ) {
26
+ it ( 'should override services via mock modules' , async ( ) => {
27
27
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
28
28
29
- browser . get ( 'index.html' ) ;
29
+ await browser . get ( 'index.html' ) ;
30
30
31
- expect ( element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '2' ) ;
31
+ expect ( await element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '2' ) ;
32
32
} ) ;
33
33
34
- it ( 'should have the version of the last loaded module' , function ( ) {
34
+ it ( 'should have the version of the last loaded module' , async ( ) => {
35
35
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
36
36
browser . addMockModule ( 'moduleB' , mockModuleB ) ;
37
37
38
- browser . get ( 'index.html' ) ;
38
+ await browser . get ( 'index.html' ) ;
39
39
40
- expect ( element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '3' ) ;
40
+ expect ( await element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '3' ) ;
41
41
} ) ;
42
42
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 ( ) => {
44
45
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
45
46
46
- var mockModuleA2 = function ( ) {
47
- var newModule = angular . module ( 'moduleA' , [ ] ) ;
47
+ let mockModuleA2 = ( ) => {
48
+ let newModule = angular . module ( 'moduleA' , [ ] ) ;
48
49
newModule . value ( 'version' , '3' ) ;
49
50
} ;
50
51
51
52
browser . addMockModule ( 'moduleA' , mockModuleA2 ) ;
52
53
53
- browser . get ( 'index.html' ) ;
54
+ await browser . get ( 'index.html' ) ;
54
55
55
- expect ( element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '3' ) ;
56
+ expect ( await element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '3' ) ;
56
57
} ) ;
57
58
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 ( ) => {
59
61
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
60
62
browser . addMockModule ( 'moduleB' , mockModuleB ) ;
61
63
62
64
browser . removeMockModule ( 'moduleB' ) ;
63
65
64
- browser . get ( 'index.html' ) ;
66
+ await browser . get ( 'index.html' ) ;
65
67
66
- expect ( element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '2' ) ;
68
+ expect ( await element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '2' ) ;
67
69
} ) ;
68
70
69
- it ( 'should remove duplicate mock modules' , function ( ) {
71
+ it ( 'should remove duplicate mock modules' , async ( ) => {
70
72
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
71
73
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
72
74
browser . removeMockModule ( 'moduleA' ) ;
73
75
74
- browser . get ( 'index.html' ) ;
76
+ await browser . get ( 'index.html' ) ;
75
77
76
- expect ( element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '0.1' ) ;
78
+ expect ( await element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '0.1' ) ;
77
79
} ) ;
78
80
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 ( ) => {
80
82
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
81
83
browser . removeMockModule ( 'moduleB' ) ;
82
84
83
- browser . get ( 'index.html' ) ;
85
+ await browser . get ( 'index.html' ) ;
84
86
85
- expect ( element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '2' ) ;
87
+ expect ( await element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '2' ) ;
86
88
} ) ;
87
89
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 ( ) => {
89
92
browser . addMockModule ( 'moduleC' , mockModuleC , '42' , 'beta' ) ;
90
93
91
- browser . get ( 'index.html' ) ;
94
+ await browser . get ( 'index.html' ) ;
92
95
93
- expect ( element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '42beta' ) ;
96
+ expect ( await element ( by . css ( '[app-version]' ) ) . getText ( ) ) . toEqual ( '42beta' ) ;
94
97
} ) ;
95
98
96
- it ( 'should retrieve a list of current mock modules' , function ( ) {
99
+ it ( 'should retrieve a list of current mock modules' , ( ) => {
97
100
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
98
101
browser . addMockModule ( 'moduleC' , mockModuleC , '2' , 'B' ) ;
99
102
@@ -103,20 +106,20 @@ describe('mock modules', function() {
103
106
expect ( browser . getRegisteredMockModules ( ) [ 2 ] ) . toEqual ( mockModuleC ) ;
104
107
} ) ;
105
108
106
- it ( 'should load mock modules after refresh' , function ( ) {
109
+ it ( 'should load mock modules after refresh' , async ( ) => {
107
110
browser . addMockModule ( 'moduleA' , mockModuleA ) ;
108
111
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' ) ;
111
114
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' ) ;
114
117
} ) ;
115
118
116
119
// Back and forward do NOT work at the moment because of an issue
117
120
// bootstrapping with Angular
118
121
/*
119
- it('should load mock modules after navigating back and forward', function() {
122
+ it('should load mock modules after navigating back and forward', () => {
120
123
browser.addMockModule('moduleA', mockModuleA);
121
124
122
125
browser.get('index.html');
@@ -133,26 +136,26 @@ describe('mock modules', function() {
133
136
});
134
137
*/
135
138
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 ) ;
143
147
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' ) ;
146
150
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' ) ;
149
153
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' ) ;
152
156
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
+ }
157
160
} ) ;
158
161
} ) ;
0 commit comments