-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Http service #169
Comments
Thanks Felix. For unit testing, I don't think there's conceptually any difference between http and any other service you may have to mock out? Here's how we do it with Ionic's storage service:
I have a closed source project unit testing a http service much the same way. For E2E, see angular/protractor#3092 |
Hi Stephen, thanks for your answer. You're right, this works, I was maybe being unclear. Taking the example storage.mock.ts, I would like the content from lines 7 -25 put in a separate json-file called mycontents.json. Then in storage.mock.ts one could have something like this: http.get('mycontents.json').subscribe(..) The reason why I would like to have this is code/content separation. This would be especially interesting if the "content" is rather longer and more unwieldy than in storage.mock.ts, But maybe not the way to go. Cheers,Felix |
Hi Stephen, I am just now trying to follow your recommendation. However I am hitting on the problem when I try to create a static initHttp. Using
[ts] Supplied parameters do not match any signature of call target. Any recommendations? Cheers,Felix |
I think this is a good idea, but why do you need to import the content as JSON over http? http-contents.mock.ts: export const myContents = {
"some": "json"
} http.mock.ts: import { myContents } from './http-contents.mock' |
You seem to be using angular2/http, which is injected into the constructor via angular's DI. This is a much simpler case, no need for a static initHTTP method. There's good examples of how to do this in ClickerService and the associated spec http.ts: constructor(public http: Http) {} http.spec.ts: let http: HttpService = null;
describe('HttpService', () => {
beforeEach(() => {
http = new HttpService(<any>new HttpMock());
}); |
Excellent, thank you very much. |
Excellent work.
Everything works for me in the current state. So this is not really an issue. I am not sure where to post it.
I've tried to get his to work with a service that itself uses http. Everything I've tried has failed. One problem seems to be that there have been quite a few changes involving http, so anything that is more than a couple of months old does not work. On the other hand it's a very common use case. I'd be interested in a solution using either a real or mocked up service.
I would appreciate any hints, pointers or links.
cheers, Felix
The text was updated successfully, but these errors were encountered: