Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adding dataset test. #45

Open
wants to merge 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2012
  1. @mattwkelly

    Adding dataset test.

    mattwkelly authored
This page is out of date. Refresh to see the latest.
Showing with 108 additions and 0 deletions.
  1. +5 −0 tests/dataset/config.yml
  2. +103 −0 tests/dataset/test.js
View
5 tests/dataset/config.yml
@@ -0,0 +1,5 @@
+---
+ r: 2
+ spec: "http://www.w3.org/TR/html5/elements.html#embedding-custom-non-visible-data-with-the-data-attributes"
+ sources: ["http://www.w3c-test.org/html/tests/approved/dataset/dataset-get.html"]
+ title: "Custom Data Attributes"
View
103 tests/dataset/test.js
@@ -0,0 +1,103 @@
+test("Dataset", function() {
+ assert( !!document.createElement("div").dataset, "Dataset supported" );
+});
+
+test("Dataset Implementation", function() {
+ var DOMStringMap = window.DOMStringMap,
+ fixture = document.createElement("div"),
+ instance, length;
+
+ // Avoid exceptions in Android #278
+ if ( !fixture.dataset ) {
+ instance = false;
+ length = 0;
+ } else {
+ fixture.dataset.beta = "b";
+ instance = (fixture.dataset instanceof DOMStringMap);
+ length = Object.keys(fixture.dataset).length;
+ }
+
+ assert( instance, "fixture.dataset property is DOMStringMap" );
+ assert( length === 1, "fixture.dataset.length expects 1" );
+});
+
+test("Dataset Interop with Attributes", function() {
+ var fixture = document.createElement("div"),
+ attr, value;
+
+ // Avoid exceptions in Android #278
+ if ( !fixture.dataset ) {
+ attr = "";
+ value = "";
+ } else {
+ fixture.setAttribute( "data-alpha", "a" );
+ fixture.dataset.beta = "b";
+
+ attr = fixture.getAttribute("data-beta");
+ value = fixture.dataset.alpha;
+ }
+
+ assert( attr === "b", "fixture.getAttribute('data-beta') === 'b' (set with dataset)" );
+ assert( value === "a", "fixture.dataset.alpha === 'a' (set with setAttribute)" );
+});
+
+test("Dataset Get*", function() {
+ var fixture = document.createElement("div");
+
+ // Avoid exceptions in Android #278
+ if ( !fixture.dataset ) {
+ assert( false, "Dataset not supported, not running get* tests" );
+ } else {
+ fixture.setAttribute( "data-alpha", "a" );
+ fixture.dataset.beta = "b";
+
+ assert( fixture.getAttribute("data-beta") === "b", "compatible get with getAttribute" );
+ assert( fixture.dataset.alpha === "a", "compatible set with setAttribute" );
+
+ [
+ [ "data-foo", "foo" ],
+ [ "data-foo-bar", "fooBar" ],
+ [ "data--", "-" ],
+ [ "data--foo", "Foo" ],
+ [ "data---foo", "-Foo" ],
+ [ "data-Foo", "foo" ],
+ [ "data-", "" ],
+ [ "data-\xE0", "\xE0" ]
+ ].forEach(function( array, index ) {
+
+ var fixture = document.createElement("div"),
+ value = index + "";
+
+ fixture.setAttribute( array[0], index + "" );
+
+ assert( fixture.dataset[ array[1] ] === value, "Expected: " + array.join(" = ") );
+ });
+ }
+});
+
+test("Dataset Enumerable", function() {
+ var fixture = document.createElement("div"),
+ actuals = [ "hello", "helloWorld", "ohHai" ],
+ length = actuals.length,
+ prop;
+
+ // Avoid exceptions in Android #278
+ if ( !fixture.dataset ) {
+ assert( false, "Dataset not supported, not running Enumerable tests" );
+ } else {
+ fixture.setAttribute( "data-hello", 1 );
+ fixture.setAttribute( "data-hello-world", 2 );
+ fixture.setAttribute( "data-oh-hai", 2 );
+
+ // This fails b/c Object.propertyIsEnumerable returns false...
+ // turns out these properties don't have property descriptors
+ // assert( Object.propertyIsEnumerable(fixture.dataset.ohHai) );
+ for ( prop in fixture.dataset ) {
+ actuals.splice( actuals.indexOf( prop ), 1 );
+ length--;
+ assert( actuals.length === length, prop );
+ }
+
+ assert( !actuals.length, "Expecting length === 0" );
+ }
+});
Something went wrong with that request. Please try again.