Why can't I test my Javascript?

Gregory Moeck
LA Ruby Conf Lightning Talk
2011-02-05

Creative Commons License
Special thanks to Kerry Buckley for the presentation layout

Quick Poll

Quick Poll

How many of you practice TDD in Ruby?

Quick Poll

How many of you practice TDD in Javascript?

Why Not?

Bad Testing Frameworks

Why Not?

Browser isn't conductive to testing

Why can't I test this?

                $query1 = "SELECT * FROM storage_access_vault_items WHERE access_id = {$_GET[pid]}";
                $result1 = mysql_query($query1);
                $inner_vault_items = array();
                while($this_item = mysql_fetch_assoc($result1))
                    $inner_vault_items[] = $this_item['vault_item_id'];
                while($vault = mysql_fetch_assoc($result))
                {?>
                  //some HTML stuff with  in it
                }
                ...
      

Why can't I test this?

Because the structure isn't testable

Why can't I test this?

NOT because of inherent problems with PHP

Lesson To Learn:

The same is true of Javascript

Lesson To Learn:

You can't test your Javascript

=>

Your structure (likely) is a problem.

Lesson To Learn:

Javascript is not like CSS

Lesson To Learn:

Javascript is a programming language.

Lesson To Learn:

Use it like you would use Ruby when your writing anything substantial.

http://gmoeck.github.com/presentations/larubyconf-why-cant-i-test-my-javascript/#1

@gregmoeck