Skip to content

Commit 3b67c51

Browse files
author
nicolasbeauvais
committed
Improve unit tests
1 parent f474874 commit 3b67c51

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

test/unit/test.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import Vue from 'vue';
2-
import AddToCalendar from '../../src/add-to-calendar';
2+
import AddToCalendar, { calendars } from '../../src/add-to-calendar';
33
import AddToCalendarMixin from '../../src/add-to-calendar-mixin';
44

55
describe('AddToCalendar', () => {
6+
const event = {
7+
title: 'VueConf',
8+
location: 'WROCŁAW, POLAND',
9+
start: new Date(),
10+
end: new Date((new Date()).setDate((new Date()).getDate() + 1)),
11+
details: 'The first Official Vue.js Conference in the world!'
12+
};
13+
614
const createComponent = (propsData = {}, attr = {}, mixin = AddToCalendarMixin) => {
715
const Ctor = Vue.extend({
816
template: `
@@ -33,26 +41,44 @@ describe('AddToCalendar', () => {
3341
}).$mount();
3442
};
3543

36-
// Inspect the raw component options
3744
it('has a mounted method', () => {
3845
expect(typeof AddToCalendar.mounted).toBe('function');
3946
});
4047

41-
// Evaluate the results of functions in
42-
// the raw component options
48+
it('has a valid template', () => {
49+
expect(typeof AddToCalendarMixin.template).toBe('string');
50+
51+
const vm = createComponent().$children[0];
52+
53+
expect(vm.$children[0].$el.text.trim()).toBe('Add to Google calendar');
54+
expect(vm.$children[1].$el.text.trim()).toBe('Add to Microsoft live calendar');
55+
56+
expect(vm.$children[0].$el.href).toContain(calendars.google.url);
57+
expect(vm.$children[1].$el.href).toContain(calendars.microsoft.url);
58+
});
59+
60+
it('has a calendar class computed property', () => {
61+
expect(typeof AddToCalendarMixin.template).toBe('string');
62+
});
63+
4364
it('sets the correct default data', () => {
4465
expect(typeof AddToCalendar.data).toBe('function');
66+
4567
const defaultData = AddToCalendar.data();
4668
expect(typeof defaultData.calendars).toBe('object');
69+
expect(defaultData.calendars).toBe(calendars);
4770
});
4871

49-
xit('should set component aliases correctly', () => {
50-
createComponent();
51-
52-
// const vm = createComponent();
53-
// console.log(vm.components, vm.google);
54-
});
55-
56-
xit('should get correct calendar url', () => {
72+
it('should set url parameters correctly', () => {
73+
for (const calendar in calendars) {
74+
expect(typeof calendars[calendar].parameters).toBe('function');
75+
expect(typeof calendars[calendar].parameters(
76+
event.title,
77+
event.location,
78+
event.description,
79+
event.start,
80+
event.end
81+
)).toBe('object');
82+
}
5783
});
5884
});

0 commit comments

Comments
 (0)