Skip to content

Commit

Permalink
chore: upgrade vue test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurk91 committed Apr 19, 2020
1 parent 8c6975d commit 3d38e55
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Contributing

### Issue reporting
* If the issue is related to flatPickr then report that issue on [flatpickr](https://github.com/chmln/flatpickr/issues) repo instead
* If the issue is related to flatPickr then report that issue on [flatpickr](https://github.com/flatpickr/flatpickr/issues) repo instead
- Issues those are related to flatPickr may be closed without any reason
* Follow ISSUE_TEMPLATE

Expand Down
47 changes: 19 additions & 28 deletions __test__/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,24 @@ describe('Flatpickr events', () => {
jest.resetAllMocks();
});

test('emits input event on value change by user', (done) => {
test('emits input event on value change by user', async () => {
const stub = jest.fn();
wrapper.vm.$on('input', stub);
wrapper.vm.$el.value = '2019-10-04';
wrapper.find('input').trigger('input');
await wrapper.vm.$nextTick();

wrapper.vm.$nextTick(() => {
expect(stub).toHaveBeenCalledWith("2019-10-04");
done();
});
expect(stub).toHaveBeenCalledWith("2019-10-04");
});

test('emits on-change event on value change', (done) => {
test('emits on-change event on value change', async () => {
const stub = jest.fn();
wrapper.vm.$on('on-change', stub);
wrapper.setProps({value: '2017-10-04'});

wrapper.vm.$nextTick(() => {
expect(stub).toHaveBeenCalled();
done();
});
await wrapper.vm.$nextTick();

expect(stub).toHaveBeenCalled();
});

test('emits on-open event on focus', () => {
Expand All @@ -62,17 +58,15 @@ describe('Flatpickr events', () => {
expect(stub).toHaveBeenCalled();
});

test('calls original onChange method on value change', (done) => {
test('calls original onChange method on value change', async () => {
wrapper.setProps({value: '2017-10-04'});

wrapper.vm.$nextTick(() => {
expect(onChangeStub).toHaveBeenCalled();
done()
});
await wrapper.vm.$nextTick();

expect(onChangeStub).toHaveBeenCalled();
});

test('emits only those are specified via prop', () => {
test('emits only those are specified via prop', async () => {
wrapper = mount(Component, {
propsData: {
value: null,
Expand All @@ -83,17 +77,16 @@ describe('Flatpickr events', () => {
const onOpen = jest.fn();
wrapper.vm.$on('on-open', onOpen);
wrapper.trigger('focus');
wrapper.vm.$nextTick(() => {
expect(onOpen).not.toHaveBeenCalled();
});
await wrapper.vm.$nextTick();

expect(onOpen).not.toHaveBeenCalled();

const onChange = jest.fn();
wrapper.vm.$on('on-change', onChange);
wrapper.setProps({value: '2017-10-04'});
wrapper.vm.$nextTick(() => {
expect(onChange).toHaveBeenCalled();
})
await wrapper.vm.$nextTick();

expect(onChange).toHaveBeenCalled();
});

test('does not emit on-change event on mount', () => {
Expand All @@ -107,15 +100,13 @@ describe('Flatpickr events', () => {
expect(wrapper.emitted().blur).toBeTruthy()
});

test('respect global callbacks', (done) => {
test('respect global callbacks', async () => {
wrapper.setProps({value: '2017-10-04'});

wrapper.vm.$nextTick(() => {
expect(globalOnChange).toHaveBeenCalled();
expect(onChangeStub).toHaveBeenCalled();
await wrapper.vm.$nextTick();

done()
});
expect(globalOnChange).toHaveBeenCalled();
expect(onChangeStub).toHaveBeenCalled();
});

});
20 changes: 16 additions & 4 deletions __test__/watchers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,43 @@ describe('Flatpickr watchers', () => {
wrapper = null;
});

test('updates input value in DOM on value changed from parent component', () => {
test('updates input value in DOM on value changed from parent component', async () => {
wrapper.setProps({value: '2019-10-04'});
await wrapper.vm.$nextTick();

expect(wrapper.vm.$el.value).toEqual('2019-10-04');
});

test('updates configs runtime', () => {
test('updates configs runtime',async () => {
wrapper.setProps({config: {time_24hr: true}});
await wrapper.vm.$nextTick();

expect(wrapper.vm.fp.config).toHaveProperty('time_24hr', true);

wrapper.setProps({config: {time_24hr: false}});
await wrapper.vm.$nextTick();

expect(wrapper.vm.fp.config).toHaveProperty('time_24hr', false);
});

test('updates locale runtime', () => {
test('updates locale runtime', async () => {
expect(wrapper.vm.fp.config.locale.months.longhand[0]).not.toBe('January');

wrapper.setProps({config: {locale: EnglishLocale}});
await wrapper.vm.$nextTick();

expect(wrapper.vm.fp.config.locale.months.longhand[0]).toBe('January');
});

test('updates disabled attribute runtime', () => {
test('updates disabled attribute runtime',async () => {
wrapper.setProps({disabled: false});
await wrapper.vm.$nextTick();

expect(wrapper.vm.fpInput().disabled).toBeFalsy();

wrapper.setProps({disabled: true});
await wrapper.vm.$nextTick();

expect(wrapper.vm.fpInput().disabled).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion examples/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<ul>
<li><a href="https://github.com/ankurk91/vue-flatpickr-component" target="_blank">Github</a></li>
<li><a href="https://www.npmjs.com/package/vue-flatpickr-component" target="_blank">npm</a></li>
<li><a href="https://chmln.github.io/flatpickr" rel="noreferrer" target="_blank">Flatpickr docs</a></li>
<li><a href="https://flatpickr.js.org/" rel="noreferrer" target="_blank">Flatpickr docs</a></li>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@babel/core": "^7.9.0",
"@babel/plugin-transform-object-assign": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@vue/test-utils": "1.0.0-beta.29",
"@vue/test-utils": "1.0.0-beta.33",
"babel-jest": "^25.3.0",
"babel-loader": "^8.1.0",
"bootstrap": "^4.4.1",
Expand Down
1 change: 0 additions & 1 deletion webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ module.exports = {
}),
new webpack.ProvidePlugin({
Vue: ['vue/dist/vue.esm.js', 'default'],
'window.Vue': 'vue',
}),
new VueLoaderPlugin(),
],
Expand Down
Loading

0 comments on commit 3d38e55

Please sign in to comment.