Skip to content

Commit 4b8eb75

Browse files
committed
fix coverage
1 parent 4314f45 commit 4b8eb75

File tree

7 files changed

+56
-9
lines changed

7 files changed

+56
-9
lines changed

src/platforms/web/runtime/class-util.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/* @flow */
22

3-
import { warn } from 'core/util/index'
4-
53
/**
64
* Add class with compatibility for SVG since classList is not supported on
75
* SVG elements in IE
86
*/
97
export function addClass (el: Element, cls: ?string) {
10-
if (!cls || cls.trim() === '') {
11-
process.env.NODE_ENV !== 'production' && warn('Ignoring empty class name.')
8+
/* istanbul ignore if */
9+
if (!cls || !cls.trim()) {
1210
return
1311
}
1412

@@ -32,8 +30,8 @@ export function addClass (el: Element, cls: ?string) {
3230
* SVG elements in IE
3331
*/
3432
export function removeClass (el: Element, cls: ?string) {
35-
if (!cls || cls.trim() === '') {
36-
process.env.NODE_ENV !== 'production' && warn('Ignoring empty class name.')
33+
/* istanbul ignore if */
34+
if (!cls || !cls.trim()) {
3735
return
3836
}
3937

src/platforms/web/runtime/modules/style.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
import { cached, extend, camelize, toObject } from 'shared/util'
44

5+
const cssVarRE = /^--/
6+
const setProp = (el, name, val) => {
7+
/* istanbul ignore if */
8+
if (cssVarRE.test(name)) {
9+
el.style.setProperty(name, val)
10+
} else {
11+
el.style[normalize(name)] = val
12+
}
13+
}
14+
515
const prefixes = ['Webkit', 'Moz', 'ms']
616

717
let testEl
@@ -50,14 +60,14 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {
5060

5161
for (name in oldStyle) {
5262
if (style[name] == null) {
53-
el.style[normalize(name)] = ''
63+
setProp(el, name, '')
5464
}
5565
}
5666
for (name in style) {
5767
cur = style[name]
5868
if (cur !== oldStyle[name]) {
5969
// ie9 setting to null has no effect, must use empty string
60-
el.style[normalize(name)] = cur == null ? '' : cur
70+
setProp(el, name, cur == null ? '' : cur)
6171
}
6272
}
6373
}

src/platforms/web/runtime/transition-util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function getTransitionInfo (el: Element, expectedType?: ?string): {
131131
}
132132

133133
function getTimeout (delays: Array<string>, durations: Array<string>): number {
134+
/* istanbul ignore next */
134135
while (delays.length < durations.length) {
135136
delays = delays.concat(delays)
136137
}

src/platforms/web/util/attrs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ const isAttr = makeMap(
3333
)
3434

3535
/* istanbul ignore next */
36-
export const isRenderableAttr = (name: string): boolean => {
36+
const isRenderableAttr = (name: string): boolean => {
3737
return (
3838
isAttr(name) ||
3939
name.indexOf('data-') === 0 ||
4040
name.indexOf('aria-') === 0
4141
)
4242
}
43+
export { isRenderableAttr }
4344

4445
export const propsToAttrMap = {
4546
acceptCharset: 'accept-charset',

src/platforms/web/util/model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default function parseModel (val: string): Object {
3030

3131
while (!eof()) {
3232
chr = next()
33+
/* istanbul ignore if */
3334
if (isStringStart(chr)) {
3435
parseString(chr)
3536
} else if (chr === 0x5B) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import parseModel from 'web/util/model'
2+
3+
describe('model expression parser', () => {
4+
it('parse string in brackets', () => {
5+
const res = parseModel('a["b"][c]')
6+
expect(res.exp).toBe('a["b"]')
7+
expect(res.idx).toBe('c')
8+
})
9+
10+
it('parse nested brackets', () => {
11+
const res = parseModel('a[i[c]]')
12+
expect(res.exp).toBe('a')
13+
expect(res.idx).toBe('i[c]')
14+
})
15+
16+
it('combined', () => {
17+
const res = parseModel('test.xxx.a["asa"][test1[idx]]')
18+
expect(res.exp).toBe('test.xxx.a["asa"]')
19+
expect(res.idx).toBe('test1[idx]')
20+
})
21+
})

test/unit/features/directives/style.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,19 @@ describe('Directive v-bind:style', () => {
151151
expect(vm.$el.style.fontSize).toBe('16px')
152152
}).then(done)
153153
})
154+
155+
const supportCssVariable = () => {
156+
const el = document.createElement('div')
157+
el.style.setProperty('--color', 'red')
158+
return el.style.getPropertyValue('--color') === 'red'
159+
}
160+
161+
if (supportCssVariable()) {
162+
it('CSS variables', done => {
163+
vm.styles = { '--color': 'red' }
164+
waitForUpdate(() => {
165+
expect(vm.$el.style.getPropertyValue('--color')).toBe('red')
166+
}).then(done)
167+
})
168+
}
154169
})

0 commit comments

Comments
 (0)