I'm writing a web app with my friend. He writes the Fronted, I write the Backend. Problem is that there is no way of me testing my code if my friend haven't wrote the integration yet, because we bundle the code in web pack and run it on a dev server. My question is, is there a way that I could test my typescript code (call functions with parameters) in chrome console, like I could test unbundled javascript?
Asked
Active
Viewed 208 times
0
-
Normally you should be able to run the server and the client build separately. And to test the API of server-side code (backend), you would write a set of unit tests, call the API using something like `node-fetch` with the data the client would send and check if the API returns the expected result. And besides that, you would write a unit test, that directly works on the different functions of your backend code to these them individually. (You wouldn't test the backend code form the chrome console) – t.niese Jun 10 '22 at 16:49
-
@t.niese problem is that backend sits on client side. Maybe I'm calling it wrong but what I mean by backend is inner mechanics of the app. I want to test connecting to a server not the server – pggu11 Jun 11 '22 at 12:02
1 Answers
0
The professional answer is: Don't do that!
- Test the actual server using Postman.
- Write unit tests for your api-handling client code that intercepts calls to the server (because those aren't unit tests), via jest or some other unit testing library.
- Write unit tests for the front end that doesn't actually touch your middle-code.
- Convert unit tests to assertions where you can, because case coverage beats code coverage and you can't possible think of everything during unit tests.
- Write integration tests that are user-centric, not widget centric.
And that's hard but you'll be glad you did it... if you can do it without the project dying because of it! For a project that is just you and a friend, that may be a mighty big "if"!
So the realistic answer is probably: Write... or get your friend to write... an ugly-but-functional page you can use to enter some values and click a button to submit it, and then add debugger
as a statement near the start of the button code. debugger
is a hardcode breakpoint that dev tools will pause at.
Once that's written and working you should be able to modify it as needed. ...just remember not to let that page escape into production.

JSmart523
- 2,069
- 1
- 7
- 17