How to merge the two cells of a table in a Google text Document without this weird result?

[edit to address updates in Google Docs]

This currently not possible. You can know if a cell is merged by looking calling getColSpan and getRowSpan but there are no setter methods.

Please star the following issue to be notified by updates regarding this.

The merge function you found is not specific to table cells, it is there to merge any element with a previous sibling of the same type, joining their content.


[original answer]

If you were expecting to have a merged cell that, like what you can do in a spreadsheet, that is not possible. Simply because that's not possible in Google Documents (at least not yet). Therefore the API cannot do this (it can only do things that are also possible manually).

This merge function is not specific to table cells as you probably imagined. It is working as designed.