|
1 | 1 | describe('UNIT: Directives', function () {
|
| 2 | + |
| 3 | + var nextTick = require('vue/src/utils').nextTick, |
| 4 | + VM = require('vue/src/viewmodel') |
2 | 5 |
|
3 | 6 | describe('attr', function () {
|
4 | 7 |
|
@@ -644,9 +647,6 @@ describe('UNIT: Directives', function () {
|
644 | 647 | // this is mainly for code coverage
|
645 | 648 | describe('repeat', function () {
|
646 | 649 |
|
647 |
| - var nextTick = require('vue/src/utils').nextTick, |
648 |
| - VM = require('vue/src/viewmodel') |
649 |
| - |
650 | 650 | it('should work', function (done) {
|
651 | 651 | var handlerCalled = false
|
652 | 652 | var v = new Vue({
|
@@ -694,6 +694,92 @@ describe('UNIT: Directives', function () {
|
694 | 694 | }
|
695 | 695 | })
|
696 | 696 |
|
| 697 | + it('should work with primitive values', function () { |
| 698 | + var v = new Vue({ |
| 699 | + template: '<span v-repeat="tags" v-ref="tags">{{$value}}</span>', |
| 700 | + data: { |
| 701 | + tags: ['a', 'b', 'c'] |
| 702 | + } |
| 703 | + }) |
| 704 | + assert.strictEqual(v.$el.textContent, 'abc') |
| 705 | + v.$.tags[0].$value = 'd' |
| 706 | + assert.strictEqual(v.tags[0], 'd') |
| 707 | + }) |
| 708 | + |
| 709 | + it('should diff and reuse existing VMs when reseting arrays', function (done) { |
| 710 | + var v = new Vue({ |
| 711 | + template: '<span v-repeat="tags" v-ref="tags">{{$value}}</span>', |
| 712 | + data: { |
| 713 | + tags: ['a', 'b', 'c'] |
| 714 | + } |
| 715 | + }) |
| 716 | + var oldVMs = v.$.tags |
| 717 | + v.tags = v.tags.slice() |
| 718 | + nextTick(function () { |
| 719 | + assert.deepEqual(oldVMs, v.$.tags) |
| 720 | + done() |
| 721 | + }) |
| 722 | + }) |
| 723 | + |
| 724 | + it('should also work on objects', function (done) { |
| 725 | + var v = new Vue({ |
| 726 | + template: '<span v-repeat="obj">{{$key}} {{msg}}</span>', |
| 727 | + data: { |
| 728 | + obj: { |
| 729 | + a: { |
| 730 | + msg: 'hi!' |
| 731 | + }, |
| 732 | + b: { |
| 733 | + msg: 'ha!' |
| 734 | + } |
| 735 | + } |
| 736 | + } |
| 737 | + }) |
| 738 | + assert.strictEqual(v.$el.textContent, 'a hi!b ha!') |
| 739 | + |
| 740 | + v.obj.a.msg = 'ho!' |
| 741 | + |
| 742 | + nextTick(function () { |
| 743 | + assert.strictEqual(v.$el.textContent, 'a ho!b ha!') |
| 744 | + testAddKey() |
| 745 | + }) |
| 746 | + |
| 747 | + function testAddKey () { |
| 748 | + v.obj.$repeater.push({ $key: 'c', msg: 'he!' }) |
| 749 | + nextTick(function () { |
| 750 | + assert.strictEqual(v.$el.textContent, 'a ho!b ha!c he!') |
| 751 | + assert.strictEqual(v.obj.c.msg, 'he!') |
| 752 | + testRemoveKey() |
| 753 | + }) |
| 754 | + } |
| 755 | + |
| 756 | + function testRemoveKey () { |
| 757 | + v.obj.$repeater.shift() |
| 758 | + nextTick(function () { |
| 759 | + assert.strictEqual(v.$el.textContent, 'b ha!c he!') |
| 760 | + assert.strictEqual(v.obj.a, undefined) |
| 761 | + testSwap() |
| 762 | + }) |
| 763 | + } |
| 764 | + |
| 765 | + function testSwap () { |
| 766 | + v.obj.b = { msg: 'hehe' } |
| 767 | + nextTick(function () { |
| 768 | + assert.strictEqual(v.$el.textContent, 'b hehec he!') |
| 769 | + testRootSwap() |
| 770 | + }) |
| 771 | + } |
| 772 | + |
| 773 | + function testRootSwap () { |
| 774 | + v.obj = { b: { msg: 'wa'}, c: {msg: 'wo'} } |
| 775 | + nextTick(function () { |
| 776 | + assert.strictEqual(v.$el.textContent, 'b wac wo') |
| 777 | + done() |
| 778 | + }) |
| 779 | + } |
| 780 | + |
| 781 | + }) |
| 782 | + |
697 | 783 | })
|
698 | 784 |
|
699 | 785 | describe('style', function () {
|
@@ -758,6 +844,21 @@ describe('UNIT: Directives', function () {
|
758 | 844 |
|
759 | 845 | })
|
760 | 846 |
|
| 847 | + describe('data', function () { |
| 848 | + |
| 849 | + it('should set data on the child VM', function () { |
| 850 | + var v = new Vue({ |
| 851 | + template: '<div v-component="test" v-ref="test" v-data="a:1,b:hi"></div>', |
| 852 | + components: { |
| 853 | + test: Vue |
| 854 | + } |
| 855 | + }) |
| 856 | + assert.strictEqual(v.$.test.a, 1) |
| 857 | + assert.strictEqual(v.$.test.b, 'hi') |
| 858 | + }) |
| 859 | + |
| 860 | + }) |
| 861 | + |
761 | 862 | })
|
762 | 863 |
|
763 | 864 | function mockDirective (dirName, tag, type) {
|
|
0 commit comments