-
Notifications
You must be signed in to change notification settings - Fork 57
Frequently asked questions
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.
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.
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.
Google JS Test is built directly on top of Google's super-fast V8 JavaScript Engine, with no browser involved. In particular, there is no overhead of starting a browser, which saves a lot of time. This is what allows it to be so fast, but is also what prevents it from offering a real browser DOM to its tests. You can work around this and still use Google Js Test for code that manipulates the DOM however; see the question below.
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.