github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/vue-1.0.24/test/unit/specs/directives/internal/class_spec.js (about)

     1  var _ = require('src/util')
     2  var def = require('src/directives/internal/class')
     3  
     4  describe(':class', function () {
     5    var el
     6    beforeEach(function () {
     7      el = document.createElement('div')
     8    })
     9  
    10    it('plain string', function () {
    11      el.className = 'foo'
    12      var dir = _.extend({ el: el }, def)
    13      dir.update('bar')
    14      expect(el.className).toBe('foo bar')
    15      dir.update('baz qux')
    16      expect(el.className).toBe('foo baz qux')
    17      dir.update('qux')
    18      expect(el.className).toBe('foo qux')
    19      dir.update()
    20      expect(el.className).toBe('foo')
    21    })
    22  
    23    it('object value', function () {
    24      el.className = 'foo'
    25      var dir = _.extend({ el: el }, def)
    26      dir.update({
    27        bar: true,
    28        baz: false
    29      })
    30      expect(el.className).toBe('foo bar')
    31      dir.update({
    32        baz: true
    33      })
    34      expect(el.className).toBe('foo baz')
    35      dir.update(null)
    36      expect(el.className).toBe('foo')
    37  
    38      dir.update({
    39        'bar baz': true,
    40        qux: false
    41      })
    42      expect(el.className).toBe('foo bar baz')
    43      dir.update({
    44        qux: true
    45      })
    46      expect(el.className).toBe('foo qux')
    47    })
    48  
    49    it('array value', function () {
    50      el.className = 'a'
    51      var dir = _.extend({ el: el }, def)
    52      dir.update(['b', 'c'])
    53      expect(el.className).toBe('a b c')
    54      dir.update(['d', 'c'])
    55      expect(el.className).toBe('a c d')
    56      dir.update(['w', 'x y z'])
    57      expect(el.className).toBe('a w x y z')
    58      dir.update()
    59      expect(el.className).toBe('a')
    60      // test mutating array
    61      var arr = ['e', '']
    62      dir.update(arr)
    63      expect(el.className).toBe('a e')
    64      arr.length = 0
    65      arr.push('f')
    66      dir.update(arr)
    67      expect(el.className).toBe('a f')
    68      // test array with objects
    69      dir.update(['x', { y: true, z: true }])
    70      expect(el.className).toBe('a x y z')
    71      dir.update(['x', { y: true, z: false }])
    72      expect(el.className).toBe('a x y')
    73      dir.update(['f', { z: true }])
    74      expect(el.className).toBe('a f z')
    75      dir.update(['l', 'f', { n: true, z: true }])
    76      expect(el.className).toBe('a f z l n')
    77      dir.update(['x', {}])
    78      expect(el.className).toBe('a x')
    79      dir.update()
    80      expect(el.className).toBe('a')
    81    })
    82  })