forked from Polymer/polymer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PolymerLabs/testy
Start of unit tests (via WCT), and a bug fix
- Loading branch information
Showing
8 changed files
with
23,918 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../../web-component-tester/browser.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
WCT.loadSuites([ | ||
'unit/base.html', | ||
]); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../../../web-component-tester/browser.js"></script> | ||
<link rel="import" href="../../src/lang.html"> | ||
<link rel="import" href="../../src/base.html"> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
var OrigBase = window.Base; | ||
var Base; | ||
var Child; | ||
var instance; | ||
|
||
beforeEach(function() { | ||
// Ensure a clean environment for each test. | ||
Base = extend({}, OrigBase); | ||
Base._features = []; | ||
Child = Object.create(Base); | ||
instance = Object.create(Child); | ||
}); | ||
|
||
suite('addFeature', function() { | ||
|
||
test('mixes the feature into Base', function() { | ||
assert.notOk(Base.someProperty); | ||
Base.addFeature({someProperty: 123}); | ||
assert.equal(Base.someProperty, 123); | ||
}); | ||
|
||
// TODO(nevir): What's up with this behavior? | ||
test('kills init', function() { | ||
Base.init = function() {}; | ||
Base.addFeature({}); | ||
assert.notOk(Base.init); | ||
}); | ||
|
||
// TODO(nevir): Ditto above. | ||
test('kills register', function() { | ||
Base.register = function() {}; | ||
Base.addFeature({}); | ||
assert.notOk(Base.register); | ||
}); | ||
|
||
}); | ||
|
||
suite('registerCallback', function() { | ||
|
||
test('calls register() for any features', function() { | ||
var called = []; | ||
Base.addFeature({register: function() {called.push('one')}}); | ||
Base.addFeature({register: function() {called.push('two')}}); | ||
assert.deepEqual(called, []); | ||
|
||
Child.registerCallback(); | ||
assert.includeMembers(called, ['one', 'two']); | ||
}); | ||
|
||
test('passes the prototype to feature register()', function() { | ||
Base.addFeature({register: function(prototype) { | ||
assert.equal(prototype, Child); | ||
}}); | ||
Child.registerCallback(); | ||
}); | ||
|
||
// TODO(nevir): Pull sinon into WCT to make this sort of test cleaner. | ||
test('calls registered() after features', function() { | ||
var lastCalled = null; | ||
Base.addFeature({register: function() { | ||
assert.equal(lastCalled, null); | ||
lastCalled = 'feature'; | ||
}}); | ||
Child.registered = function() { | ||
assert.equal(lastCalled, 'feature'); | ||
lastCalled = 'registered'; | ||
}; | ||
|
||
Child.registerCallback(Base); | ||
assert.equal(lastCalled, 'registered'); | ||
}); | ||
|
||
}); | ||
|
||
suite('createdCallback', function() { | ||
|
||
// TODO(nevir): sinonify. | ||
test('calls lifecycle events in the proper order', function() { | ||
var lastCalled = null; | ||
Child.beforeCreated = function() { | ||
assert.equal(lastCalled, null); | ||
lastCalled = 'beforeCreated'; | ||
}; | ||
Base.addFeature({init: function() { | ||
assert.equal(lastCalled, 'beforeCreated'); | ||
lastCalled = 'feature'; | ||
}}); | ||
Child.created = function() { | ||
assert.equal(lastCalled, 'feature'); | ||
lastCalled = 'created'; | ||
}; | ||
Child.afterCreated = function() { | ||
assert.equal(lastCalled, 'created'); | ||
lastCalled = 'afterCreated'; | ||
}; | ||
|
||
instance.createdCallback(); | ||
assert.equal(lastCalled, 'afterCreated'); | ||
}); | ||
|
||
test('calls init() for any features', function() { | ||
var called = []; | ||
Base.addFeature({init: function() {called.push('one')}}); | ||
Base.addFeature({init: function() {called.push('two')}}); | ||
assert.deepEqual(called, []); | ||
|
||
instance.createdCallback(); | ||
assert.includeMembers(called, ['one', 'two']); | ||
}); | ||
|
||
test('calls feature init() with the correct `this`', function() { | ||
Base.addFeature({init: function() { | ||
assert.equal(this, instance); | ||
}}); | ||
instance.createdCallback(); | ||
}); | ||
|
||
}); | ||
|
||
suite('attachedCallback', function() { | ||
|
||
test('calls attached()', function() { | ||
var called = false; | ||
Child.attached = function() {called = true}; | ||
instance.attachedCallback(); | ||
assert.isTrue(called); | ||
}); | ||
|
||
}); | ||
|
||
suite('detachedCallback', function() { | ||
|
||
test('calls detached()', function() { | ||
var called = false; | ||
Child.detached = function() {called = true}; | ||
instance.detachedCallback(); | ||
assert.isTrue(called); | ||
}); | ||
|
||
}); | ||
|
||
suite('attributeChangedCallback', function() { | ||
|
||
test('calls attributeChanged()', function() { | ||
var args = null; | ||
Child.attributeChanged = function() {args = arguments}; | ||
instance.attributeChangedCallback('attr', null, 1, 'stuff'); | ||
|
||
assert.equal(args.length, 4); | ||
assert.equal(args[0], 'attr'); | ||
assert.equal(args[1], null); | ||
assert.equal(args[2], 1); | ||
assert.equal(args[3], 'stuff'); | ||
}); | ||
|
||
}); | ||
|
||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.