github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/themes/wind/static/libs/vue-1.0.24/test/unit/specs/global_api_spec.js (about)

     1  var Vue = require('src')
     2  var _ = require('src/util')
     3  var config = require('src/config')
     4  var transition = require('src/transition')
     5  
     6  describe('Global API', function () {
     7    it('exposed utilities', function () {
     8      expect(Vue.util).toBe(_)
     9      expect(Vue.nextTick).toBe(_.nextTick)
    10      expect(Vue.config).toBe(config)
    11      expect(Vue.transition.applyTransition).toBe(transition.applyTransition)
    12    })
    13  
    14    it('extend', function () {
    15      var Test = Vue.extend({
    16        name: 'test',
    17        a: 1,
    18        b: 2
    19      })
    20      expect(Test.options.a).toBe(1)
    21      expect(Test.options.b).toBe(2)
    22      expect(Test.super).toBe(Vue)
    23      // function.name is not available in IE
    24      expect(Test.toString().match(/^function Test\s?\(/)).toBeTruthy()
    25      var t = new Test({
    26        a: 2
    27      })
    28      expect(t.$options.a).toBe(2)
    29      expect(t.$options.b).toBe(2)
    30      // inheritance
    31      var Test2 = Test.extend({
    32        a: 2
    33      })
    34      expect(Test2.options.a).toBe(2)
    35      expect(Test2.options.b).toBe(2)
    36      var t2 = new Test2({
    37        a: 3
    38      })
    39      expect(t2.$options.a).toBe(3)
    40      expect(t2.$options.b).toBe(2)
    41    })
    42  
    43    it('extend warn invalid names', function () {
    44      Vue.extend({ name: '123' })
    45      expect('Invalid component name: "123"').toHaveBeenWarned()
    46      Vue.extend({ name: '_fesf' })
    47      expect('Invalid component name: "_fesf"').toHaveBeenWarned()
    48      Vue.extend({ name: 'Some App' })
    49      expect('Invalid component name: "Some App"').toHaveBeenWarned()
    50    })
    51  
    52    it('use', function () {
    53      var def = {}
    54      var options = {}
    55      var pluginStub = {
    56        install: function (Vue, opts) {
    57          Vue.directive('plugin-test', def)
    58          expect(opts).toBe(options)
    59        }
    60      }
    61      Vue.use(pluginStub, options)
    62      expect(Vue.options.directives['plugin-test']).toBe(def)
    63      delete Vue.options.directives['plugin-test']
    64      // use a function
    65      Vue.use(pluginStub.install, options)
    66      expect(Vue.options.directives['plugin-test']).toBe(def)
    67      delete Vue.options.directives['plugin-test']
    68    })
    69  
    70    it('global mixin', function () {
    71      var options = Vue.options
    72      var spy = jasmine.createSpy('global mixin')
    73      Vue.mixin({
    74        created: function () {
    75          spy(this.$options.myOption)
    76        }
    77      })
    78      new Vue({
    79        myOption: 'hello'
    80      })
    81      expect(spy).toHaveBeenCalledWith('hello')
    82      Vue.options = options
    83    })
    84  
    85    describe('Asset registration', function () {
    86      var Test = Vue.extend()
    87  
    88      it('directive / elementDirective / filter / transition', function () {
    89        var assets = ['directive', 'elementDirective', 'filter', 'transition']
    90        assets.forEach(function (type) {
    91          var def = {}
    92          Test[type]('test', def)
    93          expect(Test.options[type + 's'].test).toBe(def)
    94          expect(Test[type]('test')).toBe(def)
    95          // extended registration should not pollute global
    96          expect(Vue.options[type + 's'].test).toBeUndefined()
    97        })
    98      })
    99  
   100      it('component', function () {
   101        var def = { a: 1 }
   102        Test.component('test', def)
   103        var component = Test.options.components.test
   104        expect(typeof component).toBe('function')
   105        expect(component.super).toBe(Vue)
   106        expect(component.options.a).toBe(1)
   107        expect(component.options.name).toBe('test')
   108        expect(Test.component('test')).toBe(component)
   109        // already extended
   110        Test.component('test2', component)
   111        expect(Test.component('test2')).toBe(component)
   112        // extended registration should not pollute global
   113        expect(Vue.options.components.test).toBeUndefined()
   114      })
   115    })
   116  })