Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2cade2

Browse filesBrowse files
authored
refactor: tidy up (#2051)
1 parent be11db6 commit f2cade2
Copy full SHA for f2cade2

12 files changed

+38
-36
lines changed

‎packages/create-instance/add-mocks.js

Copy file name to clipboardExpand all lines: packages/create-instance/add-mocks.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
import $$Vue from 'vue'
3-
import { warn } from 'shared/util'
3+
import { warn, keys } from 'shared/util'
44

55
export default function addMocks(
66
_Vue: Component,
@@ -9,7 +9,7 @@ export default function addMocks(
99
if (mockedProperties === false) {
1010
return
1111
}
12-
Object.keys(mockedProperties).forEach(key => {
12+
keys(mockedProperties).forEach(key => {
1313
try {
1414
// $FlowIgnore
1515
_Vue.prototype[key] = mockedProperties[key]

‎packages/create-instance/create-component-stubs.js

Copy file name to clipboardExpand all lines: packages/create-instance/create-component-stubs.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export function createStubsFromStubsObject(
195195
stubs: Object,
196196
_Vue: Component
197197
): Components {
198-
return Object.keys(stubs || {}).reduce((acc, stubName) => {
198+
return keys(stubs || {}).reduce((acc, stubName) => {
199199
let stub = stubs[stubName]
200200

201201
validateStub(stub)

‎packages/create-instance/create-instance.js

Copy file name to clipboardExpand all lines: packages/create-instance/create-instance.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { componentNeedsCompiling, isConstructor } from 'shared/validators'
1010
import createScopedSlots from './create-scoped-slots'
1111
import { createStubsFromStubsObject } from './create-component-stubs'
1212
import { patchCreateElement } from './patch-create-element'
13+
import { keys } from 'shared/util'
1314

1415
function createContext(options, scopedSlots, currentProps) {
1516
const on = {
@@ -86,8 +87,8 @@ export default function createInstance(
8687

8788
// watchers provided in mounting options should override preexisting ones
8889
if (componentOptions.watch && instanceOptions.watch) {
89-
const componentWatchers = Object.keys(componentOptions.watch)
90-
const instanceWatchers = Object.keys(instanceOptions.watch)
90+
const componentWatchers = keys(componentOptions.watch)
91+
const instanceWatchers = keys(instanceOptions.watch)
9192

9293
for (let i = 0; i < instanceWatchers.length; i++) {
9394
const k = instanceWatchers[i]

‎packages/shared/compile-template.js

Copy file name to clipboardExpand all lines: packages/shared/compile-template.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { compileToFunctions } from 'vue-template-compiler'
44
import { componentNeedsCompiling } from './validators'
5-
import { throwError } from './util'
5+
import { throwError, keys } from './util'
66

77
export function compileTemplate(component: Component): void {
88
if (component.template) {
@@ -31,7 +31,7 @@ export function compileTemplate(component: Component): void {
3131
}
3232

3333
if (component.components) {
34-
Object.keys(component.components).forEach(c => {
34+
keys(component.components).forEach(c => {
3535
const cmp = component.components[c]
3636
if (!cmp.render) {
3737
compileTemplate(cmp)
@@ -49,7 +49,7 @@ export function compileTemplate(component: Component): void {
4949
}
5050

5151
export function compileTemplateForSlots(slots: Object): void {
52-
Object.keys(slots).forEach(key => {
52+
keys(slots).forEach(key => {
5353
const slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]
5454
slot.forEach(slotValue => {
5555
if (componentNeedsCompiling(slotValue)) {

‎packages/shared/create-local-vue.js

Copy file name to clipboardExpand all lines: packages/shared/create-local-vue.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import Vue from 'vue'
44
import cloneDeep from 'lodash/cloneDeep'
5+
import { keys } from './util'
56

67
/**
78
* Used internally by vue-server-test-utils and test-utils to propagate/create vue instances.
@@ -17,7 +18,7 @@ function _createLocalVue(
1718
const instance = _Vue.extend()
1819

1920
// clone global APIs
20-
Object.keys(_Vue).forEach(key => {
21+
keys(_Vue).forEach(key => {
2122
if (!instance.hasOwnProperty(key)) {
2223
const original = _Vue[key]
2324
// cloneDeep can fail when cloning Vue instances

‎packages/shared/merge-options.js

Copy file name to clipboardExpand all lines: packages/shared/merge-options.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @flow
22
import { normalizeStubs, normalizeProvide } from './normalize'
3-
import { warnDeprecated } from 'shared/util'
3+
import { warnDeprecated, keys } from 'shared/util'
44

55
function getOption(option, config?: Object): any {
66
if (option === false) {
77
return false
88
}
9-
if (option || (config && Object.keys(config).length > 0)) {
9+
if (option || (config && keys(config).length > 0)) {
1010
if (option instanceof Function) {
1111
return option
1212
}
@@ -34,7 +34,7 @@ export function mergeOptions(
3434
const methods = (getOption(options.methods, config.methods): {
3535
[key: string]: Function
3636
})
37-
if (methods && Object.keys(methods).length) {
37+
if (methods && keys(methods).length) {
3838
warnDeprecated(
3939
'overwriting methods via the `methods` property',
4040
'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests'

‎packages/shared/validate-slots.js

Copy file name to clipboardExpand all lines: packages/shared/validate-slots.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import { throwError } from 'shared/util'
3+
import { throwError, keys } from 'shared/util'
44
import { compileToFunctions } from 'vue-template-compiler'
55
import { isVueComponent } from './validators'
66

@@ -19,7 +19,7 @@ function requiresTemplateCompiler(slot: any): void {
1919
}
2020

2121
export function validateSlots(slots: SlotsObject): void {
22-
Object.keys(slots).forEach(key => {
22+
keys(slots).forEach(key => {
2323
const slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]
2424

2525
slot.forEach(slotValue => {

‎packages/shared/validators.js

Copy file name to clipboardExpand all lines: packages/shared/validators.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import { throwError, capitalize, camelize, hyphenate } from './util'
2+
import { throwError, capitalize, camelize, hyphenate, keys } from './util'
33

44
export function isDomSelector(selector: any): boolean {
55
if (typeof selector !== 'string') {
@@ -64,7 +64,7 @@ export function componentNeedsCompiling(component: Component): boolean {
6464
export function isRefSelector(refOptionsObject: any): boolean {
6565
if (
6666
!isPlainObject(refOptionsObject) ||
67-
Object.keys(refOptionsObject || {}).length !== 1
67+
keys(refOptionsObject || {}).length !== 1
6868
) {
6969
return false
7070
}

‎packages/test-utils/src/create-dom-event.js

Copy file name to clipboardExpand all lines: packages/test-utils/src/create-dom-event.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import eventTypes from 'dom-event-types'
2+
import { keys } from 'shared/util'
23

34
const defaultEventType = {
45
eventInterface: 'Event',
@@ -108,7 +109,7 @@ export default function createDOMEvent(type, options) {
108109
: createOldEvent(eventParams)
109110

110111
const eventPrototype = Object.getPrototypeOf(event)
111-
Object.keys(options || {}).forEach(key => {
112+
keys(options || {}).forEach(key => {
112113
const propertyDescriptor = Object.getOwnPropertyDescriptor(
113114
eventPrototype,
114115
key

‎packages/test-utils/src/matches.js

Copy file name to clipboardExpand all lines: packages/test-utils/src/matches.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
FUNCTIONAL_OPTIONS
55
} from 'shared/consts'
66
import { isConstructor, isFunctionalComponent } from 'shared/validators'
7-
import { capitalize, camelize } from 'shared/util'
7+
import { capitalize, camelize, keys } from 'shared/util'
88

99
function vmMatchesName(vm, name) {
1010
// We want to mirror how Vue resolves component names in SFCs:
@@ -48,7 +48,7 @@ function vmCtorMatches(vm, component) {
4848
}
4949

5050
if (component.functional) {
51-
return Object.keys(vm._Ctor || {}).some(c => {
51+
return keys(vm._Ctor || {}).some(c => {
5252
return component === vm._Ctor[c].extendOptions
5353
})
5454
}

‎packages/test-utils/src/recursively-set-data.js

Copy file name to clipboardExpand all lines: packages/test-utils/src/recursively-set-data.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { isPlainObject } from 'shared/validators'
2+
import { keys } from 'shared/util'
23

34
export function recursivelySetData(vm, target, data) {
4-
Object.keys(data).forEach(key => {
5+
keys(data).forEach(key => {
56
const val = data[key]
67
const targetVal = target[key]
78

89
if (
910
isPlainObject(val) &&
1011
isPlainObject(targetVal) &&
11-
Object.keys(val).length > 0
12+
keys(val).length > 0
1213
) {
1314
recursivelySetData(vm, targetVal, val)
1415
} else {

‎packages/test-utils/src/wrapper.js

Copy file name to clipboardExpand all lines: packages/test-utils/src/wrapper.js
+13-15Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
nextTick,
1818
warn,
1919
warnDeprecated,
20-
isVueWrapper
20+
isVueWrapper,
21+
keys
2122
} from 'shared/util'
2223
import { isPlainObject } from 'shared/validators'
2324
import { isElementVisible } from 'shared/is-visible'
@@ -124,17 +125,14 @@ export default class Wrapper implements BaseWrapper {
124125
let classes = classAttribute ? classAttribute.split(' ') : []
125126
// Handle converting cssmodules identifiers back to the original class name
126127
if (this.vm && this.vm.$style) {
127-
const cssModuleIdentifiers = Object.keys(this.vm.$style).reduce(
128-
(acc, key) => {
129-
// $FlowIgnore
130-
const moduleIdent = this.vm.$style[key]
131-
if (moduleIdent) {
132-
acc[moduleIdent.split(' ')[0]] = key
133-
}
134-
return acc
135-
},
136-
{}
137-
)
128+
const cssModuleIdentifiers = keys(this.vm.$style).reduce((acc, key) => {
129+
// $FlowIgnore
130+
const moduleIdent = this.vm.$style[key]
131+
if (moduleIdent) {
132+
acc[moduleIdent.split(' ')[0]] = key
133+
}
134+
return acc
135+
}, {})
138136
classes = classes.map(name => cssModuleIdentifiers[name] || name)
139137
}
140138

@@ -480,7 +478,7 @@ export default class Wrapper implements BaseWrapper {
480478
const computed = this.vm._computedWatchers
481479
? formatJSON(
482480
// $FlowIgnore
483-
...Object.keys(this.vm._computedWatchers).map(computedKey => ({
481+
...keys(this.vm._computedWatchers).map(computedKey => ({
484482
// $FlowIgnore
485483
[computedKey]: this.vm[computedKey]
486484
}))
@@ -678,7 +676,7 @@ export default class Wrapper implements BaseWrapper {
678676
}
679677
this.__warnIfDestroyed()
680678

681-
Object.keys(methods).forEach(key => {
679+
keys(methods).forEach(key => {
682680
// $FlowIgnore : Problem with possibly null this.vm
683681
this.vm[key] = methods[key]
684682
// $FlowIgnore : Problem with possibly null this.vm
@@ -715,7 +713,7 @@ export default class Wrapper implements BaseWrapper {
715713

716714
this.__warnIfDestroyed()
717715

718-
Object.keys(data).forEach(key => {
716+
keys(data).forEach(key => {
719717
// Don't let people set entire objects, because reactivity won't work
720718
if (
721719
isPlainObject(data[key]) &&

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.