jeudi 15 novembre 2018

Modify global Window Variable in Angular 6 Tests

I'm trying to test an end-to-end process in an Angular 6 app using e2e and protractor. I have a service that injects some javaScript into the page, so my tests verify that the script has been appended to the DOM.

The wrinkle is that the service checks a configuration object that is hard-coded in the index.html file. I have to set one particular property to false in order for my tests to run, but so far, I haven't managed to find a way to hook into the app initialization process.

I can get at the property using code such as this:

browser.wait(
  browser.executeScript('return window.Config.local;')
         .then(promise => expect(promise).toBe(false)
), 5000);

But the question is where to put the call!

I have put some time into using APP_INITIALIZER, but the only way that I could get it to work was by setting it in the app.module.ts file. I'd rather not change its contents for test purposes.

I would be most appreciative if anyone had any idea how to get at the window object before the app fully initializes. I have spent three full days on this now and still no solution...

Thanks!

Aucun commentaire:

Enregistrer un commentaire