Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Frequently asked questions
What are the goals of Google JS Test?
Google JS Test is aimed at developers who want to do fast, expressive unit testing for things that really are units – self-contained chunks of code that don't have external dependencies like the browser, or have only external dependencies that can be mocked. The most important goals are:
Extremely fast iteration time. You should be able to write a test or change your code, then immediately see helpful results from Google JS Test without waiting for your tools.
Useful, readable output. The test runner should give you only helpful output, and it should be readable by a human at a glance. There should be nothing superfluous and nothing that gets in the way of the real output, like pages and pages of browser runner logging output.
Expressive assertions and mocking. There should be a powerful set of built-in ways to express test assertions as well as mock expectations and actions. The extra semantic information these convey should allow for even more useful test output. The set of matchers should be user-extensible.
Google JS Test is really fast—it takes only milliseconds to run tests. It has minimal output with exactly the information you need, and has a great set of matchers for assertions that also work with its built-in support for mocking.
Do I have to learn yet another testing framework API?
Maybe. Google JS Test's API is intentionally identical in spirit and almost identical in syntax to gtest and gmock, Google's C++ testing and mocking frameworks. If you're familiar with them, you should grok Google JS Test without any trouble at all. Even if you're not, the API is minimal and well-documented, and works as common sense would expect in most cases.
Can I use a browser to work on my tests locally?
No problem. Run
gjstest with the
html_output_file flag and it will write out
an appropriate HTML file. For example:
gjstest --js_files=bar.js,foo.js,foo_test.js --html_output_file=foo_test.html
If you open the HTML file in your browser (this is extensively tested only in Chrome), you'll get a nice browser interface to your test. You can refresh it when you change the test, the code being tested, and its dependencies.
Why doesn't Google JS Test present a DOM to the code under test?
Can I use Google JS Test to test my code that manipulates the DOM?
Yes! Google JS Test offers great built-in mocking facilities, and you can use this to pass in appropriate mock implementations of the DOM to your code under test. See "Is it for me?" for more information about this technique.