Skip to content

Commit

Permalink
feat: add a default value to the type prop
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Jan 22, 2021
1 parent 3c115cd commit 8d68c63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ p > i {
| stroke-linejoin | `string` | `"round"` | miter, round, bevel | Specifies the shape to be used at the corners of paths or basic shapes when they are stroked ([spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linejoin)). |
| stroke-width | `number \| string` | `2` | - | The stroke width of the icon ([spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width)). |
| tag | `string` | `"i"` | - | The tag of the icon. |
| type | `string` | - | All [Feather](https://feathericons.com/)'s icons. | The type of the icon. |
| type | `string` | `"feather"` | All [Feather](https://feathericons.com/)'s icons. | The type of the icon. |
2 changes: 1 addition & 1 deletion src/vue-feather.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default defineComponent({
type: {
type: String,
required: true,
default: 'feather',
validator(type: string) {
if (!feather) {
throw new Error('The Feather icons is required.');
Expand Down
49 changes: 11 additions & 38 deletions tests/props.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import VueFeather from '../src';
describe('props', () => {
describe('animation', () => {
it('default', () => {
const wrapper = mount(VueFeather, {
props: {
type: 'feather',
},
});
const wrapper = mount(VueFeather);

expect(wrapper.props('animation')).toBeUndefined();
expect(wrapper.classes()).not.toContain('vue-feather--spin');
Expand All @@ -20,7 +16,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
animation: 'spin',
type: 'feather',
},
});

Expand All @@ -32,7 +27,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
animation: 'pulse',
type: 'feather',
},
});

Expand All @@ -43,11 +37,7 @@ describe('props', () => {

describe('animation-speed', () => {
it('default', () => {
const wrapper = mount(VueFeather, {
props: {
type: 'feather',
},
});
const wrapper = mount(VueFeather);

expect(wrapper.props('animationSpeed')).toBeUndefined();
expect(wrapper.classes()).not.toContain('vue-feather--slow');
Expand All @@ -58,7 +48,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
animationSpeed: 'slow',
type: 'feather',
},
});

Expand All @@ -70,7 +59,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
animationSpeed: 'fast',
type: 'feather',
},
});

Expand All @@ -83,7 +71,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
fill: 'red',
type: 'feather',
},
});

Expand All @@ -95,7 +82,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
size: '2rem',
type: 'feather',
},
});

Expand All @@ -108,7 +94,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
stroke: 'red',
type: 'feather',
},
});

Expand All @@ -120,7 +105,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
strokeLinecap: 'butt',
type: 'feather',
},
});

Expand All @@ -132,7 +116,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
strokeLinejoin: 'miter',
type: 'feather',
},
});

Expand All @@ -144,7 +127,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
strokeWidth: 3,
type: 'feather',
},
});

Expand All @@ -154,11 +136,7 @@ describe('props', () => {

describe('tag', () => {
it('default', () => {
const wrapper = mount(VueFeather, {
props: {
type: 'feather',
},
});
const wrapper = mount(VueFeather);

expect(wrapper.props('tag')).toBe('i');
expect(wrapper.vm.$el.tagName.toLowerCase()).toBe('i');
Expand All @@ -168,7 +146,6 @@ describe('props', () => {
const wrapper = mount(VueFeather, {
props: {
tag: 'span',
type: 'feather',
},
});

Expand All @@ -178,6 +155,14 @@ describe('props', () => {
});

describe('type', () => {
it('default', () => {
const wrapper = mount(VueFeather);

expect(wrapper.props('type')).toBe('feather');
expect(wrapper.classes()).toContain('vue-feather--feather');
expect(wrapper.vm.$el.querySelector('svg').innerHTML).toContain(feather.icons.feather.contents);
});

it('invalid', () => {
expect(() => {
mount(VueFeather, {
Expand All @@ -187,17 +172,5 @@ describe('props', () => {
});
}).toThrowError();
});

it('feather', () => {
const wrapper = mount(VueFeather, {
props: {
type: 'feather',
},
});

expect(wrapper.props('type')).toBe('feather');
expect(wrapper.classes()).toContain('vue-feather--feather');
expect(wrapper.vm.$el.querySelector('svg').innerHTML).toContain(feather.icons.feather.contents);
});
});
});

0 comments on commit 8d68c63

Please sign in to comment.