diff --git a/src/actions/action-creators.test.js b/src/actions/action-creators.test.js index dd752b5..cdd477b 100644 --- a/src/actions/action-creators.test.js +++ b/src/actions/action-creators.test.js @@ -45,7 +45,10 @@ const desmosMock = { GraphingCalculator: jest.fn(() => { return { asyncScreenshot: (opts, cb) => cb(''), - getExpressions: () => [{ id: 1, latex: 'x = 3' }, { id: 2, latex: '' }], + getExpressions: () => [ + { id: 1, type: 'expression', latex: 'x = 3' }, + { id: 2, latex: '' } + ], setExpression: () => null }; }) diff --git a/src/lib/calc-helpers.js b/src/lib/calc-helpers.js index 42957f9..d88b5c8 100644 --- a/src/lib/calc-helpers.js +++ b/src/lib/calc-helpers.js @@ -28,10 +28,14 @@ export const getImageData = opts => */ const getExpByIndex = idx => calculator.getExpressions()[idx - 1]; -// Returns an error message on failure. +/** + * Returns an error message on failure. + * Skips expressions that are not of type 'expression' + */ export const setSliderByIndex = (idx, val) => { const exp = getExpByIndex(idx); if (!exp) return noSuchExpression(idx); + if (exp.type !== 'expression') return notASlider(idx); const { id, latex } = exp; const match = latex.match(/(.+)=/);