jfalek wrote:
> All projects use Ajax and
> JavaScript (based on the prototype framework).
To unit test Ajax, you must generally test that your business model has injected
the correct data into the correct entry points in your Ajax library. Don't unit
test the wire protocol itself, or the JavaScript behavior in a browser. Rely on
thru-the-GUI tests to keep that end stable.
To detect business values, I let the HTML layer generate its output, with its
embedded JavaScript. I parse the HTML, as XHTML, with XPath, and tweezer out the
<script> tags. Then I drop their contents into a JavaScript lexer that turns its
variables into a data model. Querying this model should return the correct data
values.
That kind of test intercepts the values at the last moment before the GUI layer
takes them over. And (under Ruby on Rails) the test start by mocking the server,
so we have no excess programs anywhere. No web server, internet wire, web
browser, DOM, or JavaScript come between our unit tests and the tested code.
--
Phlip