Search code examples
angularjsangularjs-e2ee2e-testingngmocke2e

Changing mock responses on a 'per test' basis


I have just started setting up e2e tests for our angular project. We have a page that collects and displays a lot of data from server.

The user will interact with the page in a limited number of ways, but the data can be presented in many different ways depending on what data the server returns.

In my current setup i define a couple of responses (using ngmocke2e) when the page loads in e2e mode.

I would like to start configuring the ngmocke2e-server responses in a before-each or similar structure in each of my test files. This would allow me to conditionally check that the page renders as expected with different sets of data.

Is there any way of doing this? It seems like a fairly obvious usecase, but I haven't found anything yet in documentation or by crawling the web.

plz halp!


Solution

  • I eventually discovered protractor-http-mock (https://github.com/atecarlos/protractor-http-mock). It did everything I wanted and can be easily run from grunt with grunt-protractor-runner & grunt-contrib-connect.

    With this approach I could also avoid having a separate build process in grunt for the end2end testing (which was an ugly hassle with ngmockE2E).