protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Passing functions to addMockModule/client-side context

Open magicode118 opened this issue 10 years ago • 1 comments

I've tried several methods, but I can't seem to resolve this one by using the current Protractor code-base. Incidentally a Stack Overflow user posted a question with my same exact issue, so I'm linking it here as it explains it really well.

I have several mock modules that need dynamic logic that is used to update the response in real-time (to test out two-way bindings etc... on the front-end with new data). This can only be done when inside the Angular context (client-side) and not within Protractor (node process) context currently.

Therefore, I'm having to create all the logic inside the addMockModule function, which is really not ideal and non-modular.

magicode118 avatar Apr 14 '16 16:04 magicode118

Protractor is intended for e2e testing, with your application talking to some kind of backend (either a real one or a fake backend for testing). addMockModule is convenient when you have to mock out simple things, but relying on it too much is a bit of an anti-pattern. Since all of that code needs to be sent to the browser via webdriver.executeScript, relying on mock modules too much can be complicated and hard to debug. If your mock modules are getting overly complex, there are a few things you can consider:

  1. Move the tests that rely on mocks into unit tests.
  2. Implement the functionality of the mocks in the app itself, and run your protractor tests in some kind of "testing mode".
  3. Instead of relying on mocks, put that logic into a testing backend server.

Those aren't the only options, and without knowing the details of your application I can't really say which would be the best. But in general, I'd say that if you need complicated testing for client side logic, Protractor is not going to be the best tool for that.

I'm going to close the issue because this could be kind of an open-ended discussion. But if you have a specific feature request that you think would help in your case, please let us know.

heathkit avatar Apr 14 '16 21:04 heathkit