Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding a bunch more tests.

  • Loading branch information...
commit 10b591e9e9817a9df22b64bec59aea7f7b66e7ca 1 parent 9061ccd
@nrn authored
Showing with 67 additions and 2 deletions.
  1. +1 −1  readme.rst
  2. +4 −0 test.html
  3. +62 −1 test/factory.js
View
2  readme.rst
@@ -60,7 +60,7 @@ arguments.
dom elements, or a string name.
* [Optional] Data to be stored if a string name was used.
Can be a function that gets called with the elment as this, and the
- index of the element in the selection as the first argument.
+ element, index, and the entire selection as the arguments.
If there is both a name and data the function sets the appropriate data
on the dom and returns the selected elements. If a name is given but no data
View
4 test.html
@@ -19,5 +19,9 @@
</head>
<body>
<div id="mocha"></div>
+ <div id="test"></div>
+ <div id="obj"></div>
+ <div id="func" class="map"></div>
+ <div id="func1" class="map"></div>
</body>
</html>
View
63 test/factory.js
@@ -1,6 +1,6 @@
describe('factory', function () {
describe('#DataDash({noMethods: true})', function () {
- dataDash = DataDash({noMethods: true});
+ var dataDash = DataDash({noMethods: true});
it('should not add method to jQuery', function () {
expect(window.jQuery.fn.dataDash).to.not.exist;
});
@@ -24,3 +24,64 @@ describe('factory', function () {
});
});
});
+
+describe('String as name', function () {
+ describe('#$("#test").dataDash', function () {
+ it('Should set/get strings', function () {
+ $('#test').dataDash('asdf', 'qwert');
+ expect($('#test').dataDash('asdf')[0]).to.equal('qwert');
+ });
+ it('Should set/get numbers', function () {
+ $('#test').dataDash('num', 42);
+ expect($('#test').dataDash('num')[0]).to.equal(42);
+ });
+ it('Should set/get objects', function () {
+ $('#test').dataDash('obj', {foo: 'blah', bar: 123, nested: {asdf: 'test'}});
+ expect($('#test').dataDash('obj')[0]).to.eql({
+ foo: 'blah',
+ bar: 123,
+ nested: {asdf: 'test'}
+ });
+ });
+ it('Should set/get arrays', function () {
+ $('#test').dataDash('arr', ['asdf', 1234, ['netsted', 4321]]);
+ expect($('#test').dataDash('arr')[0]).to.eql(['asdf', 1234, ['netsted', 4321]]);
+ });
+ it('Should get everything', function () {
+ expect($('#test').dataDash()[0]).to.eql({
+ asdf: 'qwert',
+ num: 42,
+ obj:{foo: 'blah', bar: 123, nested: {asdf: 'test'}},
+ arr:['asdf', 1234, ['netsted', 4321]]
+ });
+ });
+ });
+});
+
+describe('Setting objects', function () {
+ describe('#$("#obj").dataDash()', function () {
+ it('Should set an entire object', function () {
+ var obj = {key: 'value', stuff: 3333, inside: ['blah', 16], hmm: {wee: 'asdf'}};
+ $('#obj').dataDash(obj);
+ expect($('#obj').dataDash()[0]).to.eql(obj);
+ });
+ });
+});
+
+describe('Setting by mapping', function () {
+ describe('#$(".map").dataDash("str", function (ele, idx, array) {};)', function () {
+ it('Should map a over a set of tags', function () {
+ var maper = function (ele, idx, sel) {
+ expect(ele).to.eql(sel[idx]);
+ expect(ele).to.eql(this);
+ return 'asdf' + idx;
+ };
+ $('.map').dataDash('asdf', maper);
+ expect($('.map').dataDash('asdf')).to.eql([
+ 'asdf0',
+ 'asdf1'
+ ]);
+ });
+ });
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.