I use a custom URLProtocol class in my tests. If I register my URLProtocol class and use URLSession to load a URL, the custom class is used, but if I make a call to any firebase API, the custom class doesn't get used.
Steps to reproduce:
Write a URLProtocol subclass, implement canInit(with request:), set a breakpoint here
In the setUp() method of your test class, add URLProtocol.registerClass(CustomURLProtocol.self)
Write a test and load any URL using URLSession.shared.dataTask(with:)
Run the test and notice the breakpoint in canInit gets hit
Change the test to call Auth.auth().createUser or Database.database().reference().child(path).setValue
Run the test and notice the breakpoint in canInit does not get hit
Sorry, I think I misunderstood how registerClass would work. It works for the shared instance of URLSession, but not one with a set configuration. I'll look for another way to test.
I use a custom URLProtocol class in my tests. If I register my URLProtocol class and use URLSession to load a URL, the custom class is used, but if I make a call to any firebase API, the custom class doesn't get used.
Steps to reproduce:
canInit(with request:)
, set a breakpoint heresetUp()
method of your test class, addURLProtocol.registerClass(CustomURLProtocol.self)
URLSession.shared.dataTask(with:)
canInit
gets hitAuth.auth().createUser
orDatabase.database().reference().child(path).setValue
canInit
does not get hit