|
1 |
| -/* |
2 |
| - * Only tests directives in `src/directives/index.js` |
3 |
| - * and the non-delegated case for `v-on` |
4 |
| - * |
5 |
| - * The combination of `v-repeat` and `v-on` are covered in |
6 |
| - * the E2E test case for repeated items. |
7 |
| - */ |
8 |
| - |
9 | 1 | describe('UNIT: Directives', function () {
|
10 | 2 |
|
11 | 3 | describe('attr', function () {
|
@@ -637,6 +629,62 @@ describe('UNIT: Directives', function () {
|
637 | 629 |
|
638 | 630 | })
|
639 | 631 |
|
| 632 | + // More detailed testing for v-repeat can be found in functional tests. |
| 633 | + // this is mainly for code coverage |
| 634 | + describe('repeat', function () { |
| 635 | + |
| 636 | + var nextTick = require('vue/src/utils').nextTick, |
| 637 | + VM = require('vue/src/viewmodel') |
| 638 | + |
| 639 | + it('should work', function (done) { |
| 640 | + var handlerCalled = false |
| 641 | + var v = new Vue({ |
| 642 | + template: '<span v-repeat="items" v-on="click:check">{{title}}</span>', |
| 643 | + data: { |
| 644 | + items: [ |
| 645 | + {title: 1}, |
| 646 | + {title: 2} |
| 647 | + ] |
| 648 | + }, |
| 649 | + methods: { |
| 650 | + check: function (e) { |
| 651 | + assert.ok(e.targetVM instanceof VM) |
| 652 | + assert.strictEqual(this, v) |
| 653 | + handlerCalled = true |
| 654 | + } |
| 655 | + } |
| 656 | + }) |
| 657 | + nextTick(function () { |
| 658 | + assert.equal(v.$el.innerHTML, '<span>1</span><span>2</span><!--v-repeat-items-->') |
| 659 | + v.items.push({title:3}) |
| 660 | + v.items.pop() |
| 661 | + v.items.unshift({title:0}) |
| 662 | + v.items.shift() |
| 663 | + v.items.splice(0, 1, {title:-1}) |
| 664 | + v.items.sort(function (a, b) { |
| 665 | + return a.title > b.title |
| 666 | + }) |
| 667 | + v.items.reverse() |
| 668 | + nextTick(function () { |
| 669 | + assert.equal(v.$el.innerHTML, '<span>2</span><span>-1</span><!--v-repeat-items-->') |
| 670 | + testHandler() |
| 671 | + }) |
| 672 | + }) |
| 673 | + |
| 674 | + function testHandler () { |
| 675 | + document.getElementById('test').appendChild(v.$el) |
| 676 | + var span = v.$el.querySelector('span'), |
| 677 | + e = mockMouseEvent('click') |
| 678 | + span.dispatchEvent(e) |
| 679 | + nextTick(function () { |
| 680 | + assert.ok(handlerCalled) |
| 681 | + done() |
| 682 | + }) |
| 683 | + } |
| 684 | + }) |
| 685 | + |
| 686 | + }) |
| 687 | + |
640 | 688 | })
|
641 | 689 |
|
642 | 690 | function mockDirective (dirName, tag, type) {
|
|
0 commit comments