Permalink
Browse files

Use web-component-tester for seed and improve the look of tests

  • Loading branch information...
1 parent 6e92d2f commit 7e1748ad094bc6687f0389e71dfe5a4b53a04f27 @robdodson robdodson committed Nov 24, 2014
View
@@ -1,3 +1,3 @@
node_modules
-temp/
+tmp/
.DS_Store
@@ -7,6 +7,6 @@
"polymer": "Polymer/polymer#^0.5.1"
},
"devDependencies": {
- "polymer-test-tools": "Polymer/polymer-test-tools#^0.5.1"
+ "web-component-tester": "Polymer/web-component-tester#^2.0.0"
}
}
@@ -7,14 +7,15 @@
<meta charset="UTF-8">
<script src="../bower_components/webcomponentsjs/webcomponents.js"></script>
-
- <link rel="import" href="tests.html">
-
+ <script src="../bower_components/web-component-tester/browser.js"></script>
</head>
<body>
- <div id="mocha"></div>
+ <script>
+ WCT.loadSuites(['yo-greeting-basic.html', 'yo-list-basic.html']);
+ </script>
+
</body>
@@ -1,26 +0,0 @@
-<link rel="import"
- href="../bower_components/polymer-test-tools/tools.html">
-
-<script src="../bower_components/polymer-test-tools/mocha-htmltest.js">
-</script>
-
-<script>
-
- mocha.setup({ui: 'tdd', slow: 1000, timeout: 5000, htmlbase: ''});
-
- // Below is a set of sample element test suites.
- // Replace these with your own suites of tests.
-
- htmlSuite('yo-greeting', function() {
- htmlTest('yo-greeting-basic.html');
- });
-
- htmlSuite('yo-list', function() {
- htmlTest('yo-list-basic.html');
- });
-
- // End sample test suites
-
- mocha.run();
-
-</script>
@@ -5,31 +5,24 @@
<title>yo-greeting-basic</title>
<script src="../bower_components/webcomponentsjs/webcomponents.js"></script>
- <link rel="import"
- href="../bower_components/polymer-test-tools/tools.html">
- <script src="../bower_components/polymer-test-tools/htmltest.js">
- </script>
+ <script src="../bower_components/web-component-tester/browser.js"></script>
<!-- Step 1: import the element to test -->
<link rel="import" href="../elements/yo-greeting/yo-greeting.html">
</head>
<body>
- <yo-greeting></yo-greeting>
+ <yo-greeting id="fixture"></yo-greeting>
<script>
-
- document.addEventListener('polymer-ready', function() {
- var el = document.querySelector('yo-greeting');
- var header = el.shadowRoot.querySelector('h1');
- assert.equal(header.textContent, '\'Allo, \'Allo!');
-
- // IMPORTANT:
- // Make sure to call done() at the end of every test suite!
- done();
+ suite('yo-greeting', function() {
+ test('Allo, Allo!', function() {
+ var el = document.querySelector('yo-greeting');
+ var header = el.shadowRoot.querySelector('h1');
+ assert.equal(header.textContent, '\'Allo, \'Allo!');
+ })
});
-
</script>
</body>
@@ -5,39 +5,32 @@
<title>yo-list-basic</title>
<script src="../bower_components/webcomponentsjs/webcomponents.js"></script>
- <link rel="import"
- href="../bower_components/polymer-test-tools/tools.html">
- <script src="../bower_components/polymer-test-tools/htmltest.js">
- </script>
+ <script src="../bower_components/web-component-tester/browser.js"></script>
<!-- Step 1: import the element to test -->
<link rel="import" href="../elements/yo-list/yo-list.html">
</head>
<body>
- <yo-list></yo-list>
+ <yo-list id="fixture"></yo-list>
<script>
-
- document.addEventListener('polymer-ready', function() {
- // Test a property
- var el = document.querySelector('yo-list');
- el.items.push('Foo');
-
- // Data bindings will stamp out new DOM asynchronously
- // so wait to check for updates
- setTimeout(function() {
- var listItems = el.shadowRoot.querySelectorAll('li');
- assert.equal(el.items.length, listItems.length);
-
- // IMPORTANT:
- // Make sure to call done() at the end of every test suite!
- done();
- });
-
+ suite('yo-list', function() {
+ test('Item lengths should be equalled', function(done) {
+ // Test a property
+ var el = document.querySelector('yo-list');
+ el.items.push('Foo');
+
+ // Data bindings will stamp out new DOM asynchronously
+ // so wait to check for updates
+ setTimeout(function() {
+ var listItems = el.shadowRoot.querySelectorAll('li');
+ assert.equal(el.items.length, listItems.length);
+ done();
+ });
+ })
});
-
</script>
</body>
View
@@ -103,7 +103,6 @@ module.exports = yeoman.generators.Base.extend({
this.template('test/index.html', 'test/index.html');
this.template('test/seed-element-basic.html',
'test/' + this.elementName + '-basic.html');
- this.template('test/tests.html', 'test/tests.html');
},
install: function () {
this.installDependencies({
@@ -11,6 +11,6 @@
"polymer": "Polymer/polymer#^0.5.1"
},
"devDependencies": {
- "polymer-test-tools": "Polymer/polymer-test-tools#^0.4.0"
+ "web-component-tester": "Polymer/web-component-tester#^2.0.0"
}
}
@@ -7,14 +7,14 @@
<meta charset="UTF-8">
<script src="../../webcomponentsjs/webcomponents.js"></script>
-
- <link rel="import" href="tests.html">
-
+ <script src="../../web-component-tester/browser.js"></script>
</head>
<body>
- <div id="mocha"></div>
+ <script>
+ WCT.loadSuites(['seed-element-basic.html']);
+ </script>
</body>
@@ -5,40 +5,40 @@
<title><%= elementName %></title>
<script src="../../webcomponentsjs/webcomponents.js"></script>
- <link rel="import" href="../../polymer-test-tools/tools.html">
- <script src="../../polymer-test-tools/htmltest.js"></script>
+ <script src="../../web-component-tester/browser.js"></script>
<!-- Step 1: import the element to test -->
<link rel="import" href="../<%= elementName %>.html">
</head>
<body>
- <<%= elementName %>></<%= elementName %>>
+ <<%= elementName %> id="fixture"></<%= elementName %>>
<script>
+ var myEl = document.getElementById('fixture');
- document.addEventListener('polymer-ready', function() {
- // Test a property
- var myEl = document.querySelector('<%= elementName %>');
- assert.equal(myEl.author, 'Dimitri Glazkov');
-
- // Test a method
- var hello = myEl.sayHello();
- assert.equal(hello, '<%= elementName %> says, Hello World!');
- var greetings = myEl.sayHello('greetings Earthlings');
- assert.equal(greetings, '<%= elementName %> says, greetings Earthlings');
-
- // Test an event
- myEl.addEventListener('<%= elementName %>-lasers-success', function(event) {
- assert.equal(event.detail.sound, 'Pew pew pew!');
- // IMPORTANT:
- // Make sure to call done() at the end of every test suite!
- done();
+ suite('<<%= elementName %>>', function() {
+
+ test('defines the "author" property', function() {
+ assert.equal(myEl.author, 'Dimitri Glazkov');
+ });
+
+ test('says hello', function() {
+ assert.equal(myEl.sayHello(), '<%= elementName %> says, Hello World!');
+ var greetings = myEl.sayHello('greetings Earthlings');
+ assert.equal(greetings, '<%= elementName %> says, greetings Earthlings');
});
- myEl.fireLasers();
- });
+ test('fires lasers', function(done) {
+ myEl.addEventListener('<%= elementName %>-lasers-success', function(event) {
+ assert.equal(event.detail.sound, 'Pew pew pew!');
+ done();
+ });
+ myEl.fireLasers();
+ });
+
+ });
</script>
</body>
@@ -1,20 +0,0 @@
-<link rel="import" href="../../polymer-test-tools/tools.html">
-
-<script src="../../polymer-test-tools/mocha-htmltest.js"></script>
-
-<script>
-
- mocha.setup({ui: 'tdd', slow: 1000, timeout: 5000, htmlbase: ''});
-
- // Below is a set of sample element test suites.
- // Replace these with your own suites of tests.
-
- htmlSuite('<%= elementName %>', function() {
- htmlTest('<%= elementName %>-basic.html');
- });
-
- // End sample test suites
-
- mocha.run();
-
-</script>
View
@@ -2,32 +2,24 @@
var path = require('path');
var helpers = require('yeoman-generator').test;
+var assert = require('yeoman-generator').assert;
describe('yo polymer:app test', function () {
- before(function (done) {
- helpers.testDirectory(path.join(__dirname, 'temp'), function (err) {
- if (err) {
- return done(err);
- }
-
- this.polymer = helpers.createGenerator('polymer:app', [
- '../../app', [
- helpers.createDummyGenerator(),
- 'mocha:app'
- ]
- ]);
- this.polymer.options['skip-install'] = true;
-
- done();
- }.bind(this));
- });
- it('the generator can be required without throwing', function () {
- // not testing the actual run of generators yet
- this.app = require('../app');
+ before(function (done) {
+ helpers.run(path.join(__dirname, '../app'))
+ .inDir(path.join(__dirname, './tmp'))
+ .withArguments(['--skip-install'])
+ .withPrompt({
+ includeCore: true,
+ includePaper: true,
+ includeSass: true,
+ includeLibSass: true
+ })
+ .on('end', done);
});
- it('creates expected files', function (done) {
+ it('creates expected files', function () {
var expected = [
'bower.json',
'package.json',
@@ -50,22 +42,11 @@ describe('yo polymer:app test', function () {
'app/elements/yo-list/yo-list.html',
'app/elements/yo-list/yo-list.scss',
'app/test/index.html',
- 'app/test/tests.html',
'app/test/yo-greeting-basic.html',
'app/test/yo-list-basic.html'
];
- helpers.mockPrompt(this.polymer, {
- includeCore: true,
- includePaper: true,
- includeSass: true,
- includeLibSass: true
- });
-
- this.polymer.run({}, function () {
- helpers.assertFiles(expected);
- done();
- });
+ assert.file(expected);
});
});
Oops, something went wrong.

0 comments on commit 7e1748a

Please sign in to comment.