-
Notifications
You must be signed in to change notification settings - Fork 7
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 #1 from matthewp/complex
Implements CustomAttributeRegistry::get
- Loading branch information
Showing
3 changed files
with
76 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>get() tests</title> | ||
|
||
<script src="../node_modules/webcomponents.js/webcomponents-lite.min.js" defer></script> | ||
<script src="../attr.js" defer></script> | ||
<link rel="import" href="../node_modules/mocha-test/mocha-test.html" defer> | ||
</head> | ||
<body> | ||
<div id="fixture"></div> | ||
<mocha-test> | ||
<template> | ||
<script> | ||
describe('get()', function(){ | ||
function later(fn){ | ||
setTimeout(fn, 0); | ||
} | ||
|
||
afterEach(function(){ | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('gets the attribute instance', function(done){ | ||
class Foobar {} | ||
customAttributes.define('foo-bar', Foobar); | ||
|
||
var el = document.createElement('span'); | ||
el.setAttribute('foo-bar', 'baz'); | ||
fixture.appendChild(el); | ||
|
||
later(function(){ | ||
var fooBar = customAttributes.get(el, 'foo-bar'); | ||
assert.ok(fooBar instanceof Foobar); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('allows passing more complex data types', function(done){ | ||
class Foobar { | ||
set baz(val) { | ||
assert.equal(val, 'hello world'); | ||
done(); | ||
} | ||
} | ||
customAttributes.define('foo-bar', Foobar); | ||
|
||
var el = document.createElement('span'); | ||
el.setAttribute('foo-bar', 'bam'); | ||
fixture.appendChild(el); | ||
|
||
later(function(){ | ||
var fooBar = customAttributes.get(el, 'foo-bar'); | ||
fooBar.baz = 'hello world'; | ||
}); | ||
}); | ||
}); | ||
</script> | ||
</template> | ||
</mocha-test> | ||
</body> | ||
</html> |