¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

[TDD] How to TDD JavaScript so it thinks it is in a browser.


 

There are a bunch of different ways to do it. I recommend Jasmine as a test framework. It has a fluent, RSpec-like syntax and is decoupled from its runner enough to run almost everywhere (There are dozens of other frameworks and tools that play nice with it.)?

You can use something like jsdom or one of a number of alternatives to stub out a dom and verify code that runs against it. Those run ridiculously fast on Node.js and are a good first pass for basic correctness. However, you are still going to want to have a few integration tests to make sure that critical things do run in the various browsers.?

You also want to decouple your domain logic from your dom manipulation. This is exactly the same as in any other OO language. The language in your code should be about what the user is trying to accomplish and details about the dom manipulation should be in small composed methods underneath that.?


On Fri, Apr 4, 2014 at 2:35 PM, Ian <hobson42@...> wrote:
?

Hi all,

How can I set up some programmed tests to test JavaScript, so it thinks
its in a browser?

The JavaScript code modifies the style objects and the DOM.

Have tried various utilities that claim to test JavaScript in the
browser, and they have
proved impractically slow. (A paste of a 25 character string took over 3
minutes!)

So I guess the JavaScript has to be run elsewhere (WSH?) and made to
think it is in a browser,
but I have no ideas how to do this.

I can use Windows or Linux - (No mac :( ).

Thanks

Ian