Skip to content

Commit

Permalink
Merge pull request #19 from 43081j/more-tests
Browse files Browse the repository at this point in the history
add more tests
  • Loading branch information
aomarks authored Nov 22, 2017
2 parents 0e11db5 + def63af commit 9bcac25
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*]
indent_size = 2
indent_style = space
6 changes: 5 additions & 1 deletion src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export function customElement(tagname?: string) {
// TODO Investigate narrowing down the type of clazz.
return (clazz: any) => {
// TODO(justinfagnani): we could also use the kebab-cased class name
tagname = clazz.is = clazz.is || tagname;
if (clazz.is) {
tagname = clazz.is;
} else {
clazz.is = tagname;
}
window.customElements.define(tagname!, clazz);
}
}
Expand Down
9 changes: 8 additions & 1 deletion test/integration/decorators.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="bower_components/reflect-metadata/Reflect.js"></script>
<script src="bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="./test-element.html">
<link rel="import" href="./elements/test-element.html">
<link rel="import" href="./elements/element-with-is.html">
</head>
<body>

Expand All @@ -25,6 +26,12 @@
</template>
</test-fixture>

<test-fixture id="element-with-is">
<template>
<element-with-is></element-with-is>
</template>
</test-fixture>

<script src="decorators.js"></script>

</body>
Expand Down
28 changes: 28 additions & 0 deletions test/integration/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ suite('TypeScript Decorators', function() {
chai.assert.instanceOf(testElement, TestElement);
});

test('defines an element with an "is" getter', function() {
const el = fixture('element-with-is') as ElementWithIs;
chai.assert.instanceOf(el, ElementWithIs);
});
});

suite('@property', function() {
Expand All @@ -34,6 +38,30 @@ suite('TypeScript Decorators', function() {
chai.assert.equal(numText, '999');
});

test('notify property should fire events', function() {
let fired = false;
const fn = function() {
fired = true;
};

testElement.addEventListener('a-num-changed', fn);
testElement.aNum = 999;
chai.assert.equal(fired, true);
testElement.removeEventListener('a-num-changed', fn);
});

test('notify should default to false', function() {
let fired = false;
const fn = function() {
fired = true;
};

testElement.addEventListener('doesnt-notify-changed', fn);
testElement.doesntNotify = false;
chai.assert.equal(fired, false);
testElement.removeEventListener('doesnt-notify-changed', fn);
});

test('reflectToAttribute property should be reflected as an attribute', function() {
testElement.reflectedString = "nice";
const attributeText = testElement.getAttribute('reflected-string');
Expand Down
4 changes: 4 additions & 0 deletions test/integration/elements/element-with-is.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/polymer-decorators/polymer-decorators.html">

<script src="./element-with-is.js"></script>
17 changes: 17 additions & 0 deletions test/integration/elements/element-with-is.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt The complete set of authors may be found
* at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
* be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
* Google as part of the polymer project is also subject to an additional IP
* rights grant found at http://polymer.github.io/PATENTS.txt
*/

/// <reference path="../bower_components/polymer-decorators/global.d.ts" />

@Polymer.decorators.customElement()
class ElementWithIs extends Polymer.Element {
public static get is() { return 'element-with-is'; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<link rel="import" href="bower_components/polymer/polymer-element.html">
<link rel="import" href="bower_components/polymer-decorators/polymer-decorators.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/polymer-decorators/polymer-decorators.html">

<dom-module id="test-element">
<template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* rights grant found at http://polymer.github.io/PATENTS.txt
*/

/// <reference path="bower_components/polymer-decorators/global.d.ts" />
/// <reference path="../bower_components/polymer-decorators/global.d.ts" />

const {customElement, property, query, queryAll, observe} = Polymer.decorators;

Expand All @@ -18,6 +18,9 @@ class TestElement extends Polymer.Element {
@property({notify: true})
aNum: number = 42;

@property()
doesntNotify: boolean = true;

@property({notify: true})
aString: string = 'yes';

Expand Down
3 changes: 2 additions & 1 deletion test/integration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"emitDecoratorMetadata": true
},
"include": [
"*.ts"
"*.ts",
"elements/*.ts"
]
}

0 comments on commit 9bcac25

Please sign in to comment.