1

How do I unit test a function that takes a list of maps and returns an HTML table with the same data in Clojure/Hiccup?

1 Answers1

1

For such "small" pieces of functionality, I would just perform regression testing on examples. Write a few samples representing some cases you want to deal with, manually build the results, and compare the output.

samples could be:

  • empty list
  • list with 1 entry / 1 col
  • list with 4 entries
  • invalid data (nested map, heterogeneous keys)

This test is brittle, but the scope of the function is so small that it is hard to come up with a good definition for the service provided.

A slightly better way is to parse the html and perform specific assertions on the structure returned by the function (nbr of rows, innerText of a td etc).

Simon Bergot
  • 7,970
  • 4
  • 35
  • 55