Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kaorun343 committed Sep 2, 2017
1 parent 97817e5 commit 1d9e2f8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/vue-property-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function Model(event?: string, options: (PropOptions | Constructor[] | Co
(options as PropOptions).type = Reflect.getMetadata('design:type', target, key)
}
createDecorator((componentOptions, k) => {
(componentOptions.props || (componentOptions.props = {}) as any)[k] = options;
(componentOptions.props || (componentOptions.props = {}) as any)[k] = options
componentOptions.model = { prop: k, event: event || k }
})(target, key)
}
Expand Down
59 changes: 56 additions & 3 deletions test/decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
import * as Vue from 'vue'
import { Component, Inject, Model, Prop, Provide, Watch } from '../src/vue-property-decorator'
import { Component, Emit, Inject, Model, Prop, Provide, Watch } from '../src/vue-property-decorator'
import test from 'ava'

test('@Emit decorator test', t => {

@Component
class Child extends Vue {
count = 0

@Emit('reset') resetCount() {
this.count = 0
}

@Emit() increment(n: number) {
this.count += n
}

@Emit() canceled() {
return false
}
}
const child = new Child()

let result = {
called: false,
event: '',
arg: 0
}

child.$emit = (event, ...args) => {
result.called = true
result.event = event
result.arg = args[0]

return child
}

child.resetCount()
t.is(result.called, true)
t.is(result.event, 'reset')
t.is(result.arg, undefined)

result.called = false
child.increment(30)
t.is(result.event, 'increment')
t.is(result.arg, 30)

result.called = false
child.canceled()
t.is(result.called, false)

})

test('@Inject decorator test', t => {
const s = Symbol()
@Component({
Expand Down Expand Up @@ -46,8 +96,11 @@ test('@Model decorator test', t => {
}

const { $options } = new Test()
t.deepEqual($options.model, { prop: 'checked', event: 'change' })
t.deepEqual($options.props, { checked: { type: Boolean } })
t.deepEqual($options.model, { prop: 'checked', event: 'change' })
const { props } = $options
if (!(props instanceof Array)) {
t.deepEqual(props!['checked'], { type: Boolean })
}
})

test('@Prop decorator test', t => {
Expand Down

0 comments on commit 1d9e2f8

Please sign in to comment.