wct-mocha makes testing your web components a breeze!
You get a streamlined browser-based testing environment, designed to work with web-component-tester or on its own.
# Getting Started
Install mocha and wct-mocha as devDependencies
$ npm install --save-dev mocha$ npm install --save-dev wct-mocha
$ npm install --global web-component-tester$ npm install --global polymer-cli
$ wct --npm$ polymer test --npm
Your test suites can be
.html documents. For example,
Alternatively, you can write tests in separate
.js sources. For example,
To help support this case, you can also directly define an index that will load any desired tests:
When you use
polymer test on the command line, it is generating an
index like this for you based on the suites you ask it to load.
Web Components Support
By default, WCT will defer tests until the
WebComponentsReady event has been
@webcomponents/webcomponents-loader.js or one of its polyfill
bundles. This saves you from having to wait for elements to upgrade and all
If you need to test something that occurs before that event, the
can be used.
Alternately, if you are not using the
or loader or otherwise simply want tests to run as soon as possible, you can
disable this delay by setting
WCT.waitForFrameworks = false (though, they are
still async due to Mocha).
If you would like to have WCT load libraries on your behalf, you can define a list of scripts to load. There are two ways of doing this:
Inside your test code (before
wct-mocha/wct-mocha.js is loaded):
web-component-tester can pass the entire value of the WCT block
object here straight from the
clientOptions key in
A reference of the default configuration can be found at browser/config.ts.
Use any web server
If you prefer not to use WCT's command line tool, you can also run WCT tests directly in a browser via a web server of your choosing and still make use of all of its features.
Make sure that the
wct-mocha/wct-mocha.js script is accessible by your web
server, and have your tests load it after loading