-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Access to component state data #45
Changes from 5 commits
e103e58
436399d
878e60f
98d3f35
91de97a
1efecf2
60e6cce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,44 @@ describe('trackEventMethodDecorator', () => { | |
expect(trackEvent).toHaveBeenCalledWith(dummyData); | ||
expect(spyTestEvent).toHaveBeenCalledWith('x'); | ||
}); | ||
|
||
it('properly passes through the correct arguments when trackingData is a function', () => { | ||
const dummyData = {}; | ||
const trackingData = jest.fn(() => dummyData); | ||
const trackEvent = jest.fn(); | ||
const spyTestEvent = jest.fn(); | ||
const dummyArgument = 'x'; | ||
|
||
class TestClass { | ||
constructor() { | ||
this.props = { | ||
tracking: { | ||
trackEvent, | ||
}, | ||
}; | ||
this.state = { | ||
myState: "someState", | ||
}; | ||
} | ||
|
||
@trackEventMethodDecorator(trackingData) | ||
handleTestEvent = spyTestEvent | ||
} | ||
|
||
const myTC = new TestClass(); | ||
myTC.handleTestEvent(dummyArgument); | ||
|
||
// Access the trackingData arguments | ||
const trackingDataArguments = trackingData.mock.calls[0]; | ||
|
||
expect(trackingData).toHaveBeenCalledTimes(1); | ||
expect(trackingDataArguments[0]).toEqual(myTC.props); | ||
expect(trackingDataArguments[1]).toEqual(myTC.state); | ||
// Here we have access to the raw `arguments` object, which is not an actual Array, | ||
// so in order to compare, we convert the arguments to an array. | ||
expect(Array.from(trackingDataArguments[2])).toEqual([dummyArgument]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally I tried: expect(trackingData).toHaveBeenCalledWith(myTC.props, myTC.state, spyTestEvent.mock.calls[0])
// also tried ['x'] or [dummyArgument] in this case However, you end up comparing an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Thanks for the comment as well 馃憤 |
||
|
||
expect(trackEvent).toHaveBeenCalledWith(dummyData); | ||
expect(spyTestEvent).toHaveBeenCalledWith(dummyArgument); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jest docs