Copied from this meaning , which discusses this issue in detail.
The comments are all inclusive. There is much to consider.
What is wrong with mocks
Consider this data structure used to get a membership-based list of names.
/users/<user id>/name /rooms/members/<user id>/true
Now, let's create a couple of simple classes without any real consideration for testing structures, assuming we will use the Firebase layout to test them. Notice that I see such errors constantly in the wild; this example is not too exaggerated or exaggerated (it is pretty tame in comparison)
class User {
Better Approach Using Proper Encapsulation and TDD
Ok, now let me reverse this by starting with developing an effective test unit and see if we can design our classes with lesser grip to accommodate.
function testGetNames() { const userList = new UserList(); userList.add( new User('kato', 'Kato Richardson') ); userList.add( new User('chuck', 'Chuck Norris') ); assertEqual( userList.getNames(), ['Kato Richardson', 'Chuck Norris']);
Kato
source share