Skip to content

Instantly share code, notes, and snippets.

@tpluscode
Last active April 24, 2017 16:03
Show Gist options
  • Save tpluscode/8f856398b3305d73885015a3fb67abb1 to your computer and use it in GitHub Desktop.
Save tpluscode/8f856398b3305d73885015a3fb67abb1 to your computer and use it in GitHub Desktop.
Example of Web Component Tester with bound fixture
bower_components/
  1. bower install
  2. open test.html in your browser
  3. Watch the window title
{
"name": "wct-so-test",
"description": "",
"main": "",
"authors": [
"tpluscode"
],
"license": "MIT",
"moduleType": [],
"homepage": "",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"devDependencies": {
"web-component-tester": "~4.3.1"
},
"dependencies": {
"polymer": "polymer/polymer#~1.6.0"
}
}
<!doctype html>
<head>
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html"/>
<script src="bower_components/web-component-tester/browser.js"></script>
</head>
<html>
<dom-module id="my-element">
<template>
<style>
:host {
display: block;
box-sizing: border-box;
}
</style>
<div id="txt-url" class="card-content">{{captureUrl}}</div>
</template>
<script>
Polymer({
is: 'my-element',
properties: {captureUrl: String}
});
</script>
</dom-module>
<test-fixture id="my-element-fixture">
<template is="dom-template">
<my-element capture-url="{{captureUrl}}">
<h2>seed-element</h2>
</my-element>
</template>
</test-fixture>
<script>
suite('<my-element>', function () {
var myEl;
setup(function () {
myEl = fixture('my-element-fixture', {captureUrl: 'the url'});
});
test('heading is captureUrl', function () {
var urlDiv = myEl.$$('#txt-url');
// this will obviously fail, but used for logging purposes
assert.equal(urlDiv.textContent, 'the url');
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment