Skip to content
This repository has been archived by the owner on Mar 8, 2019. It is now read-only.

test: add e2e for JSX Button #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/components/button-jsx/Button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Vue from 'vue'

/**
* This is an example of creating a reusable button component and using it with external data.
* @author [Rafael](https://github.com/rafaesc92)
* @version 1.0.5
*/
export default {
name: 'buttonComponent',
props: {
/**
* The size of the button
*/
size: {
default: 'normal',
},
},
data() {
return {
count: 0,
}
},
render() {
const { sortKey, capitalize } = this
return <button>Click Me</button>
},
methods: {
onClick() {
console.log('Hello World')
setTimeout(() => {
/**
* Success event.
*
* @event success
* @property {object} demo - example
* @property {number} called - test called
* @property {boolean} isPacked - Indicates whether the snowball is tightly packed.
*/
this.$emit(
'success',
{
demo: 'example',
},
10,
false,
)
}, 1000)
},
},
}
77 changes: 77 additions & 0 deletions tests/components/button-jsx/__snapshots__/button-jsx.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`tests button should match the snapshot 1`] = `
Object {
"description": "This is an example of creating a reusable button component and using it with external data.",
"displayName": "buttonComponent",
"events": Object {
"success": Object {
"description": "Success event.",
"properties": Array [
Object {
"description": "example",
"name": "demo",
"type": Object {
"names": Array [
"object",
],
},
},
Object {
"description": "test called",
"name": "called",
"type": Object {
"names": Array [
"number",
],
},
},
Object {
"description": "Indicates whether the snowball is tightly packed.",
"name": "isPacked",
"type": Object {
"names": Array [
"boolean",
],
},
},
],
"type": Object {
"names": Array [
"undefined",
],
},
},
},
"methods": Array [],
"props": Object {
"size": Object {
"defaultValue": Object {
"func": false,
"value": "'normal'",
},
"description": "The size of the button",
"required": "",
"tags": Object {},
"type": Object {
"name": "string",
},
},
},
"slots": Object {},
"tags": Object {
"author": Array [
Object {
"description": "[Rafael](https://github.com/rafaesc92)",
"title": "author",
},
],
"version": Array [
Object {
"description": "1.0.5",
"title": "version",
},
],
},
}
`;
51 changes: 51 additions & 0 deletions tests/components/button-jsx/button-jsx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as path from 'path'

import { ComponentDoc } from '../../../src/Documentation'
import { parse } from '../../../src/main'
const button = path.join(__dirname, './Button.jsx')
let docButton: ComponentDoc

describe('tests button', () => {
beforeAll(done => {
docButton = parse(button)
done()
})

it('should return an object', () => {
expect(typeof docButton).toEqual('object')
})

it('The component name should be buttonComponent', () => {
expect(docButton.displayName).toEqual('buttonComponent')
})

it('The component should have a description', () => {
expect(docButton.description).toEqual(
'This is an example of creating a reusable button component and using it with external data.',
)
})

it('should the component has two tags', () => {
expect(Object.keys(docButton.tags).length).toEqual(2)
})

it('should the component has authors', () => {
expect(docButton.tags.author).not.toBeUndefined()
})

it('should not see the method without tag @public', () => {
expect(docButton.methods.length).toEqual(0)
})

it('should have props', () => {
expect(docButton.props).not.toBeUndefined()
})

it('should the component has version', () => {
expect(docButton.tags.version).not.toBeUndefined()
})

it('should match the snapshot', () => {
expect(docButton).toMatchSnapshot()
})
})