Skip to content

WIP adding unit tests #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eb70b1c
Add unit tests for 4/6 utility functions
mikeu Apr 4, 2019
12eb81e
Add some checks to catch certain argument errors
mikeu Apr 4, 2019
dfc59d9
Replace real-time sleep delays with mock waits
mikeu Apr 5, 2019
b89d41f
WIP: Tests to investigate mounting inside LMap slot
mikeu Apr 7, 2019
de8625a
Create test helper for wrapping in LMaps. Test LControlZoom props.
mikeu Apr 8, 2019
ef68c30
Add jest module mapper for tests directory
mikeu Apr 22, 2019
eb785e9
Return both component and map wrappers when mounting
mikeu Apr 22, 2019
4fc49bc
Finish batch of passing LControlZoom tests
mikeu Apr 22, 2019
d9e176c
Move LMap spec to component test dir. Use test helpers.
mikeu Apr 22, 2019
32cecad
Merge branch 'master' into unit-tests
mikeu Apr 22, 2019
c499af1
Move LMarker spec into component test directory
mikeu Apr 22, 2019
e58a58d
Make test descriptions and styles more uniform
mikeu Apr 22, 2019
dda4488
Reorganise tests to more closely match Leaflet API docs
mikeu Apr 23, 2019
2361283
Add tests for LControlAttribution and LControlScale
mikeu Apr 23, 2019
6c3ef4a
Update vue-test-utils requirement to beta 29
mikeu Apr 23, 2019
d6ec4fa
Merge branch 'master' into unit-tests
mikeu Apr 27, 2019
ae0c673
Add tests for LControlLayers options
mikeu Apr 27, 2019
be2cac2
Merge branch 'master' into unit-tests
mikeu May 29, 2019
e504bfb
Add test setup to make Leaflet think JSDOM supports SVG
mikeu May 29, 2019
8a4862c
Prevent "error reading property 'lng' of null" on default
mikeu May 29, 2019
5fc96e5
Add blank lines between arrange/act/assert steps
mikeu May 29, 2019
bd4473c
Add tests for LCircle latLng and radius props
mikeu May 29, 2019
64d61f7
Add helper to test mixed-in path functionality
mikeu May 29, 2019
82ca3db
Add tests for remaining path mixin properties
mikeu May 29, 2019
7d289cc
Move radius test into test for Circle mixin and include Path there
mikeu May 29, 2019
9a60975
Prevent "error reading property 'lng' of null" on default CircleMarker
mikeu May 29, 2019
b84879c
Add tests for LCircleMarker component
mikeu May 29, 2019
cc2c9f3
Add tests to ensure legitimate falsy values can be set
mikeu May 30, 2019
88fc290
Add tests for LPolyline.vue and Polyline mixin
mikeu May 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ module.exports = {
coverageDirectory: 'coverage',
restoreMocks: true,
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
setupFiles: [
'<rootDir>/tests/setup.js'
],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub',
'^.+\\.jsx?$': 'babel-jest'
},
moduleNameMapper: {
'^@/tests/(.*)$': '<rootDir>/tests/$1',
'^@/(.*)$': '<rootDir>/src/$1'
},
snapshotSerializers: ['jest-serializer-vue'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.1",
"@babel/runtime": "^7.3.4",
"@vue/test-utils": "^1.0.0-beta.20",
"@vue/test-utils": "^1.0.0-beta.29",
"babel-eslint": "^8.2.6",
"babel-jest": "^24.1.0",
"coveralls": "^3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/components/LCircle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
props: {
latLng: {
type: [Object, Array],
default: () => []
default: () => [0, 0]
}
},
data () {
Expand Down
2 changes: 1 addition & 1 deletion src/components/LCircleMarker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
props: {
latLng: {
type: [Object, Array],
default: () => []
default: () => [0, 0]
},
pane: {
type: String,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const debounce = (fn, time) => {
};

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

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

export const findRealParent = (firstVueParent) => {
let found = false;
while (!found) {
while (firstVueParent && !found) {
if (firstVueParent.mapObject === undefined) {
firstVueParent = firstVueParent.$parent;
} else {
Expand Down
32 changes: 32 additions & 0 deletions tests/mixin-tests/circle-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { getWrapperWithMap } from '@/tests/test-helpers';
import { testPathFunctionality } from './path-tests';

export const testCircleFunctionality = (component, componentName = 'it') => {
// The Circle mixin includes the Path mixin.
testPathFunctionality(component, componentName);

// Radius

test(`${componentName} has a getRadius method`, () => {
const { wrapper } = getWrapperWithMap(component);

expect(typeof wrapper.vm.mapObject.getRadius).toEqual('function');
});

test(`${componentName} accepts and uses radius prop`, () => {
const radius = 100;
const { wrapper } = getWrapperWithMap(component, { radius });

expect(wrapper.vm.mapObject.getRadius()).toEqual(radius);
});

test(`${componentName} updates radius when prop changes`, async () => {
const { wrapper } = getWrapperWithMap(component, { radius: 100 });

const newRadius = 2000;
wrapper.setProps({ radius: newRadius });
await wrapper.vm.$nextTick();

expect(wrapper.vm.mapObject.getRadius()).toEqual(newRadius);
});
};
Loading