From eb08895efec0e7794d78ccb3ede50ba6c8d2b5e7 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Wed, 7 Nov 2018 11:48:59 -0800 Subject: [PATCH] chore(test): move mockmodule_spec.js off of the control flow --- spec/basic/mockmodule_spec.js | 109 +++++++++++++++++----------------- spec/basicConf.js | 3 +- spec/ciFullConf.js | 4 +- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/spec/basic/mockmodule_spec.js b/spec/basic/mockmodule_spec.js index b9381dd18..546e4fc1f 100644 --- a/spec/basic/mockmodule_spec.js +++ b/spec/basic/mockmodule_spec.js @@ -1,99 +1,102 @@ -describe('mock modules', function() { +describe('mock modules', () => { // A module to override the 'version' service. This function will be // executed in the context of the application under test, so it may // not refer to any local variables. - var mockModuleA = function() { - var newModule = angular.module('moduleA', []); + const mockModuleA = () => { + let newModule = angular.module('moduleA', []); newModule.value('version', '2'); }; // A second module overriding the 'version' service. // This module shows the use of a string for the load // function. - var mockModuleB = `angular.module('moduleB', []).value('version', '3');`; + const mockModuleB = `angular.module('moduleB', []).value('version', '3');`; // A third module overriding the 'version' service. This function // references the additional arguments provided through addMockModule(). - var mockModuleC = function() { + const mockModuleC = () => { var newModule = angular.module('moduleC', []); newModule.value('version', arguments[0] + arguments[1]); }; - afterEach(function() { + afterEach(() => { browser.clearMockModules(); }); - it('should override services via mock modules', function() { + it('should override services via mock modules', async() => { browser.addMockModule('moduleA', mockModuleA); - browser.get('index.html'); + await browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); }); - it('should have the version of the last loaded module', function() { + it('should have the version of the last loaded module', async() => { browser.addMockModule('moduleA', mockModuleA); browser.addMockModule('moduleB', mockModuleB); - browser.get('index.html'); + await browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('3'); + expect(await element(by.css('[app-version]')).getText()).toEqual('3'); }); - it('should use the latest module if two are added with the same name', function() { + it('should use the latest module if two are added with the same name', + async() => { browser.addMockModule('moduleA', mockModuleA); - var mockModuleA2 = function() { - var newModule = angular.module('moduleA', []); + let mockModuleA2 = () => { + let newModule = angular.module('moduleA', []); newModule.value('version', '3'); }; browser.addMockModule('moduleA', mockModuleA2); - browser.get('index.html'); + await browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('3'); + expect(await element(by.css('[app-version]')).getText()).toEqual('3'); }); - it('should have the version of the module A after deleting module B', function() { + it('should have the version of the module A after deleting module B', + async() => { browser.addMockModule('moduleA', mockModuleA); browser.addMockModule('moduleB', mockModuleB); browser.removeMockModule('moduleB'); - browser.get('index.html'); + await browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); }); - it('should remove duplicate mock modules', function () { + it('should remove duplicate mock modules', async() => { browser.addMockModule('moduleA', mockModuleA); browser.addMockModule('moduleA', mockModuleA); browser.removeMockModule('moduleA'); - browser.get('index.html'); + await browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('0.1'); + expect(await element(by.css('[app-version]')).getText()).toEqual('0.1'); }); - it('should be a noop to remove a module which does not exist', function() { + it('should be a noop to remove a module which does not exist', async() => { browser.addMockModule('moduleA', mockModuleA); browser.removeMockModule('moduleB'); - browser.get('index.html'); + await browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); }); - it('should have the version provided from parameters through Module C', function() { + it('should have the version provided from parameters through Module C', + async() => { browser.addMockModule('moduleC', mockModuleC, '42', 'beta'); - browser.get('index.html'); + await browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('42beta'); + expect(await element(by.css('[app-version]')).getText()).toEqual('42beta'); }); - it('should retrieve a list of current mock modules', function() { + it('should retrieve a list of current mock modules', () => { browser.addMockModule('moduleA', mockModuleA); browser.addMockModule('moduleC', mockModuleC, '2', 'B'); @@ -103,20 +106,20 @@ describe('mock modules', function() { expect(browser.getRegisteredMockModules()[2]).toEqual(mockModuleC); }); - it('should load mock modules after refresh', function() { + it('should load mock modules after refresh', async() => { browser.addMockModule('moduleA', mockModuleA); - browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + await browser.get('index.html'); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); - browser.navigate().refresh(); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + await browser.navigate().refresh(); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); }); // Back and forward do NOT work at the moment because of an issue // bootstrapping with Angular /* - it('should load mock modules after navigating back and forward', function() { + it('should load mock modules after navigating back and forward', () => { browser.addMockModule('moduleA', mockModuleA); browser.get('index.html'); @@ -133,26 +136,26 @@ describe('mock modules', function() { }); */ - it('should load mock modules after navigating back and forward from link', function() { - browser.getCapabilities().then(function(caps) { - if (caps.get('browserName') === 'safari') { - // Safari can't handle navigation. Ignore this test. - return; - } else { - browser.addMockModule('moduleA', mockModuleA); + it('should load mock modules after navigating back and forward from link', + async() => { + const caps = await browser.getCapabilities(); + if (caps.get('browserName') === 'safari') { + // Safari can't handle navigation. Ignore this test. + return; + } else { + browser.addMockModule('moduleA', mockModuleA); - browser.get('index.html'); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + await browser.get('index.html'); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); - element(by.linkText('repeater')).click(); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + await element(by.linkText('repeater')).click(); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); - browser.navigate().back(); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); + await browser.navigate().back(); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); - browser.navigate().forward(); - expect(element(by.css('[app-version]')).getText()).toEqual('2'); - } - }); + await browser.navigate().forward(); + expect(await element(by.css('[app-version]')).getText()).toEqual('2'); + } }); }); diff --git a/spec/basicConf.js b/spec/basicConf.js index 4c68be0d4..99694475d 100644 --- a/spec/basicConf.js +++ b/spec/basicConf.js @@ -12,8 +12,9 @@ exports.config = { 'basic/lib_spec.js', 'basic/locators_spec.js' // 'basic/elements_spec.js', - // 'basic/navigation_spec.js', // 'basic/handling_spec.js', + // 'basic/mockmodule_spec.js', + // 'basic/navigation_spec.js', ], // Exclude patterns are relative to this directory. diff --git a/spec/ciFullConf.js b/spec/ciFullConf.js index 8389a999f..3e6953837 100644 --- a/spec/ciFullConf.js +++ b/spec/ciFullConf.js @@ -14,9 +14,9 @@ exports.config = { 'basic/lib_spec.js', 'basic/locators_spec.js' // 'basic/elements_spec.js', - // 'basic/navigation_spec.js', // 'basic/handling_spec.js' - // 'basic/elements_spec.js', + // 'basic/mockmodule_spec.js', + // 'basic/navigation_spec.js', ], // Exclude patterns are relative to this directory.