From 4fb042212d10039186157a43cfeff3799d6caeae Mon Sep 17 00:00:00 2001 From: Bart Ledoux Date: Sat, 2 Mar 2019 16:12:22 -0600 Subject: [PATCH] add e2e for Button --- tests/components/button-jsx/Button.jsx | 50 ++++++++++++ .../__snapshots__/button-jsx.test.ts.snap | 77 +++++++++++++++++++ .../components/button-jsx/button-jsx.test.ts | 51 ++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 tests/components/button-jsx/Button.jsx create mode 100644 tests/components/button-jsx/__snapshots__/button-jsx.test.ts.snap create mode 100644 tests/components/button-jsx/button-jsx.test.ts diff --git a/tests/components/button-jsx/Button.jsx b/tests/components/button-jsx/Button.jsx new file mode 100644 index 0000000..c5de05a --- /dev/null +++ b/tests/components/button-jsx/Button.jsx @@ -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 + }, + 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) + }, + }, +} diff --git a/tests/components/button-jsx/__snapshots__/button-jsx.test.ts.snap b/tests/components/button-jsx/__snapshots__/button-jsx.test.ts.snap new file mode 100644 index 0000000..01600d4 --- /dev/null +++ b/tests/components/button-jsx/__snapshots__/button-jsx.test.ts.snap @@ -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", + }, + ], + }, +} +`; diff --git a/tests/components/button-jsx/button-jsx.test.ts b/tests/components/button-jsx/button-jsx.test.ts new file mode 100644 index 0000000..e21b827 --- /dev/null +++ b/tests/components/button-jsx/button-jsx.test.ts @@ -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() + }) +})