浏览代码

Added a few more tests

This adds a test that makes sure that the inline data attribute
overrides the options that are passed in during initialization.

This also adds a test for the `createTag` option, which is used
when tagging.
Kevin Brown 10 年之前
父节点
当前提交
ff596e692e
共有 2 个文件被更改,包括 42 次插入1 次删除
  1. 29 1
      tests/data/tags-tests.js
  2. 13 0
      tests/options/data-tests.js

+ 29 - 1
tests/data/tags-tests.js

@@ -12,7 +12,7 @@ var options = new Options({
   tags: true
 });
 
-test('does not trigger on blank/null terms', function (assert) {
+test('does not trigger on blank or null terms', function (assert) {
   var data = new SelectTags($('#qunit-fixture .single'), options);
 
   data.query({
@@ -185,3 +185,31 @@ test('createTag returns null for no tag', function (assert) {
     assert.equal(data.results.length, 1);
   });
 });
+
+test('the createTag options customizes the function', function (assert) {
+  var data = new SelectTags(
+    $('#qunit-fixture .single'),
+    new Options({
+      tags: true,
+      createTag: function (params) {
+        return {
+          id: params.term,
+          text: params.term,
+          tag: true
+        };
+      }
+    })
+  );
+
+  data.query({
+    term: 'test'
+  }, function (data) {
+    assert.equal(data.results.length, 1);
+
+    var item = data.results[0];
+
+    assert.equal(item.id, 'test');
+    assert.equal(item.text, 'test');
+    assert.equal(item.tag, true);
+  });
+});

+ 13 - 0
tests/options/data-tests.js

@@ -18,3 +18,16 @@ test('with nesting', function (assert) {
   assert.ok(!(options.get('first-Second')));
   assert.equal(options.get('first').second, 'test');
 });
+
+test('overrides initialized data', function (assert) {
+  var $test = $('<select data-override="yes" data-data="yes"></select>');
+
+  var options = new Options({
+    options: 'yes',
+    override: 'no'
+  }, $test);
+
+  assert.equal(options.get('options'), 'yes');
+  assert.equal(options.get('override'), 'yes');
+  assert.equal(options.get('data'), 'yes');
+});