I'm making a small test framework that uses the JavaScript module pattern for UI Automation testing on iOS. However, I seem to be getting odd results based on #import and extending modules.
I have the base test module called Tester-Module.js
:
(function() {
var Tester = this.Tester = {};
Tester.setUp = function() {
UIALogger.logMessage('Regular SetUp()');
}
}).call(this);
If I import this module in my test case, it works fine. Here's the test file tester.js
(tester.js
is the file I import in Instruments):
#import "./Tester-Module.js"
// Prints 'Regular SetUp()'
Tester.setUp();
However, if I try to extend the Tester-Module.js
module in another module file, I cannot reference the Tester object. Tester-Extension.js
extends the Tester module defined in Tester-Module.js
:
#import "./Tester-Module.js"
// Outputs:
// Exception raised while running script:
// ReferenceError: Can't find variable: Tester\n
Tester.setUp = function() {
UIALogger.logMessage('Overwritten SetUp()');
}
And the updated test case file tester.js
:
#import "./Tester-Extension.js"
// Exception is thrown before this
Tester.setUp();
My hopefully related questions are:
Why can I not reference the Tester object inside
Tester-Extension.js
, but can intester.js
?What is the #import macro doing?