-
Notifications
You must be signed in to change notification settings - Fork 12
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(SFINT-3353): Test cleaning #87
Conversation
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.
nice catches!
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.
Nice job!
@@ -109,16 +104,16 @@ describe('ExpandableList', () => { | |||
const el = list.element.querySelector<HTMLElement>('.coveo-more-less'); | |||
el.click(); | |||
|
|||
return delay(() => { | |||
delay(() => { |
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.
Since delay()
returns a Promise
, shouldn't we use await delay(...)
instead?
The way I understand it, the test currently exits before the expectations are verified.
}); | ||
|
||
it('should pass the user id option to each of it sub components', () => { | ||
it('should pass the user id option to each of it sub components', async () => { |
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.
...to each of it ...
-> ...to each of its ...
|
||
expect(spyDispatchEvent.calledOnceWith(new CustomEvent('userActionsPanelHide'))); | ||
expect(spyDispatchEvent.calledOnce); |
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.
Shouldn't it be expect(spyDispatchEvent.calledOnce).toBe(true)
instead?
const spyDispatchEvent = sandbox.spy(mock.cmp.element, 'dispatchEvent'); | ||
|
||
mock.cmp.hide(); | ||
|
||
expect(spyDispatchEvent.calledOnceWith(new CustomEvent('userActionsPanelHide'))); | ||
expect(spyDispatchEvent.calledOnce); |
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.
Shouldn't it be expect(spyDispatchEvent.calledOnce).toBe(true)
instead?
What
While investigating SFINT-3353, I discovered several issues in the UT
The actual 'fix' for SFINT-3353 will be done in a second term to have a clear split between refacto' and fix.
Improper use of
expect
:https://jasmine.github.io/api/3.6/global.html#expect
TL;DR: Use matchers after expect. Always.
This will pass. expect is not Assert. This will not pass:
Issue with Stub, jasmine and yield function.
Various, various issues. My goal was to, whenever possible to 'flatten' and synchronize the tests, and avoid delay as much as possible (except when used to 'flush' the promise stack see
waitForPromiseCompletions
).How to flatten delay
Doing an
await(delay(()=>{})
ensure that all Promises are resolved before continuing. (assuming there's no setTimeout&co going on).This is due to how microtasks and (macro)tasks work https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide
So, long story short:
await(delay(()=>{})
are ran (if they encounter a setTimeout so be it, they add it to the (macro)task queue, which will be executed once all promises are executed. If a promise is added, however, see the article, but from what I understand, it's executed before the next (macro)taskHow did you test your tests.
By hand, most of them failed at first so, not a lot of choices (I won't say I checked all of them by hand, but a good 75%)
Further Improvements
ClickedDocumentList
and theExpendableList
)