From 56beb24b9473ceedc491f3ca00fbce1bb9a18f29 Mon Sep 17 00:00:00 2001 From: Julie Ralph Date: Tue, 6 Jan 2015 15:11:44 -0800 Subject: [PATCH] feat(protractor): add browser.getRegisteredMockModules() Now `browser.getRegisteredMockModules()` returns a list of the functions or strings that have been registered as mock modules. For troubleshooting. Closes #1434. --- lib/protractor.js | 11 +++++++++++ spec/basic/mockmodule_spec.js | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/protractor.js b/lib/protractor.js index 87f9ed54f..911ccdfd0 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -379,6 +379,17 @@ Protractor.prototype.removeMockModule = function(name) { } }; +/** + * Get a list of the current mock modules. + * + * @return {Array.} + */ +Protractor.prototype.getRegisteredMockModules = function() { + return this.mockModules_.map(function(module) { + return module.script; + }); +}; + /** * Add the base mock modules used for all Protractor tests. * diff --git a/spec/basic/mockmodule_spec.js b/spec/basic/mockmodule_spec.js index 39d66a6e8..1a1d55a93 100644 --- a/spec/basic/mockmodule_spec.js +++ b/spec/basic/mockmodule_spec.js @@ -85,6 +85,16 @@ describe('mock modules', function() { expect(element(by.css('[app-version]')).getText()).toEqual('42beta'); }); + it('should retrieve a list of current mock modules', function() { + browser.addMockModule('moduleA', mockModuleA); + browser.addMockModule('moduleC', mockModuleC, '2', 'B'); + + // Should have 3 mock modules, A, C, and the base. + expect(browser.getRegisteredMockModules().length).toBe(3); + expect(browser.getRegisteredMockModules()[1]).toEqual(mockModuleA); + expect(browser.getRegisteredMockModules()[2]).toEqual(mockModuleC); + }); + it('should load mock modules after refresh', function() { browser.addMockModule('moduleA', mockModuleA);