Skip to content

Commit

Permalink
Merge pull request #4 from 14nrv/dev
Browse files Browse the repository at this point in the history
Merge dev
  • Loading branch information
14nrv authored Oct 23, 2018
2 parents e383ee7 + 8d2466a commit 3912b7a
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 330 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ describe('MyComponent', () => {
expect('input[type=text]').toHaveValue('plop')
expect('input[type=text]').not.toHaveValue('not plop')
```
* toHaveProp(propName)
```js
expect(wrapper).toHaveProp('propName')
expect(wrapper).not.toHaveProp('not-propName')
```
* toEmit(eventName)
```js
expect(wrapper).toEmit('eventName')
expect(wrapper).not.toEmit('not eventName')
```
* toEmitWith(eventName, eventValue)

eventValue can be a string, an object or an array
```js
expect(wrapper).toEmitWith('eventName', 'eventValue')
expect(wrapper).not.toEmitWith('not eventName', { data: 'eventValue' })
Expand Down
13 changes: 13 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
],
"compilerOptions": {
"checkJs": true,
"target": "es2017"
}
}
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"scripts": {
"prepare": "yarn build",
"build": "vue-cli-service build --target lib --name jest-vue-matcher ./src/matchers.js",
"build": "rollup -c",
"lint": "vue-cli-service lint",
"test": "vue-cli-service test:unit --coverage",
"test:tdd": "vue-cli-service test:unit --coverage --watchAll",
Expand All @@ -31,9 +31,10 @@
"dist/*.js"
]
},
"main": "./dist/jest-vue-matcher.common.js",
"module": "dist/jest-vue-matcher.esm.min.js",
"main": "dist/jest-vue-matcher.cjs.min.js",
"files": [
"dist/*"
"dist"
],
"repository": {
"type": "git",
Expand All @@ -55,6 +56,9 @@
"dependencies": {
"vue": "^2.5.17"
},
"peerDependencies": {
"expect": "^23.6.0"
},
"devDependencies": {
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
Expand All @@ -74,8 +78,10 @@
"eslint-plugin-jest": "^21.25.1",
"husky": "^1.1.2",
"jest-junit": "^5.2.0",
"jest-matcher-utils": "^23.6.0",
"lint-staged": "^7.3.0",
"rollup": "^0.66.6",
"rollup-plugin-analyzer": "^2.1.0",
"rollup-plugin-uglify-es": "^0.0.1",
"semantic-release": "^15.10.3",
"vue-template-compiler": "^2.5.17",
"wallaby-vue-compiler": "^1.0.3"
Expand Down
16 changes: 16 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { plugin as analyze } from 'rollup-plugin-analyzer'
import uglify from 'rollup-plugin-uglify-es'
import pkg from './package.json'

export default {
input: 'src/matchers.js',
external: ['expect'],
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' }
],
plugins: [
uglify(),
analyze()
]
}
71 changes: 37 additions & 34 deletions src/components/Questions.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils'
import Questions from '@/components/Questions.vue'
import matchers from '@/matchers'
import Questions from '@/components/Questions.vue'

const inputTitle = 'input[name=title]'
let wrapper
Expand All @@ -25,15 +25,13 @@ describe('Questions', () => {
it('can success', () => {
expect(selector).toHaveText(sentence)

const { pass, message } = matchers(wrapper).toHaveText(selector, sentence)
const { pass } = matchers(wrapper).toHaveText(selector, sentence)
expect(pass).toBeTruthy()
expect(message().includes('To not contains')).toBeTruthy()
})

it('can fail', () => {
const { pass, message } = matchers(wrapper).toHaveText(selector, `not ${sentence}`)
const { pass } = matchers(wrapper).toHaveText(selector, `not ${sentence}`)
expect(pass).toBeFalsy()
expect(message().includes('To contains')).toBeTruthy()
})

it('can reverse', () => {
Expand All @@ -50,17 +48,15 @@ describe('Questions', () => {

expect(selector).toHaveValue(sentence)

const { pass, message } = matchers(wrapper).toHaveValue(selector, sentence)
const { pass } = matchers(wrapper).toHaveValue(selector, sentence)
expect(pass).toBeTruthy()
expect(message().includes('to not be')).toBeTruthy()
})

it('can fail', () => {
setInputValue(selector, sentence)

const { pass, message } = matchers(wrapper).toHaveValue(selector, `not ${sentence}`)
const { pass } = matchers(wrapper).toHaveValue(selector, `not ${sentence}`)
expect(pass).toBeFalsy()
expect(message().includes('to be')).toBeTruthy()
})

it('can reverse', () => {
Expand All @@ -70,6 +66,26 @@ describe('Questions', () => {
})
})

describe('toHaveProp', () => {
const prop = 'name'

it('can success', () => {
expect(wrapper).toHaveProp(prop)

const { pass } = matchers(wrapper).toHaveProp(wrapper, prop)
expect(pass).toBeTruthy()
})

it('can fail', () => {
const { pass } = matchers(wrapper).toHaveProp(wrapper, `not-${prop}`)
expect(pass).toBeFalsy()
})

it('can reverse', () => {
expect(wrapper).not.toHaveProp(`not-${prop}`)
})
})

describe('toEmit', () => {
const eventName = 'isEditing'
const selector = '.edit'
Expand All @@ -80,17 +96,15 @@ describe('Questions', () => {

expect(wrapper).toEmit(eventName)

const { pass, message } = matchers(wrapper).toEmit(undefined, eventName)
const { pass } = matchers(wrapper).toEmit(undefined, eventName)
expect(pass).toBeTruthy()
expect(message().includes('falsy')).toBeTruthy()
})

it('can fail', () => {
trigger(selector)

const { pass, message } = matchers(wrapper).toEmit(wrapper, `not ${eventName}`)
const { pass } = matchers(wrapper).toEmit(wrapper, `not ${eventName}`)
expect(pass).toBeFalsy()
expect(message().includes('truthy')).toBeTruthy()
})

it('can reverse', () => {
Expand All @@ -109,19 +123,16 @@ describe('Questions', () => {
trigger(selector)
expect(wrapper).toEmitWith(eventName, eventValue)

wrapper.vm.fireStatus()

const { pass, message } = matchers(wrapper).toEmitWith(undefined, eventName, eventValue)
const { pass } = matchers(wrapper).toEmitWith(undefined, eventName, eventValue)
expect(pass).toBeTruthy()
expect(message().includes('To not contains')).toBeTruthy()
})

it('can fail', () => {
trigger(selector)

const { pass, message } = matchers(wrapper).toEmitWith(wrapper, `not ${eventName}`, eventValue)
expect(pass).toBeFalsy()
expect(message().includes('To contains')).toBeTruthy()
expect(message()).toBe(`Can't find event: 'not ${eventName}'`)
})

it('can reverse', () => {
Expand Down Expand Up @@ -149,15 +160,13 @@ describe('Questions', () => {
it('can success', () => {
expect(selector).toBeADomElement()

const { pass, message } = matchers(wrapper).toBeADomElement(selector)
const { pass } = matchers(wrapper).toBeADomElement(selector)
expect(pass).toBeTruthy()
expect(message().includes('to not be')).toBeTruthy()
})

it('can fail', () => {
const { pass, message } = matchers(wrapper).toBeADomElement(`not-${selector}`)
const { pass } = matchers(wrapper).toBeADomElement(`not-${selector}`)
expect(pass).toBeFalsy()
expect(message().includes('to be')).toBeTruthy()
})

it('can reverse', () => {
Expand All @@ -171,15 +180,13 @@ describe('Questions', () => {
it('can success', () => {
expect(selector).toBeVisible()

const { pass, message } = matchers(wrapper).toBeVisible(selector)
const { pass } = matchers(wrapper).toBeVisible(selector)
expect(pass).toBeTruthy()
expect(message().includes('to not be')).toBeTruthy()
})

it('can fail', () => {
const { pass, message } = matchers(wrapper).toBeVisible('ul')
const { pass } = matchers(wrapper).toBeVisible('ul')
expect(pass).toBeFalsy()
expect(message().includes('to be')).toBeTruthy()
})

it('can reverse', () => {
Expand All @@ -194,15 +201,13 @@ describe('Questions', () => {
it('can success', () => {
expect(wrapper).toHaveAClass('container')

const { pass, message } = matchers(wrapper).toHaveAClass(selector, className)
const { pass } = matchers(wrapper).toHaveAClass(selector, className)
expect(pass).toBeTruthy()
expect(message().includes('To not contains')).toBeTruthy()
})

it('can fail', () => {
const { pass, message } = matchers(wrapper).toHaveAClass(selector, `not-${className}`)
const { pass } = matchers(wrapper).toHaveAClass(selector, `not-${className}`)
expect(pass).toBeFalsy()
expect(message().includes('To contains')).toBeTruthy()
})

it('can reverse', () => {
Expand All @@ -218,15 +223,13 @@ describe('Questions', () => {
it('can success', () => {
expect(selector).toHaveAttribute(attrName, className)

const { pass, message } = matchers(wrapper).toHaveAttribute(selector, attrName, className)
const { pass } = matchers(wrapper).toHaveAttribute(selector, attrName, className)
expect(pass).toBeTruthy()
expect(message().includes('to not be')).toBeTruthy()
})

it('can fail', () => {
const { pass, message } = matchers(wrapper).toHaveAttribute(selector, attrName, `not-${className}`)
const { pass } = matchers(wrapper).toHaveAttribute(selector, attrName, `not-${className}`)
expect(pass).toBeFalsy()
expect(message().includes('to be')).toBeTruthy()
})

it('can reverse', () => {
Expand Down
11 changes: 8 additions & 3 deletions src/components/Questions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export default {
data: () => ({
editing: false
}),
props: {
name: {
type: String
},
plop: {
type: String
}
},
methods: {
update () {
this.$emit('applied')
Expand All @@ -39,9 +47,6 @@ export default {
this.$emit('isEditing', 40)
this.editing = true
},
fireStatus () {
this.$emit('status', 200, 300, 400, 404, 500)
},
fireObject () {
const data = {
company: 'Apple.inc',
Expand Down
Loading

0 comments on commit 3912b7a

Please sign in to comment.