| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- var _ = require('../../../../src/util')
- var Vue = require('../../../../src/vue')
- if (_.inBrowser) {
- describe('prop', function () {
- var el
- beforeEach(function () {
- el = document.createElement('div')
- spyOn(_, 'warn')
- })
- it('should work', function (done) {
- var vm = new Vue({
- el: el,
- data: {
- b: 'B',
- test: {
- a: 'A'
- }
- },
- template: '<div v-component="test" testt="{{test}}" bb="{{b}}" v-ref="child"></div>',
- components: {
- test: {
- props: ['testt', 'bb'],
- template: '{{testt.a}} {{bb}}'
- }
- }
- })
- expect(el.firstChild.textContent).toBe('A B')
- vm.test.a = 'AA'
- vm.b = 'BB'
- _.nextTick(function () {
- expect(el.firstChild.textContent).toBe('AA BB')
- vm.test = { a: 'AAA' }
- _.nextTick(function () {
- expect(el.firstChild.textContent).toBe('AAA BB')
- vm.$data = {
- b: 'BBB',
- test: {
- a: 'AAAA'
- }
- }
- _.nextTick(function () {
- expect(el.firstChild.textContent).toBe('AAAA BBB')
- // test two-way
- vm.$.child.bb = 'B'
- vm.$.child.testt = { a: 'A' }
- _.nextTick(function () {
- expect(el.firstChild.textContent).toBe('A B')
- expect(vm.test.a).toBe('A')
- expect(vm.test).toBe(vm.$.child.testt)
- expect(vm.b).toBe('B')
- done()
- })
- })
- })
- })
- })
- it('teardown', function (done) {
- var vm = new Vue({
- el: el,
- data: {
- b: 'B'
- },
- template: '<div v-component="test" bb="{{b}}"></div>',
- components: {
- test: {
- props: ['bb'],
- template: '{{bb}}'
- }
- }
- })
- expect(el.firstChild.textContent).toBe('B')
- vm.b = 'BB'
- _.nextTick(function () {
- expect(el.firstChild.textContent).toBe('BB')
- vm._children[0]._directives[0].unbind()
- vm.b = 'BBB'
- _.nextTick(function () {
- expect(el.firstChild.textContent).toBe('BB')
- done()
- })
- })
- })
- it('block instance with replace:true', function () {
- var vm = new Vue({
- el: el,
- template: '<div v-component="test" b="{{a}}" c="{{d}}"></div>',
- data: {
- a: 'AAA',
- d: 'DDD'
- },
- components: {
- test: {
- props: ['b', 'c'],
- template: '<p>{{b}}</p><p>{{c}}</p>',
- replace: true
- }
- }
- })
- expect(el.innerHTML).toBe('<!--v-start--><p>AAA</p><p>DDD</p><!--v-end--><!--v-component-->')
- })
- })
- }
|