Skip to content

Commit cd5290d

Browse files
author
Nicolò Maria Mezzopera
authored
Merge pull request #365 from mikeu/unit-tests
WIP adding unit tests
2 parents feba0b0 + 88fc290 commit cd5290d

24 files changed

+1384
-120
lines changed

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ module.exports = {
55
coverageDirectory: 'coverage',
66
restoreMocks: true,
77
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
8+
setupFiles: [
9+
'<rootDir>/tests/setup.js'
10+
],
811
transform: {
912
'^.+\\.vue$': 'vue-jest',
1013
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
1114
'jest-transform-stub',
1215
'^.+\\.jsx?$': 'babel-jest'
1316
},
1417
moduleNameMapper: {
18+
'^@/tests/(.*)$': '<rootDir>/tests/$1',
1519
'^@/(.*)$': '<rootDir>/src/$1'
1620
},
1721
snapshotSerializers: ['jest-serializer-vue'],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@babel/plugin-transform-runtime": "^7.3.4",
2020
"@babel/preset-env": "^7.3.1",
2121
"@babel/runtime": "^7.3.4",
22-
"@vue/test-utils": "^1.0.0-beta.20",
22+
"@vue/test-utils": "^1.0.0-beta.29",
2323
"babel-eslint": "^8.2.6",
2424
"babel-jest": "^24.1.0",
2525
"coveralls": "^3.0.3",

src/components/LCircle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
props: {
1616
latLng: {
1717
type: [Object, Array],
18-
default: () => []
18+
default: () => [0, 0]
1919
}
2020
},
2121
data () {

src/components/LCircleMarker.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
props: {
1616
latLng: {
1717
type: [Object, Array],
18-
default: () => []
18+
default: () => [0, 0]
1919
},
2020
pane: {
2121
type: String,

src/utils/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const debounce = (fn, time) => {
1616
};
1717

1818
export const capitalizeFirstLetter = (string) => {
19+
if (!string || typeof string.charAt !== 'function') { return string; }
1920
return string.charAt(0).toUpperCase() + string.slice(1);
2021
};
2122

@@ -78,7 +79,7 @@ export const optionsMerger = (props, instance) => {
7879

7980
export const findRealParent = (firstVueParent) => {
8081
let found = false;
81-
while (!found) {
82+
while (firstVueParent && !found) {
8283
if (firstVueParent.mapObject === undefined) {
8384
firstVueParent = firstVueParent.$parent;
8485
} else {

tests/mixin-tests/circle-tests.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { getWrapperWithMap } from '@/tests/test-helpers';
2+
import { testPathFunctionality } from './path-tests';
3+
4+
export const testCircleFunctionality = (component, componentName = 'it') => {
5+
// The Circle mixin includes the Path mixin.
6+
testPathFunctionality(component, componentName);
7+
8+
// Radius
9+
10+
test(`${componentName} has a getRadius method`, () => {
11+
const { wrapper } = getWrapperWithMap(component);
12+
13+
expect(typeof wrapper.vm.mapObject.getRadius).toEqual('function');
14+
});
15+
16+
test(`${componentName} accepts and uses radius prop`, () => {
17+
const radius = 100;
18+
const { wrapper } = getWrapperWithMap(component, { radius });
19+
20+
expect(wrapper.vm.mapObject.getRadius()).toEqual(radius);
21+
});
22+
23+
test(`${componentName} updates radius when prop changes`, async () => {
24+
const { wrapper } = getWrapperWithMap(component, { radius: 100 });
25+
26+
const newRadius = 2000;
27+
wrapper.setProps({ radius: newRadius });
28+
await wrapper.vm.$nextTick();
29+
30+
expect(wrapper.vm.mapObject.getRadius()).toEqual(newRadius);
31+
});
32+
};

0 commit comments

Comments
 (0)