Skip to content

Commit

Permalink
Changed Unit testing engine to Jest.
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyxguo committed Apr 4, 2021
1 parent d986989 commit 54a34b2
Show file tree
Hide file tree
Showing 7 changed files with 1,597 additions and 503 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
mocha: true
jest: true
}
}
]
Expand Down
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
transform: {
'^.+\\.vue$': 'vue-jest'
}
}
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-aurora",
"version": "1.1.1",
"version": "1.1.2",
"description": "Futuristic auroral theme for Hexo.",
"author": "TriDiamond <[email protected]>",
"license": "MIT",
Expand All @@ -16,16 +16,16 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --mode production",
"build:stage": "vue-cli-service build --mode staging",
"preview": "node build/index.js --preview",
"test:unit": "vue-cli-service test:unit",
"test:unit-watch": "vue-cli-service test:unit --watch",
"lint": "vue-cli-service lint",
"env:local": "node ./build/scripts/config-script.js local",
"env:prod": "node ./build/scripts/config-script.js prod",
"env:pub": "node ./build/scripts/config-script.js publish"
},
"dependencies": {
"axios": "^0.21.1",
"core.js": "^0.4.2",
"core-js": "^3.6.5",
"js-cookie": "^2.2.1",
"normalize.css": "^8.0.1",
"nprogress": "^0.2.0",
Expand All @@ -39,27 +39,23 @@
"vue3-scroll-spy": "^1.0.8"
},
"devDependencies": {
"@intlify/vue-i18n-loader": "^2.0.0-beta.3",
"@tailwindcss/postcss7-compat": "npm:@tailwindcss/postcss7-compat",
"@types/chai": "^4.2.14",
"@types/jest": "^26.0.22",
"@types/js-cookie": "^2.2.6",
"@types/mocha": "^8.2.0",
"@types/nprogress": "^0.2.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"@vue/cli-plugin-babel": "^4.5.11",
"@vue/cli-plugin-eslint": "^4.5.11",
"@vue/cli-plugin-router": "^4.5.11",
"@vue/cli-plugin-typescript": "^4.5.11",
"@vue/cli-plugin-unit-mocha": "^4.5.11",
"@vue/cli-plugin-vuex": "^4.5.11",
"@vue/cli-plugin-unit-jest": "^4.5.12",
"@vue/cli-service": "^4.5.11",
"@vue/compiler-sfc": "^3.0.5",
"@vue/compiler-sfc": "^3.0.11",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/eslint-config-typescript": "^7.0.0",
"@vue/test-utils": "^1.1.2",
"@vue/test-utils": "^2.0.0-0",
"autoprefixer": "^9",
"chai": "^4.2.0",
"eslint": "^7.19.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.5.0",
Expand All @@ -75,6 +71,7 @@
"svg-sprite-loader": "^5.2.1",
"svgo": "^1.3.2",
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
"typescript": "^4.2.3"
"typescript": "^4.2.3",
"vue-jest": "^5.0.0-0"
}
}
37 changes: 37 additions & 0 deletions tests/unit/components/Toggle.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { shallowMount } from '@vue/test-utils'
import Toggle from '@/components/ToggleSwitch/Toggle.vue'
import { nextTick } from 'vue'

function factory(props: { [key: string]: any }) {
return shallowMount(Toggle, {
props
})
}

describe('Component: Toggle.vue', () => {
it('Toggle on', async () => {
const wrapper = factory({ status: true })
await nextTick()
expect(
wrapper
.get('.slider')
.attributes()
.style.includes(
'background-color: rgb(110, 64, 201); transform: translateX(18px);'
)
).toBe(true)
})

it('Toggle off', async () => {
const wrapper = factory({ status: false })
await nextTick()
expect(
wrapper
.get('.slider')
.attributes()
.style.includes(
'background-color: rgb(16, 14, 22); transform: translateX(0);'
)
).toBe(true)
})
})
13 changes: 0 additions & 13 deletions tests/unit/example.spec.ts

This file was deleted.

5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"baseUrl": "types",
"typeRoots": ["types"],
"compilerOptions": {
"target": "esnext",
"module": "esnext",
Expand All @@ -15,9 +13,8 @@
"resolveJsonModule": true,
"sourceMap": true,
"baseUrl": ".",
"types": ["webpack-env", "mocha", "chai"],
"types": ["webpack-env", "jest"],
"paths": {
"typings/*": ["typings/*"],
"@/*": ["src/*"]
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
Expand Down
Loading

0 comments on commit 54a34b2

Please sign in to comment.