forked from akxcv/vuera
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,223 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
"jsx-quotes": ["error", "prefer-single"], | ||
"new-cap": "off", | ||
"no-param-reassign": "off" | ||
} | ||
}, | ||
"plugins": ["vue"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
browser: true, | ||
collectCoverageFrom: ['src/**/*.js', 'dist/babel.js'], | ||
setupFiles: ['./tests/__setup__.js'], | ||
testMatch: ['<rootDir>/tests/**/*-test.js'], | ||
moduleNameMapper: { | ||
vue: 'vue/dist/vue.js', | ||
}, | ||
moduleFileExtensions: ['js', 'vue'], | ||
transform: { | ||
'\\.js$': 'babel-jest', | ||
'\\.vue$': 'jest-vue-preprocessor', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"env": { | ||
"jest": true, | ||
"browser": true | ||
}, | ||
"rules": { | ||
"react/prop-types": "off", | ||
"react/prefer-stateless-function": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Vue from 'vue' | ||
import { React } from '../src' | ||
import PureFunctionalComponent from './fixtures/ReactPureFunctionalComponent' | ||
import Component from './fixtures/ReactComponent' | ||
|
||
const mockReset = jest.fn() | ||
const makeVueInstanceWithReactComponent = passedComponent => | ||
new Vue({ | ||
el: '#app', | ||
data: { | ||
component: passedComponent, | ||
message: 'Message for React', | ||
}, | ||
computed: { | ||
passedProps () { | ||
return { | ||
message: this.message, | ||
reset: this.reset, | ||
} | ||
}, | ||
}, | ||
methods: { | ||
reset: mockReset, | ||
}, | ||
template: ` | ||
<div> | ||
<input v-model="message" /> | ||
<react :component="component" :passedProps="passedProps"></react> | ||
</div> | ||
`, | ||
components: { React }, | ||
}) | ||
|
||
describe('ReactInVue', () => { | ||
beforeEach(() => { | ||
document.body.innerHTML = '<div id="app"></div>' | ||
}) | ||
|
||
it('mounts the React component correctly', () => { | ||
makeVueInstanceWithReactComponent(Component) | ||
expect(document.body.innerHTML).toBe( | ||
'<div><input> <div><div><span>Message for React</span><button></button></div></div></div>' | ||
) | ||
}) | ||
|
||
it('mounts the pure React component correctly', () => { | ||
makeVueInstanceWithReactComponent(PureFunctionalComponent) | ||
expect(document.body.innerHTML).toBe( | ||
'<div><input> <div><div><span>Message for React</span><button></button></div></div></div>' | ||
) | ||
}) | ||
|
||
it('synchronises props', () => { | ||
const vm = makeVueInstanceWithReactComponent(Component) | ||
vm.message = 'New message!' | ||
return Vue.nextTick().then(() => { | ||
expect(vm.$data.message).toBe('New message!') | ||
expect(document.body.innerHTML).toContain('New message!') | ||
}) | ||
}) | ||
|
||
test('functions work', () => { | ||
makeVueInstanceWithReactComponent(Component) | ||
const button = document.querySelector('button') | ||
|
||
expect(mockReset.mock.calls.length).toBe(0) | ||
button.click() | ||
expect(mockReset.mock.calls.length).toBe(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import { Vue } from '../src' | ||
import VueComponent from './fixtures/VueComponent' | ||
import VueSingleFileComponent from './fixtures/VueSingleFileComponent.vue' | ||
import normalizeHTMLString from './utils/normalizeHTML' | ||
|
||
const mockReset = jest.fn() | ||
const makeReactInstanceWithVueComponent = passedComponent => { | ||
class ReactApp extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
this.state = { | ||
message: props.message, | ||
} | ||
} | ||
|
||
onChange = e => { | ||
this.setState({ message: e.currentTarget.value }) | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<input type='text' value={this.state.message} onChange={this.onChange} /> | ||
<Vue component={passedComponent} message={this.state.message} reset={mockReset} /> | ||
</div> | ||
) | ||
} | ||
} | ||
ReactDOM.render(<ReactApp message='Message for Vue' />, document.getElementById('root')) | ||
} | ||
|
||
describe('VueInReact', () => { | ||
beforeEach(() => { | ||
document.body.innerHTML = '<div id="root"></div>' | ||
}) | ||
|
||
it('mounts the Vue component correctly', () => { | ||
makeReactInstanceWithVueComponent(VueComponent) | ||
expect(document.body.innerHTML).toBe( | ||
normalizeHTMLString( | ||
`<div id="root"> | ||
<div> | ||
<input type="text" value="Message for Vue"> | ||
<div> | ||
<span>Message for Vue</span> <button></button> | ||
</div> | ||
</div> | ||
</div>` | ||
) | ||
) | ||
}) | ||
|
||
/** | ||
* SKIPPING: having trouble with jest-vue-preprocessor | ||
*/ | ||
it('mounts the Vue single file component correctly', () => { | ||
makeReactInstanceWithVueComponent(VueSingleFileComponent) | ||
expect(document.body.innerHTML).toBe( | ||
normalizeHTMLString( | ||
`<div id="root"> | ||
<div> | ||
<input type="text" value="Message for Vue"> | ||
<div> | ||
<span>Message for Vue</span> <button></button> | ||
</div> | ||
</div> | ||
</div>` | ||
) | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './polyfills/raf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
|
||
export default class Component extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
<span>{this.props.message}</span> | ||
<button onClick={this.props.reset} /> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
|
||
export default function PureFunctionalComponent (props) { | ||
return ( | ||
<div> | ||
<span>{props.message}</span> | ||
<button onClick={props.reset} /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Vue from 'vue' | ||
|
||
export default Vue.component('vue-component', { | ||
props: ['message', 'reset'], | ||
template: ` | ||
<div> | ||
<span>{{ message }}</span> | ||
<button @click="reset"></button> | ||
</div> | ||
`, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<template> | ||
<div> | ||
<span>{{ message }}</span> | ||
<button @click="reset"></button> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'what', | ||
props: ['message', 'reset'], | ||
} | ||
</script> | ||
|
||
<style> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable */ | ||
// https://gist.github.com/paulirish/1579671 | ||
;(function() { | ||
var lastTime = 0 | ||
var vendors = ['ms', 'moz', 'webkit', 'o'] | ||
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | ||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'] | ||
window.cancelAnimationFrame = | ||
window[vendors[x] + 'CancelAnimationFrame'] || | ||
window[vendors[x] + 'CancelRequestAnimationFrame'] | ||
} | ||
|
||
if (!window.requestAnimationFrame) | ||
window.requestAnimationFrame = function(callback, element) { | ||
var currTime = new Date().getTime() | ||
var timeToCall = Math.max(0, 16 - (currTime - lastTime)) | ||
var id = window.setTimeout(function() { | ||
callback(currTime + timeToCall) | ||
}, timeToCall) | ||
lastTime = currTime + timeToCall | ||
return id | ||
} | ||
|
||
if (!window.cancelAnimationFrame) | ||
window.cancelAnimationFrame = function(id) { | ||
clearTimeout(id) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function normalizeHTMLString (string) { | ||
return string.replace(/\n\s*/g, '') | ||
} |
Oops, something went wrong.