Skip to content

Commit

Permalink
✅ Add jest for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jan 28, 2018
1 parent 8089242 commit 3ccffdd
Show file tree
Hide file tree
Showing 5 changed files with 3,961 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"presets": [
["env", {
"targets": {
"browsers": [
"last 2 Chrome versions",
]
}
}]
],
"env": {
"test": {
"presets": [
["env", {
"targets": {
"node": "current"
}
}]
]
}
}
}
37 changes: 35 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"unpkg": "dist/vue-promised.js",
"browser": "dist/vue-promised.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint --color --ext=js,html src test example docs",
"unit": "jest",
"dev": "npm run unit -- --watchAll",
"test": "npm run lint && npm run unit",
"prepublishOnly": "rollit"
},
"files": [
Expand All @@ -28,5 +31,35 @@
"type": "git",
"url": "git+https://github.com/posva/vue-promised.git"
},
"license": "MIT"
"license": "MIT",
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.11",
"babel-jest": "^22.1.0",
"babel-preset-env": "^1.6.1",
"codecov": "^3.0.0",
"eslint": "^4.16.0",
"eslint-config-posva": "^1.3.2",
"jest": "^22.1.4",
"vue": "^2.5.13",
"vue-jest": "^2.0.0",
"vue-template-compiler": "^2.5.13"
},
"jest": {
"collectCoverage": true,
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
"coveragePathIgnorePatterns": [
"<rootDir>/test/*.js",
"<rootDir>/test/utils/Helper.vue",
"<rootDir>/test/.*.js",
"<rootDir>/test/*/*.js"
]
}
}
23 changes: 23 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { mount } from '@vue/test-utils'
import Promised from '../src'
import Helper from './utils/Helper'

const tick = () => new Promise(r => setImmediate(r))

describe('Tweezing', () => {
let wrapper
let promise
beforeEach(() => {
promise = Promise.resolve('foo')
wrapper = mount(Helper, {
propsData: {
promise,
},
})
})

test('displays a loading screen waiting for the promise', async () => {
await tick()
console.log(wrapper.text())
})
})
18 changes: 18 additions & 0 deletions test/utils/Helper.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<Promised v-bind="$props">
<h1>loading</h1>
<!-- The default scoped slots will be used as the result -->
<h1 slot-scope="data">{{ data }}</h1>
<!-- The 'error' named scoped slots will be used if there is an error -->
<h1 slot="error" slot-scope="error">{{ error.message }}</h1>
</Promised>
</template>

<script>
import Promised from '../../src'
export default {
props: ['promise', 'promises'],
components: { Promised },
}
</script>
Loading

0 comments on commit 3ccffdd

Please sign in to comment.