diff --git a/calculator/test.js b/calculator/test.js index e8e7212..e07027f 100644 --- a/calculator/test.js +++ b/calculator/test.js @@ -57,10 +57,12 @@ global.load = () => {}; // --- Load calculator app --- +// We wrap the app code in a function that returns the buttonPress function, +// so we can capture it and use it in our tests. const calculatorCode = fs.readFileSync(path.join(__dirname, 'calculator.app.js'), 'utf8'); -(function(require) { - eval(calculatorCode); -})((name) => { +const wrappedCode = `(function(require) { ${calculatorCode}; return buttonPress; })`; +const getButtonPress = eval(wrappedCode); +const buttonPress = getButtonPress((name) => { if (name === "FontDylex7x13") { return { add: () => {} }; }