javascript - When using Jasmine's exceptGET / $httpBackend, what's the benefit of having .respond()? -


i using book called angularjs , running. gives example of using exceptget. example:

mockbackend = $httpbackend; mockbackend.exceptget('/api/note')     .respond([{id:1, label: 'mock'}]); 

my question is, isn't point of unittesting server calls make server call , verify server call expect be?

with above code, not make server call , force response equal [{id:1, label: 'mock'}]? what's point of doing if aren't able check actual response is?

because later on in code, checks response so:

mockbackend.flush(); expect(ctrl.items).toequal([{id:1, label: 'mock'}]); 

wouldn't equal [{id:1, label: 'mock'}] because that's forced response equal? what's benefit of having .respond() , controlling response?

if hit api endpoint on server in unit test, it not unit test anymore - involve more component under test (controller/service/provider etc) - network, web server, backend itself, database etc - becomes integration test or system/functional test.

your unit test not isolated anymore , depend on more things should. point of mocking make test isolated, independent , imitate desired conditions - in case http response - , check how component under test react.

expect(ctrl.items).toequal([{id:1, label: 'mock'}]);

this expect call itself, @ least, check mock applied , items controller variable contains mocked response.

please see more at:


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -