Testing at the Edges
On one project that I worked on, we abstracted the web DOM in this way in order to make our web page logic unit testable. There are better options now, but at the time it was tricky to unit test web applications in the absence of a real browser. We didn’t want to slow down our testing by having to start up a browser instance for each test case, so, instead, we changed how we wrote our UI. We wrote a library of UI components that “sat in front of the DOM” (Ports & Adapters for the DOM), so if we needed a table, we created a JavaScript Table via our own DOM factory. At runtime, that gave us a thin facade object that gave us a table that we could use. At test time, it gave us a stub that we could test against but didn’t require the presence of a real browser or DOM.
Link:: Modern Software Engineering