Skip to content

Commit

Permalink
feat(tests): Jest tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
wchmiel committed May 21, 2019
1 parent 9d3f1d0 commit c6c88c7
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
9 changes: 8 additions & 1 deletion .babelrc
@@ -1,5 +1,12 @@
{
"presets": [
["@babel/preset-env", {"modules": false}]
]
],
"env": {
"test": {
"presets": [
["@babel/preset-env", { "targets": { "node": "current" }}]
]
}
}
}
3 changes: 3 additions & 0 deletions .eslintrc.json
Expand Up @@ -3,6 +3,9 @@
"plugin:vue/essential",
"standard"
],
"env": {
"jest": true
},
"rules": {
"no-new": 0,
"vue/html-indent": [
Expand Down
6 changes: 3 additions & 3 deletions dist/highcharts-vue.js
Expand Up @@ -126,7 +126,7 @@ var generateVueComponent = function generateVueComponent(Highcharts) {
props: {
constructorType: {
type: String,
default: 'chart'
"default": 'chart'
},
options: {
type: Object,
Expand All @@ -135,7 +135,7 @@ var generateVueComponent = function generateVueComponent(Highcharts) {
callback: Function,
updateArgs: {
type: Array,
default: function _default() {
"default": function _default() {
return [true, true];
}
},
Expand All @@ -144,7 +144,7 @@ var generateVueComponent = function generateVueComponent(Highcharts) {
},
deepCopyOnUpdate: {
type: Boolean,
default: true
"default": true
}
},
watch: {
Expand Down
27 changes: 26 additions & 1 deletion package.json
Expand Up @@ -5,14 +5,31 @@
"main": "dist/highcharts-vue.min.js",
"typings": "types/highcharts-vue.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"build": "webpack",
"build:app": "cd demo && npm install",
"app": "cd demo && npm run dev",
"lint": "eslint . --ext .js,.vue",
"lint:fix": "eslint . --ext .js,.vue --fix",
"release": "standard-version"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"snapshotSerializers": [
"<rootDir>/node_modules/jest-serializer-vue"
]
},
"homepage": "https://github.com/highcharts/highcharts-vue#readme",
"repository": {
"type": "git",
Expand Down Expand Up @@ -41,13 +58,21 @@
"devDependencies": {
"@babel/core": "^7.0.0-beta.39",
"@babel/preset-env": "^7.0.0-beta.39",
"@vue/test-utils": "^1.0.0-beta.29",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.0-beta.0",
"eslint": "^4.17.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^4.2.2",
"highcharts": "^7.1.1",
"husky": "^1.0.0-rc.13",
"jest": "^24.8.0",
"jest-serializer-vue": "^2.0.2",
"standard": "^10.0.3",
"standard-version": "^4.4.0",
"vue": "^2.6.10",
"vue-jest": "^3.0.4",
"vue-template-compiler": "^2.6.10",
"webpack": "^3.10.0"
}
}
77 changes: 77 additions & 0 deletions tests/unit.test.js
@@ -0,0 +1,77 @@
import { mount } from '@vue/test-utils'
import generateVueComponent from '../src/component'
import Highcharts from 'highcharts'

const Chart = generateVueComponent(Highcharts)

const propsData = {
options: {
series: [{
name: 'Series',
data: [1, 2, 3]
}]
},
callback: function () {
this.wasCallbackInvoked = true
}
}

describe('highcharts-vue tests', () => {
const wrapper = mount(Chart, { propsData })
const chart = Highcharts.charts[0]

test('Wrapper should be a Vue instance.', () => {
expect(wrapper.isVueInstance()).toBeTruthy()
})

test('Only one chart should be created.', () => {
expect(Highcharts.charts.length).toBe(1)
})

test('Chart data should be set correctly.', () => {
expect(
wrapper.props().options.series[0].data
).toEqual(
chart.series[0].yData
)
})

test('Callback should be invoked.', () => {
expect(chart.wasCallbackInvoked).toBeTruthy()
})

test('Chart data should be copied.', () => {
wrapper.setProps({
options: {
series: [{
name: 'Series',
data: [1, 2, 3, 9]
}]
}
})

expect(
wrapper.props('options').series[0].data === chart.series[0].userOptions.data
).not.toBeTruthy()
})

test('Chart data should not be copied.', () => {
wrapper.setProps({
deepCopyOnUpdate: false,
options: {
series: [{
data: [12, 10, 5, 6, 10]
}]
}
})

expect(
wrapper.props('options').series[0].data === chart.series[0].userOptions.data
).toBeTruthy()
})

test('Chart should be destroyed when component is destroyed.', () => {
wrapper.destroy()
expect(Highcharts.charts[0]).not.toBeTruthy()
})
})

0 comments on commit c6c88c7

Please sign in to comment.