Skip to content

Commit

Permalink
chore(test): move mockmodule_spec.js off of the control flow (angular…
Browse files Browse the repository at this point in the history
  • Loading branch information
cnishina committed Dec 19, 2018
1 parent 511104d commit d27e36a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
109 changes: 56 additions & 53 deletions spec/basic/mockmodule_spec.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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');
Expand All @@ -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');
}
});
});
3 changes: 2 additions & 1 deletion spec/basicConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions spec/ciFullConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d27e36a

Please sign in to comment.