Created
January 29, 2018 13:14
-
-
Save lmiller1990/2c264448856853d139c10ca3c029df23 to your computer and use it in GitHub Desktop.
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
import Vue from 'vue' | |
const EvtBus = new Vue() | |
EvtBus.addEvent = (evt, fn) => { | |
EvtBus.$on(evt, () => { | |
fn() | |
}) | |
} | |
export { EvtBus } |
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
import { EvtBus } from './EventBus' | |
describe('EventBus', () => { | |
it('adds a new event using addEvent', () => { | |
const evtToAdd = () => {} | |
EvtBus.addEvent('test', evtToAdd) | |
expect(EvtBus._events['test']).toBeTruthy() | |
}) | |
}) |
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
import { shallow } from 'vue-test-utils' | |
import Test from './Test' | |
describe('Test', () => { | |
it('renders', () => { | |
const wrapper = shallow(Test) | |
wrapper.find('button').trigger('click') | |
expect(wrapper.emitted().test.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
<template> | |
<div> | |
<button @click="go">Emit event</button> | |
</div> | |
</template> | |
<script> | |
import { EvtBus } from './EventBus' | |
export default { | |
name: 'Test', | |
created () { | |
EvtBus.addEvent('test', () => { | |
console.log('Add this function to event bus') | |
}) | |
}, | |
methods: { | |
go () { | |
this.$emit('test') | |
EvtBus.$emit('test') | |
} | |
} | |
} | |
</script> | |
<style scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment