To write unit tests for your javascript code you can use a testing framework like JSTestDriver which is able to run under TeamCity.
Usage and configuration instructions for JSTestDriver are available on their website. For integration with TeamCity you’ll have to write an ant build file. But to be able to run browsers on your build agent machine you’ll have to use Xvfb. The test task in your ant file should look like the one below: