-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] Deprecate dispatch in place of trigger
- Loading branch information
1 parent
3f10b5c
commit 3c87f3c
Showing
8 changed files
with
180 additions
and
11 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
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,24 @@ | ||
# trigger(eventName) | ||
|
||
trigger an event on the wrapper | ||
|
||
### Arguments | ||
|
||
event (`String`): type of event (e.g. click). | ||
|
||
## Example | ||
|
||
```js | ||
import { mount } from 'avoriaz'; | ||
import sinon from 'sinon'; | ||
import Foo from './Foo'; | ||
|
||
const clickHandler = sinon.stub(); | ||
const wrapper = mount(Foo, { | ||
propsData: { clickHandler }, | ||
}); | ||
|
||
wrapper.trigger('click'); | ||
|
||
expect(clickHandler.called).to.equal(true) | ||
``` |
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
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,84 @@ | ||
import mount from '../../../../src/mount'; | ||
import ClickComponent from '../../../resources/components/event-components/ClickComponent.vue'; | ||
import ClickToggleComponent from '../../../resources/components/event-components/ClickToggleComponent.vue'; | ||
import KeydownComponent from '../../../resources/components/event-components/KeydownComponent.vue'; | ||
import KeydownWithModifier from '../../../resources/components/event-components/KeydownWithModifierComponent.vue'; | ||
|
||
describe('trigger', () => { | ||
it('causes click handler to fire when wrapper.trigger("click") is called on a child node', () => { | ||
const childClickHandler = sinon.stub(); | ||
const wrapper = mount(ClickComponent, { | ||
propsData: { childClickHandler, parentClickHandler: () => {} }, | ||
}); | ||
const button = wrapper.find('#button')[0]; | ||
button.trigger('click'); | ||
|
||
expect(childClickHandler).to.be.calledOnce; | ||
}); | ||
|
||
it('causes click handler to fire when wrapper.trigger("click") is fired on root node', () => { | ||
const parentClickHandler = sinon.stub(); | ||
const wrapper = mount(ClickComponent, { | ||
propsData: { childClickHandler: () => {}, parentClickHandler }, | ||
}); | ||
wrapper.trigger('click'); | ||
|
||
expect(parentClickHandler).to.be.calledOnce; | ||
}); | ||
|
||
it('causes click handler to fire when wrapper.trigger("click") is fired on root node', () => { | ||
const parentClickHandler = sinon.stub(); | ||
const TestComponent = { | ||
render: h => h(ClickComponent, { | ||
props: { | ||
childClickHandler: () => {}, parentClickHandler, | ||
}, | ||
}), | ||
}; | ||
const wrapper = mount(TestComponent); | ||
wrapper.find(ClickComponent)[0].trigger('click'); | ||
|
||
expect(parentClickHandler).to.be.calledOnce; | ||
}); | ||
|
||
it('causes keydown handler to fire when wrapper.trigger("keydown") is fired on root node', () => { | ||
const keydownHandler = sinon.stub(); | ||
const wrapper = mount(KeydownComponent, { | ||
propsData: { keydownHandler }, | ||
}); | ||
wrapper.trigger('keydown'); | ||
|
||
expect(keydownHandler).to.be.calledOnce; | ||
}); | ||
|
||
it('causes keydown handler to fire when wrapper.trigger("keydown.enter") is fired on root node', () => { | ||
const keydownHandler = sinon.stub(); | ||
const wrapper = mount(KeydownWithModifier, { | ||
propsData: { keydownHandler }, | ||
}); | ||
wrapper.trigger('keydown.enter'); | ||
|
||
expect(keydownHandler).to.be.calledOnce; | ||
}); | ||
|
||
it('causes DOM to update after clickHandler method that changes components data is called', () => { | ||
const wrapper = mount(ClickToggleComponent); | ||
|
||
expect(wrapper.hasClass('active')).to.equal(false); | ||
|
||
wrapper.trigger('click'); | ||
|
||
expect(wrapper.hasClass('active')).to.equal(true); | ||
}); | ||
|
||
it('throws an error if type is not a string', () => { | ||
const wrapper = mount(ClickToggleComponent); | ||
const invalidSelectors = [ | ||
undefined, null, NaN, 0, 2, true, false, () => {}, {}, [], | ||
]; | ||
invalidSelectors.forEach((invalidSelector) => { | ||
const message = 'wrapper.trigger() must be passed a string'; | ||
expect(() => wrapper.trigger(invalidSelector)).to.throw(Error, message); | ||
}); | ||
}); | ||
}); |