Skip to content

Use class name as Vue component's name #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function componentFactory (
Component: VueClass,
options: ComponentOptions<any> = {}
): VueClass {
options.name = options.name || (Component as any)._componentTag
options.name = options.name || (Component as any)._componentTag || (Component as any).name
// prototype props.
const proto = Component.prototype
Object.getOwnPropertyNames(proto).forEach(function (key) {
Expand Down
28 changes: 28 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ describe('vue-class-component', () => {
expect(c.b).to.equal(3)
})

describe('name', () => {
it('via name option', () => {
@Component({ name: 'test' })
class MyComp extends Vue {}

const c = new MyComp()
expect(c.$options.name).to.equal('test')
})

it('via _componentTag', () => {
@Component
class MyComp extends Vue {
static _componentTag = 'test'
}

const c = new MyComp()
expect(c.$options.name).to.equal('test')
})

it('via class name', () => {
@Component
class MyComp extends Vue {}

const c = new MyComp()
expect(c.$options.name).to.equal('MyComp')
})
})

it('other options', (done) => {
let v: number

Expand Down
2 changes: 1 addition & 1 deletion test/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
'./test/test-babel.js'
],
output: {
path: './test',
path: __dirname,
filename: 'test.build.js'
},
module: {
Expand Down