Test-Driven Development in JS with Acceptance Tests

  Рет қаралды 2,135

Bran van der Meer

Bran van der Meer

Күн бұрын

Пікірлер: 6
@Richter12
@Richter12 8 ай бұрын
I love the explanation, extremely high quality coding and examples. You gave me a lot of context on testing I really hope you keep doing all these videos.
@esc120
@esc120 Жыл бұрын
Hi! Thanks for the awesome content! 😀 I just found some problem in the code so I put them here: 17:17 Do not use Array.map for side effect. Use Array.forEach if you are not actually mapping things. 25:33 Do not add unknown attributes on standard HTML elements. Use data-* for custom data attributes instead. 29:46 Array.slice is using shallow copy, so you are still mutating the inner object.
@branvandermeer
@branvandermeer Жыл бұрын
Good points, thanks for the codereview! A second pair of eyes is always a good idea :)
@ermakamre
@ermakamre Жыл бұрын
Hello, thanks for the video! Some questions/notes: 1) Why there are no tests for the react components AddTodo/TodoList, were they developed without TDD? 2) Injecting initial state to the App looks like a cheating, there is no such simple approach in real apps. How would you deal with app that takes initial state from the server? 3) Should data-testid be unique on the page? 4) Introducing done field and not updating the state in all existing tests also looks strange, treating done as optional is questionable approach. 5) Does is it worth to execute all tests including the potentially slow acceptance tests every time while working in the inner loop of TDD? 6) Why not to run the tests inside the IDE?
@branvandermeer
@branvandermeer Жыл бұрын
1) First because they weren't the focus of my video, but also because they're too simple to warant a test I would say. If you look at the AddTodo component, there isn't even any branching, just html rendering. What would you even test? The actual logic is in the reducer. 2) I hoped to make a more realistic example without having a gargantuan codebase. You can look at other design patterns and frameworks which promote centralised state management. This was introduced with Flux, it's now in the more modern Redux, MobX and GraphQL/Apollo. Yes, in larger apps not in the root, but even then, its about passing the `state` and `dispatch` via either props or the react context api (not the only solution ofc, but the most popular one). And the elephant in the room is ofc testing: now its easy to inject, so to make it testable, I even prefer a (semi-)centralised state management solution. 3) Not sure. On the one hand, anything called "id" (as-in "identifier"), implies uniqueness for me. On the other hand, I would like to select multiple sometimes, so maybe I should start using a data-testclass analogous to html's id/class attributes. 4) I actually prefer my objects to be open for extension, and closed for modification (Open-closed Principle). It's fine that the object contains more properties than what the tests need. I do this all time, because it makes sure I don't tight-couple my tests to the full object specification in this way, but instead my tests only access the properties they need. (I also dislike TS a bit for this reason.) As another example; in the last 2 tests in this code: pastebin.com/hutbAgqr - I've explicitly chosen to only expect() the 'from' and 'to' properties, thereby loose-coupling myself to the object. I don't have to change all my tests all the time as my code evolves, there's no added value in an exact object match for those tests, they're there to mitigate a different risk. If they were tight coupled, it would also give me more false-negatives, they would fail for the wrong reason. 5) That becomes a question of cost/benefit ratio. If your acceptance tests are more towards end2end tests then definitely not. If they're slow, also skip them. In general, it's good to have the capability to run just 1 test suite or something. (I'm not a fan of end2end tests at all, they're often not worth their money. Many end2end cost more time and headache, they're not catching bugs but they are often failing when they shouldn't fail.) 6) Just preference. The terminal inside VSCode is less performant and configurable for example (I automate and configure a lot). In addition, I ran jest without babel in nodejs with es-modules, this requires experimental flags which weren't accepted automatically by the jest extension in VSCode. I could have made it work probably, but I chose to spend my time on a better a video :)
@havefun5519
@havefun5519 6 ай бұрын
Detailed explained
Unit tests: How I tell the Good from the Bad
9:45
Bran van der Meer
Рет қаралды 4,3 М.
这是自救的好办法 #路飞#海贼王
00:43
路飞与唐舞桐
Рет қаралды 92 МЛН
Human vs Jet Engine
00:19
MrBeast
Рет қаралды 178 МЛН
Why TDD with UI code is hard
14:59
Bran van der Meer
Рет қаралды 807
Test-Driven Development // Fun TDD Introduction with JavaScript
12:55
Dependency Injection, simplified
9:55
Bran van der Meer
Рет қаралды 4,2 М.
TDD Is The Best Design Technique
19:26
Continuous Delivery
Рет қаралды 51 М.
🚀  TDD, Where Did It All Go Wrong (Ian Cooper)
1:03:55
DevTernity Conference
Рет қаралды 563 М.
Ubiquitous Language, simplified
9:25
Bran van der Meer
Рет қаралды 1,2 М.
Why Vitest Is Better Than Jest
13:13
Web Dev Simplified
Рет қаралды 138 М.
Test Driven Development vs Behavior Driven Development
18:42
Continuous Delivery
Рет қаралды 153 М.
The First Rule of Comments in Code
10:56
Bran van der Meer
Рет қаралды 1,3 М.
Introduction to Jest Testing | JavaScript Unit Tests
25:30
Dave Gray
Рет қаралды 32 М.
这是自救的好办法 #路飞#海贼王
00:43
路飞与唐舞桐
Рет қаралды 92 МЛН