-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add classes, attributes, and props methods (#141)
* Add classes wrapper method * Add support for css modules * Add attributes wrapper method * Added props wrapper method
- Loading branch information
1 parent
ac4f82f
commit 12de854
Showing
12 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { compileToFunctions } from 'vue-template-compiler' | ||
import mount from '~src/mount' | ||
|
||
describe('attributes', () => { | ||
it('returns true if wrapper contains attribute matching value', () => { | ||
const attribute = 'attribute' | ||
const value = 'value' | ||
const compiled = compileToFunctions(`<div ${attribute}=${value}></div>`) | ||
const wrapper = mount(compiled) | ||
expect(wrapper.attributes()).to.eql({ attribute: value }) | ||
}) | ||
|
||
it('returns empty object if wrapper does not contain any attributes', () => { | ||
const compiled = compileToFunctions('<div />') | ||
const wrapper = mount(compiled) | ||
expect(wrapper.attributes()).to.eql({}) | ||
}) | ||
|
||
it('returns empoty object if wrapper element is null', () => { | ||
const compiled = compileToFunctions('<div />') | ||
const wrapper = mount(compiled) | ||
wrapper.element = null | ||
expect(wrapper.attributes()).to.eql({}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
import { compileToFunctions } from 'vue-template-compiler' | ||
import mount from '~src/mount' | ||
import ComponentWithCssModules from '~resources/components/component-with-css-modules.vue' | ||
|
||
describe('classes', () => { | ||
it('returns array of class names if wrapper has class names', () => { | ||
const compiled = compileToFunctions('<div class="a-class b-class" />') | ||
const wrapper = mount(compiled) | ||
expect(wrapper.classes()).to.eql(['a-class', 'b-class']) | ||
}) | ||
|
||
it('returns empty array if wrapper has no classes', () => { | ||
const compiled = compileToFunctions('<div />') | ||
const wrapper = mount(compiled) | ||
expect(wrapper.classes()).to.eql([]) | ||
}) | ||
|
||
it('returns original class names when element mapped in css modules', () => { | ||
const wrapper = mount(ComponentWithCssModules) | ||
|
||
expect(wrapper.classes()).to.eql(['extension', 'color-red']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { compileToFunctions } from 'vue-template-compiler' | ||
import mount from '~src/mount' | ||
import ComponentWithProps from '~resources/components/component-with-props.vue' | ||
|
||
describe('props', () => { | ||
it('returns true if wrapper has prop', () => { | ||
const prop1 = {} | ||
const prop2 = 'string val' | ||
const wrapper = mount(ComponentWithProps, { | ||
propsData: { prop1, prop2 } | ||
}) | ||
expect(wrapper.props()).to.eql({ prop1: {}, prop2: 'string val' }) | ||
}) | ||
|
||
it('returns an empty object if wrapper does not have props', () => { | ||
const compiled = compileToFunctions('<div />') | ||
const wrapper = mount(compiled) | ||
expect(wrapper.props()).to.eql({}) | ||
}) | ||
|
||
it('throws an error if called on a non vm wrapper', () => { | ||
const compiled = compileToFunctions('<div><p /></div>') | ||
const p = mount(compiled).findAll('p').at(0) | ||
const message = '[vue-test-utils]: wrapper.props() must be called on a Vue instance' | ||
const fn = () => p.props() | ||
expect(fn).to.throw().with.property('message', message) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { compileToFunctions } from 'vue-template-compiler' | ||
import mount from '~src/mount' | ||
|
||
describe('attributes', () => { | ||
it('throws error if wrapper array contains no items', () => { | ||
const compiled = compileToFunctions('<div />') | ||
const message = '[vue-test-utils]: attributes cannot be called on 0 items' | ||
expect(() => mount(compiled).findAll('p').attributes('p')).to.throw().with.property('message', message) | ||
}) | ||
|
||
it('throws error when called on a WrapperArray', () => { | ||
const compiled = compileToFunctions('<div><div /></div>') | ||
const wrapper = mount(compiled) | ||
const message = '[vue-test-utils]: attributes must be called on a single wrapper, use at(i) to access a wrapper' | ||
const fn = () => wrapper.findAll('div').attributes() | ||
expect(fn).to.throw().with.property('message', message) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { compileToFunctions } from 'vue-template-compiler' | ||
import mount from '~src/mount' | ||
|
||
describe('classes', () => { | ||
it('throws error if wrapper array contains no items', () => { | ||
const compiled = compileToFunctions('<div />') | ||
const message = '[vue-test-utils]: classes cannot be called on 0 items' | ||
expect(() => mount(compiled).findAll('p').classes('p')).to.throw().with.property('message', message) | ||
}) | ||
|
||
it('throws error when called on a WrapperArray', () => { | ||
const compiled = compileToFunctions('<div><div /></div>') | ||
const wrapper = mount(compiled) | ||
const message = '[vue-test-utils]: classes must be called on a single wrapper, use at(i) to access a wrapper' | ||
const fn = () => wrapper.findAll('div').classes() | ||
expect(fn).to.throw().with.property('message', message) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { compileToFunctions } from 'vue-template-compiler' | ||
import mount from '~src/mount' | ||
|
||
describe('props', () => { | ||
it('throws error if wrapper array contains no items', () => { | ||
const compiled = compileToFunctions('<div />') | ||
const message = '[vue-test-utils]: props cannot be called on 0 items' | ||
expect(() => mount(compiled).findAll('p').props('p')).to.throw().with.property('message', message) | ||
}) | ||
|
||
it('throws error when called on a WrapperArray', () => { | ||
const compiled = compileToFunctions('<div><div /></div>') | ||
const wrapper = mount(compiled) | ||
const message = '[vue-test-utils]: props must be called on a single wrapper, use at(i) to access a wrapper' | ||
const fn = () => wrapper.findAll('div').props() | ||
expect(fn).to.throw().with.property('message', message) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters