Skip to content

Commit

Permalink
Add snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Ryuk committed Feb 22, 2018
1 parent 9996488 commit ab4e4fc
Show file tree
Hide file tree
Showing 5 changed files with 3,442 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
["env", { "modules": false }]
],
"env": {
"test": {
"presets": [
["env", { "targets": { "node": "current" }}]
]
}
}
}
31 changes: 29 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Mobile-friendly picture file input component with image preview and drag and drop.",
"main": "PictureInput.vue",
"scripts": {
"test": "npm run unit"
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -24,5 +24,32 @@
"bugs": {
"url": "https://github.com/alessiomaffeis/vue-picture-input/issues"
},
"homepage": "https://github.com/alessiomaffeis/vue-picture-input"
"homepage": "https://github.com/alessiomaffeis/vue-picture-input",
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.12",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"jest": "^22.4.0",
"jest-serializer-vue": "^0.3.0",
"vue": "^2.5.13",
"vue-jest": "^2.1.0",
"vue-server-renderer": "^2.5.13",
"vue-template-compiler": "^2.5.13"
},
"jest": {
"moduleFileExtensions": [
"js",
"vue"
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
"snapshotSerializers": [
"<rootDir>/node_modules/jest-serializer-vue"
]
}
}
15 changes: 15 additions & 0 deletions test/PictureInput.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { shallow } from '@vue/test-utils'
import { createRenderer } from 'vue-server-renderer'

import PictureInput from '../PictureInput.vue'

describe('PictureInput.vue', () => {
it('matches snapshot', () => {
const renderer = createRenderer()
const wrapper = shallow(PictureInput)
renderer.renderToString(wrapper.vm, (err, str) => {
if (err) throw new Error(err)
expect(str).toMatchSnapshot()
})
})
})
10 changes: 10 additions & 0 deletions test/__snapshots__/PictureInput.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PictureInput.vue matches snapshot 1`] = `
<div id="picture-input" class="picture-input">
<div>
<button class="btn btn-primary button">Select a Photo</button>
</div>
<input type="file" accept="image/*">
</div>
`;
Loading

0 comments on commit ab4e4fc

Please sign in to comment.