├── .babelrc ├── .editorconfig ├── .github ├── pull_request_template.md └── workflows │ ├── node.js.yml │ └── npm-publish.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── README.md ├── circle.yml ├── dangerfile.ts ├── example ├── App.vue └── index.js ├── package-lock.json ├── package.json ├── src ├── components │ ├── VueGist.vue │ └── VueGistCore.vue └── index.js └── test ├── VueGist.test.js ├── VueGistCore.test.js ├── __mocks__ └── jsonp.js └── index.test.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "poi" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### What is in this PR: 2 | 3 | What is this PR all about, you can list down all the things that will help a reviewer understand this better. Pro tip: It is helpful to link a PR to an issue. Follow this [guide](https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue) 4 | 5 | - Point 6 | 7 | ### How to test this PR: 8 | 9 | Provide step by step instructions about how to test this feature 10 | 11 | ### Related PR: 12 | 13 | Any related or already existing pull requests? 14 | 15 | ### Screenshot and preview: 16 | 17 | A picture is worth a thousand words 18 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Build and Test 5 | 6 | on: 7 | workflow_dispatch: 8 | push: 9 | branches: [ master ] 10 | pull_request_target: 11 | branches: [ master ] 12 | 13 | jobs: 14 | build: 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Use Node.js 12.x 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: 12.x 24 | - name: Cache Node.js modules 25 | uses: actions/cache@v2 26 | with: 27 | # npm cache files are stored in `~/.npm` on Linux/macOS 28 | path: ~/.npm 29 | key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }} 30 | restore-keys: | 31 | ${{ runner.OS }}-node- 32 | ${{ runner.OS }}- 33 | - name: Install dependencies 34 | run: npm ci 35 | - name: Build project 36 | run: npm run build --if-present 37 | - name: Run tests 38 | run: npm test 39 | - name: Run Danger 40 | run: npx danger ci 41 | env: 42 | DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} 43 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages 3 | 4 | name: Publish 5 | 6 | on: 7 | push: 8 | tags: 9 | - v[0-9].[0-9]+.[0-9]+ 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: 12 19 | - run: npm ci 20 | - run: npm test 21 | 22 | publish-npm: 23 | needs: build 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v2 27 | - uses: actions/setup-node@v1 28 | with: 29 | node-version: 12 30 | registry-url: https://registry.npmjs.org/ 31 | - run: npm ci 32 | - run: npm publish 33 | env: 34 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 35 | - run: npm run build:example 36 | - name: deploy example 37 | uses: peaceiris/actions-gh-pages@v3 38 | with: 39 | github_token: ${{ secrets.GITHUB_TOKEN }} 40 | publish_dir: ./example/dist 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .DS_Store 4 | coverage 5 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, religion, or sexual identity 11 | and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the 27 | overall community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or 32 | advances of any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email 36 | address, without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | sudhanshu.15@gmail.com. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series 87 | of actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or 94 | permanent ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within 114 | the community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.0, available at 120 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 121 | 122 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 123 | enforcement ladder](https://github.com/mozilla/diversity). 124 | 125 | [homepage]: https://www.contributor-covenant.org 126 | 127 | For answers to common questions about this code of conduct, see the FAQ at 128 | https://www.contributor-covenant.org/faq. Translations are available at 129 | https://www.contributor-covenant.org/translations. 130 | 131 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute 2 | 3 | First of all, thank you so much for using this plugin in your project secondly, I really appreciate you taking the initiative to consider contributing to this project. One of the fundamental goals of this project was to promote learning and if this is your first time contributing you are very welcome here and I hope it fun and exciting for you. 4 | 5 | Some general technical overview to get you started and help understand the project better. 6 | PS: This is also for me to refer later 🙈 7 | 8 | This project uses: 9 | - [bili](https://bili.egoist.sh/#/) for bundling the library. It is simple and easy to use. 10 | - ESlint for linting 11 | - Jest for testing 12 | - All source code resides in `src/` 13 | - To validate your changes run `npm run prepublishOnly`. This will run the test suite and also try to build the project. 😉 it might be wise to update the test cases in `test/`. 14 | - There is a test app in `example/` which uses this library and can be used for testing. 15 | - The test app uses [poi](https://poi.js.org/) and is fairly simple to use. 16 | - To test run `npm run example` and you should be good. 17 | - The project uses [CircleCI](https://circleci.com/) as the CI solution, so any PR will be run on CI before it can be approved. 18 | 19 | ## Creating a pull request 20 | 21 | Your new shiny feature is ready or you have tackled some nasty bug, what next? Nothing much just create a [Github Pull Request](https://github.com/sudhanshu-15/vue-embed-gist/pull/new/master). To make this smoother fill-in the details in the PR template. 22 | Some best practices to consider while creating a pull request: 23 | - Always good to refer an issue if it exists. 24 | - Providing meaningful comments are good. 25 | - Branches could be follow this naming `bug/issue-#-someDescription` or `feature/issue-#-someDescription`. eg: `feature/issue-7-addContributionGuides` 26 | - Even if you don't follow this convention it is fine, your contributions are always welcome. 🤗 27 | 28 | ## [Code of conduct](CODE_OF_CONDUCT.md) 29 | 30 | Thank you again and happy contributing. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-embed-gist 2 | 3 | [![NPM version](https://img.shields.io/npm/v/vue-embed-gist.svg?style=flat)](https://npmjs.com/package/vue-embed-gist) [![NPM downloads](https://img.shields.io/npm/dm/vue-embed-gist.svg?style=flat)](https://npmjs.com/package/vue-embed-gist) [![CircleCI](https://circleci.com/gh/sudhanshu-15/vue-embed-gist/tree/master.svg?style=shield)](https://circleci.com/gh/sudhanshu-15/vue-embed-gist/tree/master) 4 | [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](code_of_conduct.md) 5 | 6 | Vue component to embed Github Gists, inspired by Blair Vanderhoof's gist-embed. (https://github.com/blairvanderhoof/gist-embed) 7 | 8 | ## Demo 9 | 10 | [Demo of vue-embed-gist](https://sudhanshu-15.github.io/vue-embed-gist) 11 | 12 | ## Install 13 | 14 | ```bash 15 | yarn add vue-embed-gist 16 | ``` 17 | 18 | or 19 | 20 | ```bash 21 | npm install --save vue-embed-gist 22 | ``` 23 | 24 | 25 | 26 | ## Usage 27 | 28 | ```vue 29 | 32 | 33 | 42 | ``` 43 | 44 | ### Props 45 | 46 | #### gist-Id 47 | 48 | **Type:** `String` 49 | **Required:** `true` 50 | 51 | :octocat: Github gist Id 52 | 53 | #### file 54 | 55 | **Type:** `String` 56 | **Required:** `false` 57 | 58 | File name in the gist 59 | 60 | ## [Contributing to this project 🙌🏽](CONTRIBUTING.md) 61 | 62 | ## [Code of conduct](CODE_OF_CONDUCT.md) 63 | 64 | ## License 65 | 66 | MIT © [Sudhanshu Siddh](www.ssiddh.me) 67 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | working_directory: ~/repo 5 | docker: 6 | - image: circleci/node:latest 7 | steps: 8 | - checkout 9 | - restore_cache: 10 | key: dependency-cache-{{ checksum "package-lock.json" }} 11 | - run: 12 | name: install dependences 13 | command: npm install 14 | - save_cache: 15 | key: dependency-cache-{{ checksum "package-lock.json" }} 16 | paths: 17 | - ./node_modules 18 | - run: 19 | name: test 20 | command: npm run test 21 | - run: 22 | name: build 23 | command: npm run build 24 | publish: 25 | working_directory: ~/repo 26 | docker: 27 | - image: circleci/node:latest 28 | steps: 29 | - checkout 30 | - run: 31 | name: add npm token 32 | command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc 33 | - restore_cache: 34 | key: dependency-cache-{{ checksum "package-lock.json" }} 35 | - run: 36 | name: install dependences 37 | command: npm install 38 | - save_cache: 39 | key: dependency-cache-{{ checksum "package-lock.json" }} 40 | paths: 41 | - ./node_modules 42 | - run: 43 | name: publish on npm 44 | command: npm publish 45 | 46 | workflows: 47 | version: 2 48 | build-and-publish: 49 | jobs: 50 | - build: 51 | filters: 52 | tags: 53 | ignore: /v[0-9]+(\.[0-9]+)*/ 54 | - publish: 55 | filters: 56 | branches: 57 | ignore: /.*/ 58 | tags: 59 | only: /v[0-9]+(\.[0-9]+)*/ 60 | -------------------------------------------------------------------------------- /dangerfile.ts: -------------------------------------------------------------------------------- 1 | import { danger, warn } from "danger"; 2 | import { includes } from "lodash"; 3 | import spellcheck from "danger-plugin-spellcheck"; 4 | 5 | // No PR is too small to include a description of why you made a change 6 | if (danger.github.pr.body.length < 10) { 7 | warn("A PR description is helpful for reviewers, eg: test cases to consider. 🤓"); 8 | } 9 | 10 | // Request changes to src also include changes to tests. 11 | const allFiles = danger.git.modified_files.concat(danger.git.created_files); 12 | const hasLibChanges = allFiles.some(p => includes(p, "src/")); 13 | const hasTestChanges = allFiles.some(p => includes(p, "__tests__/")); 14 | const hasExampleChanges = allFiles.some(p => includes(p, "example/")); 15 | 16 | if (hasLibChanges && !hasTestChanges) { 17 | warn( 18 | "Thank you for the PR 🙌🏽 There're library changes, but no tests 😱" 19 | ); 20 | } 21 | 22 | if (hasLibChanges && !hasExampleChanges) { 23 | warn( 24 | "Updating the example app helps demonstrate new features to users 🧐" 25 | ); 26 | } 27 | 28 | // Check if package-lock was updated 29 | const packageChanged = danger.git.modified_files.includes('package.json'); 30 | const lockfileChanged = danger.git.modified_files.includes('package-lock.json'); 31 | 32 | if (packageChanged && !lockfileChanged) { 33 | warn( 34 | "Updatess were made to package.json, but not to package-lock.json - Need to run `npm install`" 35 | ); 36 | } 37 | 38 | // Perform a spell check 39 | spellcheck() -------------------------------------------------------------------------------- /example/App.vue: -------------------------------------------------------------------------------- 1 | 43 | 44 | 67 | 68 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | new Vue({ 5 | el: '#app', 6 | render: h => h(App) 7 | }) 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-embed-gist", 3 | "version": "1.2.0", 4 | "description": "Vue component to embed Github Gists, inspired by Blair Vanderhoof's gist-embed.", 5 | "repository": { 6 | "url": "sudhanshu-15/vue-embed-gist", 7 | "type": "git" 8 | }, 9 | "keywords": [ 10 | "vue", 11 | "gist", 12 | "embed", 13 | "component" 14 | ], 15 | "main": "dist/vue-embed-gist.cjs.js", 16 | "files": [ 17 | "dist" 18 | ], 19 | "scripts": { 20 | "prepublishOnly": "npm test && npm run build", 21 | "lint": "eslint . --ext .js --ext .vue", 22 | "test": "npm run lint && tyu", 23 | "build": "bili", 24 | "example": "poi", 25 | "build:example": "poi build", 26 | "deploy": "npm run build:example && gh-pages -d example/dist" 27 | }, 28 | "author": { 29 | "name": "Sudhanshu Siddh", 30 | "email": "sudhanshu.15@gmail.com" 31 | }, 32 | "license": "MIT", 33 | "poi": { 34 | "entry": "example/index.js", 35 | "dist": "example/dist", 36 | "homepage": "./" 37 | }, 38 | "bili": { 39 | "format": [ 40 | "cjs", 41 | "umd" 42 | ], 43 | "name": "vue-embed-gist", 44 | "plugins": [ 45 | "vue" 46 | ] 47 | }, 48 | "eslintConfig": { 49 | "extends": [ 50 | "plugin:vue/recommended" 51 | ] 52 | }, 53 | "jest": { 54 | "collectCoverage": true, 55 | "collectCoverageFrom": [ 56 | "**/*.{js,vue}" 57 | ], 58 | "coveragePathIgnorePatterns": [ 59 | "/example/", 60 | "/coverage/" 61 | ] 62 | }, 63 | "devDependencies": { 64 | "@babel/helper-module-imports": "^7.0.0-beta.44", 65 | "bili": "^1.6.5", 66 | "danger": "^10.5.0", 67 | "danger-plugin-spellcheck": "^1.5.0", 68 | "eslint": "^4.14.0", 69 | "eslint-plugin-vue": "^4.0.1", 70 | "gh-pages": "^1.1.0", 71 | "poi": "^9.3.10", 72 | "rollup-plugin-vue": "^2.5.2", 73 | "tyu": "^1.0.0", 74 | "vue-test-utils": "^1.0.0-beta.9" 75 | }, 76 | "dependencies": { 77 | "jsonp": "^0.2.1" 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/components/VueGist.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 81 | 82 | 86 | -------------------------------------------------------------------------------- /src/components/VueGistCore.vue: -------------------------------------------------------------------------------- 1 | 6 | 16 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import VueGist from './components/VueGist.vue' 2 | export default { 3 | name: 'vue-embed-gist', 4 | props: { 5 | gistId: { 6 | type: String, 7 | required: true 8 | }, 9 | file: { 10 | type: String, 11 | required: false 12 | } 13 | }, 14 | render(h) { 15 | return h(VueGist, { 16 | props: { 17 | gistId: this.gistId, 18 | file: this.file 19 | } 20 | }) 21 | } 22 | } -------------------------------------------------------------------------------- /test/VueGist.test.js: -------------------------------------------------------------------------------- 1 | // jest.mock("$", () => { 2 | // ajax: jest.fn(() => Promise.resolve({ 3 | // div: 'Output Div' 4 | // })) 5 | // }) 6 | import { mount, shallow } from 'vue-test-utils' 7 | import VueGist from '../src/components/VueGist.vue' 8 | import VueGistCore from '../src/components/VueGistCore.vue' 9 | import jsonp from './__mocks__/jsonp' 10 | 11 | describe('VueGist Component', () => { 12 | test('is a Vue instance', () => { 13 | const wrapper = shallow(VueGist, { 14 | propsData: { 15 | gistId: '8bab656a910829ab9c32d7700c570be6' 16 | } 17 | }) 18 | expect(wrapper.isVueInstance()).toBe(true) 19 | }) 20 | 21 | test('has required props', () => { 22 | const wrapper = shallow(VueGist, { 23 | propsData: { 24 | gistId: '8bab656a910829ab9c32d7700c570be6' 25 | } 26 | }) 27 | expect(wrapper.props().gistId).not.toBe(undefined) 28 | }) 29 | 30 | test('does not have optional props', () => { 31 | const wrapper = shallow(VueGist, { 32 | propsData: { 33 | gistId: '8bab656a910829ab9c32d7700c570be6' 34 | } 35 | }) 36 | expect(wrapper.props().file).toBe(undefined) 37 | }) 38 | 39 | test('has props', () => { 40 | const wrapper = shallow(VueGist, { 41 | propsData: { 42 | gistId: '8bab656a910829ab9c32d7700c570be6', 43 | file: 'index.js' 44 | } 45 | }) 46 | expect(wrapper.props().gistId).not.toBe(undefined) 47 | expect(wrapper.props().gistId).toBe('8bab656a910829ab9c32d7700c570be6') 48 | expect(wrapper.props().file).not.toBe(undefined) 49 | expect(wrapper.props().file).toBe('index.js') 50 | }) 51 | 52 | test('contains VueGistCore', () => { 53 | const wrapper = mount(VueGist, { 54 | propsData: { 55 | gistId: '8bab656a910829ab9c32d7700c570be6' 56 | } 57 | }) 58 | expect(wrapper.contains(VueGistCore)).toBe(true) 59 | }) 60 | 61 | test('Check gistData initial value', () => { 62 | const wrapper = shallow(VueGist, { 63 | propsData: { 64 | gistId: '8bab656a910829ab9c32d7700c570be6' 65 | } 66 | }) 67 | expect(wrapper.vm.gistData).toBe('loading...') 68 | }) 69 | 70 | test('Show Error component', () =>{ 71 | const wrapper = shallow(VueGist, { 72 | propsData: { 73 | gistId: '8bab656a910829ab9c32d7700c570be6', 74 | file: 'index.js' 75 | } 76 | }) 77 | wrapper.setData({ gistErr: true}) 78 | // looking for the css selector 79 | expect(wrapper.find("#notFound")).toBeTruthy() 80 | }) 81 | 82 | test('Dynamically change the gist after the instance created', () => { 83 | const wrapper = shallow(VueGist, { 84 | propsData: { 85 | gistId: '8bab656a910829ab9c32d7700c570be6' 86 | } 87 | }) 88 | // This should be called as soon as the watch handler triggered 89 | wrapper.vm.getGistData = jest.fn(); 90 | // First gist Id 91 | expect(wrapper.vm.gistData).toBe('loading...') 92 | // Change the data in the instance 93 | wrapper.setData({ gistId: 'f284fdc92dd66f8f16e6dee335ff3cef' }); 94 | // Change the data again in the instance 95 | wrapper.setData({ gistId: '0c9be8f1974d126b38206380c9544592' }); 96 | // the trigger should happen for 2 times 97 | expect(wrapper.vm.getGistData).toHaveBeenCalledTimes(2); 98 | }) 99 | 100 | it('Ajax call -- check call parameters', () => { 101 | const wrapper = shallow(VueGist, { 102 | propsData: { 103 | gistId: 'gistId', 104 | file: 'test.java' 105 | } 106 | }) 107 | wrapper.vm.getGistData('gistId') 108 | expect(jsonp).toBeCalledWith( 109 | 'https://gist.github.com/gistId.json?file=test.java', 110 | { timeout: 20000 }, 111 | expect.any(Function) 112 | ) 113 | }) 114 | }) -------------------------------------------------------------------------------- /test/VueGistCore.test.js: -------------------------------------------------------------------------------- 1 | import { mount, shallow } from 'vue-test-utils' 2 | import VueGistCore from '../src/components/VueGistCore.vue' 3 | 4 | describe('VueGistCoreCore Component', () => { 5 | test('is a Vue instance', () => { 6 | const wrapper = shallow(VueGistCore, { 7 | propsData: { 8 | gistDiv: '

New Titile

' 9 | } 10 | }) 11 | expect(wrapper.isVueInstance()).toBe(true) 12 | }) 13 | 14 | test('has required props', () => { 15 | const wrapper = shallow(VueGistCore, { 16 | propsData: { 17 | gistDiv: '

New Titile

' 18 | } 19 | }) 20 | expect(wrapper.props().gistDiv).not.toBe(undefined) 21 | }) 22 | 23 | test('has props', () => { 24 | const wrapper = shallow(VueGistCore, { 25 | propsData: { 26 | gistDiv: '

New Titile

' 27 | } 28 | }) 29 | expect(wrapper.props().gistDiv).not.toBe(undefined) 30 | expect(wrapper.props().gistDiv).toBe('

New Titile

') 31 | }) 32 | 33 | test('contains paragraph', () => { 34 | const wrapper = mount(VueGistCore, { 35 | propsData: { 36 | gistDiv: '

New Titile

' 37 | } 38 | }) 39 | expect(wrapper.contains('p')).toBe(true) 40 | }) 41 | }) -------------------------------------------------------------------------------- /test/__mocks__/jsonp.js: -------------------------------------------------------------------------------- 1 | export default jest.fn(() => { 2 | Promise.resolve({ 3 | response : { 4 | div: 'Output Div' 5 | } 6 | }) 7 | }); 8 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | import { mount, shallow } from 'vue-test-utils' 2 | import VueEmbedGist from '../src/' 3 | 4 | describe('Component', () => { 5 | test('is a Vue instance', () => { 6 | const wrapper = mount(VueEmbedGist, { 7 | propsData: { 8 | gistId: '8bab656a910829ab9c32d7700c570be6' 9 | } 10 | }) 11 | expect(wrapper.isVueInstance()).toBe(true) 12 | }) 13 | 14 | test('has required props', () => { 15 | const wrapper = shallow(VueEmbedGist, { 16 | propsData: { 17 | gistId: '8bab656a910829ab9c32d7700c570be6' 18 | } 19 | }) 20 | expect(wrapper.props().gistId).not.toBe(undefined) 21 | }) 22 | 23 | test('does not have optional props', () => { 24 | const wrapper = shallow(VueEmbedGist, { 25 | propsData: { 26 | gistId: '8bab656a910829ab9c32d7700c570be6' 27 | } 28 | }) 29 | expect(wrapper.props().file).toBe(undefined) 30 | }) 31 | 32 | test('has props', () => { 33 | const wrapper = shallow(VueEmbedGist, { 34 | propsData: { 35 | gistId: '8bab656a910829ab9c32d7700c570be6', 36 | file: 'index.js' 37 | } 38 | }) 39 | expect(wrapper.props().gistId).not.toBe(undefined) 40 | expect(wrapper.props().gistId).toBe('8bab656a910829ab9c32d7700c570be6') 41 | expect(wrapper.props().file).not.toBe(undefined) 42 | expect(wrapper.props().file).toBe('index.js') 43 | }) 44 | }) --------------------------------------------------------------------------------