0

I have a problem with mock a variable shown below:

const DEFAULT_SEARCH_RESULTS_PAGE_SIZE = wkVars.vars('backends')['andro-ics'].search.resultsPageSize;

I tried:

 beforeAll(() => {
    const wkVars = jasmine.createSpyObj('wkVars', ['vars']);
    wkVars.vars.and.callFake(() => {
    return {
            'andro-ics': {
                search: {
                    resultsPageSize: 'test'
                }
            }
        };
    });
});

...but still doesn't work. Do you have any suggestions what can I change?

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
  • `wkVars` seems to be local variable in `beforeAll`, try declaring it in suite scope (like in [this answer](https://stackoverflow.com/a/24329981/7404943)) – barbsan Jun 28 '18 at 08:28
  • I tried this way. A console shown: "...vars.json does not exist. Trying to use vars.json instead. Cannot find vars. Serving empty object TypeError: Cannot read property 'andro-ics' of undefined" – Natalia Gurgul Jun 28 '18 at 09:28
  • Do you pass `wkVars` as argument of tested function or is it local variable of that function/module? If the latter check [this question](https://stackoverflow.com/questions/9619500/using-jasmine-to-spy-on-variables-in-a-function). It seems that tested function tries loading vars.json file, propably you'll need to mock that too. – barbsan Jun 28 '18 at 09:52
  • It is a global variable which is used by this function. – Natalia Gurgul Jun 28 '18 at 10:29

0 Answers0