Skip to content

Commit

Permalink
test: all features except transition pass
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 20, 2022
1 parent 906907f commit 73bcd07
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 202 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ packages/vue-template-compiler/build.js
packages/vue-template-compiler/browser.js
.vscode
dist
debug.spec.ts
6 changes: 4 additions & 2 deletions test/helpers/to-have-warned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { SpyInstance } from 'vitest'
expect.extend({
toHaveBeenWarned(received: string) {
asserted.add(received)
const passed = warn.mock.calls.some((args) => args[0].includes(received))
const passed = warn.mock.calls.some((args) =>
String(args[0]).includes(received)
)
if (passed) {
return {
pass: true,
Expand Down Expand Up @@ -102,7 +104,7 @@ afterEach(() => {
.map((args) => args[0])
.filter((received) => {
return !assertedArray.some((assertedMsg) => {
return received.includes(assertedMsg)
return String(received).includes(assertedMsg)
})
})
warn.mockRestore()
Expand Down
4 changes: 2 additions & 2 deletions test/ssr/ssr-bundle-render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function createAssertions (runInNewContext) {
expect(err).toBeNull()
expect(res).toBe(expected)
expect(get).toHaveBeenCalledWith(key)
const setArgs = set.calls.argsFor(0)
const setArgs = set.mock.calls[0]
expect(setArgs[0]).toBe(key)
expect(setArgs[1].html).toBe(expected)
expect(cache[key].html).toBe(expected)
Expand Down Expand Up @@ -178,7 +178,7 @@ function createAssertions (runInNewContext) {
expect(res).toBe(expected)
expect(has).toHaveBeenCalledWith(key)
expect(get).not.toHaveBeenCalled()
const setArgs = set.calls.argsFor(0)
const setArgs = set.mock.calls[0]
expect(setArgs[0]).toBe(key)
expect(setArgs[1].html).toBe(expected)
expect(cache[key].html).toBe(expected)
Expand Down
7 changes: 3 additions & 4 deletions test/unit/features/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { formatComponentName, warn } from 'core/util/debug'

describe('Debug utilities', () => {
it('properly format component names', () => {
// @ts-expect-error
const vm = new Vue()
expect(formatComponentName(vm)).toBe('<Root>')

Expand Down Expand Up @@ -84,15 +83,15 @@ found in

describe('warn', () => {
const msg = 'message'
// @ts-expect-error
const vm = new Vue()

it('calls warnHandler if warnHandler is set', () => {
Vue.config.warnHandler = vi.fn()
const spy = Vue.config.warnHandler = vi.fn()

warn(msg, vm)

expect(Vue.config.warnHandler).toHaveBeenCalledWith(msg, vm, jasmine.any(String))
expect(spy.mock.calls[0][0]).toBe(msg)
expect(spy.mock.calls[0][1]).toBe(vm)

// @ts-expect-error
Vue.config.warnHandler = null
Expand Down
3 changes: 1 addition & 2 deletions test/unit/features/error-handling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('Error handling', () => {
const spy = Vue.config.errorHandler = vi.fn()
const vm = createTestInstance(components.render)

const args = spy.calls.argsFor(0)
const args = spy.mock.calls[0]
expect(args[0].toString()).toContain('Error: render') // error
expect(args[1]).toBe(vm.$refs.child) // vm
expect(args[2]).toContain('render') // description
Expand All @@ -170,7 +170,6 @@ describe('Error handling', () => {
Vue.nextTick(() => {
expect(spy).toHaveBeenCalledWith(err1, undefined, 'nextTick')

// @ts-expect-error
const vm = new Vue()
vm.$nextTick(() => { throw err2 })
Vue.nextTick(() => {
Expand Down
2 changes: 0 additions & 2 deletions test/unit/features/instance/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import Vue from 'vue'

describe('Initialization', () => {
it('without new', () => {
// @ts-expect-error
try { Vue() } catch (e) {}
expect('Vue is a constructor and should be called with the `new` keyword').toHaveBeenWarned()
})

it('with new', () => {
// @ts-expect-error
expect(new Vue() instanceof Vue).toBe(true)
})
})
3 changes: 1 addition & 2 deletions test/unit/features/instance/methods-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import Vue from 'vue'
describe('Instance methods events', () => {
let vm, spy
beforeEach(() => {
// @ts-expect-error
const vm = new Vue()
vm = new Vue({})
spy = vi.fn()
})

Expand Down
4 changes: 2 additions & 2 deletions test/unit/features/instance/methods-lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ describe('Instance methods lifecycle', () => {
})

it('Dep.target should be undefined in lifecycle', () => {
const vm = new Vue({
new Vue({
template: '<div><my-component></my-component></div>',
components: {
myComponent: {
template: '<div>hi</div>',
mounted () {
const _msg = this.msg
this.msg
expect(Dep.target).toBe(undefined)
},
computed: {
Expand Down
6 changes: 2 additions & 4 deletions test/unit/features/instance/properties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('Instance properties', () => {
b () {}
}
})
expect(typeof vm.$options.methods.a).toBe('function')
expect(typeof vm.$options.methods.b).toBe('function')
expect(typeof vm.$options.methods?.a).toBe('function')
expect(typeof vm.$options.methods?.b).toBe('function')
})

it('$root/$children', done => {
Expand Down Expand Up @@ -161,7 +161,6 @@ describe('Instance properties', () => {
})

it('warn mutating $attrs', () => {
// @ts-expect-error
const vm = new Vue()
vm.$attrs = {}
expect(`$attrs is readonly`).toHaveBeenWarned()
Expand Down Expand Up @@ -197,7 +196,6 @@ describe('Instance properties', () => {
})

it('warn mutating $listeners', () => {
// @ts-expect-error
const vm = new Vue()
vm.$listeners = {}
expect(`$listeners is readonly`).toHaveBeenWarned()
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/options/data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Options data', () => {
})

it('should merge data properly', () => {
const Test: Vue = Vue.extend({
const Test = Vue.extend({
data () {
return { a: 1 }
}
Expand Down
13 changes: 7 additions & 6 deletions test/unit/features/options/directives.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SpyInstanceFn } from 'vitest'
import Vue from 'vue'

describe('Options directives', () => {
Expand Down Expand Up @@ -152,7 +153,7 @@ describe('Options directives', () => {
})

it('should properly handle same node with different directive sets', done => {
const spies = {}
const spies: Record<string, SpyInstanceFn> = {}
const createSpy = name => (spies[name] = vi.fn())
const vm = new Vue({
data: {
Expand Down Expand Up @@ -249,20 +250,20 @@ describe('Options directives', () => {

const oldEl = vm.$el
expect(dir.bind.mock.calls.length).toBe(1)
expect(dir.bind.calls.argsFor(0)[0]).toBe(oldEl)
expect(dir.bind.mock.calls[0][0]).toBe(oldEl)
expect(dir.inserted.mock.calls.length).toBe(1)
expect(dir.inserted.calls.argsFor(0)[0]).toBe(oldEl)
expect(dir.inserted.mock.calls[0][0]).toBe(oldEl)
expect(dir.unbind).not.toHaveBeenCalled()

vm.$refs.child.ok = false
waitForUpdate(() => {
expect(vm.$el.tagName).toBe('SPAN')
expect(dir.bind.mock.calls.length).toBe(2)
expect(dir.bind.calls.argsFor(1)[0]).toBe(vm.$el)
expect(dir.bind.mock.calls[1][0]).toBe(vm.$el)
expect(dir.inserted.mock.calls.length).toBe(2)
expect(dir.inserted.calls.argsFor(1)[0]).toBe(vm.$el)
expect(dir.inserted.mock.calls[1][0]).toBe(vm.$el)
expect(dir.unbind.mock.calls.length).toBe(1)
expect(dir.unbind.calls.argsFor(0)[0]).toBe(oldEl)
expect(dir.unbind.mock.calls[0][0]).toBe(oldEl)
}).then(done)
})

Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/options/functional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Options functional', () => {
document.body.appendChild(vm.$el)
triggerEvent(vm.$el.children[0], 'click')
expect(foo).toHaveBeenCalled()
expect(foo.calls.argsFor(0)[0].type).toBe('click') // should have click event
expect(foo.mock.calls[0][0].type).toBe('click') // should have click event
triggerEvent(vm.$el.children[0], 'mousedown')
expect(bar).toHaveBeenCalledWith('bar')
document.body.removeChild(vm.$el)
Expand Down
3 changes: 1 addition & 2 deletions test/unit/features/options/lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ describe('Options lifecycle hooks', () => {

// #3898
it('should call for manually mounted instance with parent', () => {
// @ts-expect-error
const vm = new Vue()
const parent = new Vue()
expect(spy).not.toHaveBeenCalled()
new Vue({
parent,
Expand Down
14 changes: 7 additions & 7 deletions test/unit/features/options/mixins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ describe('Options mixins', () => {
})
expect(result.a).toBe(1)
expect(result.b).toBe(1)
expect(result.directives.a).toBe(a)
expect(result.directives.b).toBe(b)
expect(result.directives.c).toBe(c)
expect(result.created[0]).toBe(f1)
expect(result.created[1]).toBe(f2)
expect(result.created[2]).toBe(f3)
expect(result.directives?.a).toBe(a)
expect(result.directives?.b).toBe(b)
expect(result.directives?.c).toBe(c)
expect(result.created?.[0]).toBe(f1)
expect(result.created?.[1]).toBe(f2)
expect(result.created?.[2]).toBe(f3)
expect(result.template).toBe('bar')
})

Expand All @@ -85,7 +85,7 @@ describe('Options mixins', () => {
xyz: f3
}
})
expect(result.methods.xyz).toBe(f3)
expect(result.methods?.xyz).toBe(f3)
})

it('should accept constructors as mixins', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/options/name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Options name', () => {
it('id should not override given name when using Vue.component', () => {
const SuperComponent = Vue.component('super-component', {
name: 'SuperVue'
})
})!

expect(SuperComponent.options.components['SuperVue']).toEqual(SuperComponent)
expect(SuperComponent.options.components['super-component']).toEqual(SuperComponent)
Expand Down
Loading

0 comments on commit 73bcd07

Please sign in to comment.