AngularJS unit testing without relying on mocks for query data

I finally got the setup of the AngularJS test environment, and I'm trying to check if the pages are working in my application. This includes patterns , routes , queries , directives , etc.

From what I found, when testing a working application, it turns out that most of the work requires mock. Although this is good, I would still like to check the actual templates and data from my application.

Whenever a GET call is made in my application, I get an error message:

Unexpected request: GET application/templates/home.html No more request expected Error: Unexpected request: GET application/templates/home.html 

It turns out he can't load the request correctly. This is normal. From what, in my opinion, is happening, the test runner (testacular) cannot load the template file, since it is in a different environment (without an HTTP address). The only solutions I came across with how to fix this is to mute the request using the layout using the $ httpBackend service. Although this is useful for certain situations, I want to get the actual data.

Any idea on how to fix this?

+4
source share
1 answer

You probably want to write two different types of tests:

  • Unit tests with mocks to test components in isolation, such as controllers, directives, etc.
  • e2e tests that run your full stack, including data from your own server.

Each of the two types of tests requires a separate test configuration.

Angular provides support for navigating the test browser and interacting with your application as a user. Explanation and API are described here: http://docs.angularjs.org/guide/dev_guide.e2e-testing

My test e2e configuration and explanation are posted here: fooobar.com/questions/1434830 / ...

An important part of running tests from your own server is proxies , as explained in this post.

+3
source

Source: https://habr.com/ru/post/1447568/


All Articles