-
Notifications
You must be signed in to change notification settings - Fork 0
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
OR-5242 Practice URLSession
#68
Conversation
* main: OR-5242 Practice `URLSession` (#68)
* OR-5242-p2: OR-5242 Practice `URLSession` (#68)
func testURLSessionPublisher() { | ||
let expectation = XCTestExpectation(description: "Fetching GitHub user info") | ||
|
||
publisher.sink { [weak self] completion in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the convenient method:
URLSession.shared.dataTaskPublisher(for: url).sink { [weak self] completion in
let apiURL = URL(string: "https://api.github.com/users/crazymanish") | ||
let urlRequest = URLRequest(url: apiURL!) | ||
urlSession = URLSession.shared | ||
publisher = URLSession.DataTaskPublisher(request: urlRequest, session: urlSession) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using real request, please take a look URLProtocol
, e.g.
https://www.theinkedengineer.com/articles/mocking-requests-using-url-protocol
or https://www.google.com/search?q=mock+urlprotocol
Context
NotificationCenter
#67In this PR
URLSession
Testing steps
cmd+u