An error still infrequently occurs when the āshouldnātā test is the first test that runs.
We can easily experience that by forcing the āshouldnātā test to run, using fit instead of just it
videoPlayer tests > init > shouldnāt let you play until the player is ready TypeError: window.onYouTubeIframeAPIReady is not a function
That one happens because in the resetPlayer() function, we have not yet initialized videoPlayer.
Before calling window.onYouTubeIframeAPIReady() call videoPlayer.init() to initialize the video player.
This has been a lot of additions, but when all of the tests reliably pass we then move on to refactoring, which is where we can reorder and restructure the code to help simplify things.
Please look at what has been done with the init statement in the āshouldnātā test. You should see what to do from there.
Itās taken me a while to realize, but we should not have delayed improvements to the init function. Well itās too late now, we are in the midst of things. Afterwards we can work on improving the init function so that it behaves appropriately when given no arguments.
Test passes Fail Pass ā Refactor
All tests are now passing, so itās on to the next stage, refactoring.
Refactor the code Fail Pass ā Refactor
We donāt just make changes to the code without understanding what they are for.
The refactorings need to be driven by an understanding of what need to be improved.
A good way to arrive at those improvements is to understand what the problems were.
In this recent set of work since adding the āshouldnātā test, can you create a list of all the different problems that there were?
Those are the high-level problems that we are wanting to solve, but thatās not what Iām talking about.
The situation that Iām talking about is after we creates that āshouldnātā test to simulate the problem, we needed to do some other things to get the other tests working again. Those things are:
we needed to add a cleanup section, where stubYT() is called before initializing the video player
in resetPlayer() after assigning window.YT (similar to stubYT), we needed to initialize the video player before calling the ready event
Also, in the initVIdeoPlayer function when we initialize the video player, we call the ready event.
Those all involve stubYT, video player initialization, and the ready event in a specific sequence:
stubYT()
videoPlayer initialization
call the ready event
The cleanup of the āshouldnātā test is only needed, I think, because when the other tests call initVideoPlayer, things arenāt being fully or properly initialized.
We should be able to completely remove that cleanup section by properly intializing things in the initVideoPlayer function.
That is what there is to be learned from this recent work, and is what helps to give focus to what this set of refactoring needs to achieve.
In the four part process of dealing with the play button issue:
Test the problem with tests failing
Test the problem with tests passing
Test the solution with tests failing
Test the solution with tests passing
We are part-way through part 2, but not finished with part 2 until refactoring has been done.
Anything relating to improving the init function or other things can not be dealt with until after we have fully completed the above steps for the play issue.
From the investigation in post #1714 it was concluded that an appropriate structure involved stubYT, init, and the ready handler.
Currently stubYT() is called in the beforeAll section. That we now know is not such a good place for it due to changes that can occur, so moving the stubYT() call so that itās instead the first thing inside the initVideoPlayer() function, is a good start to things.
TypeError: Cannot read properties of undefined (reading ānodeNameā)
function initVideoPlayer(videoIds = ["0dgNc5S8cLI"]) {
iframe = stubYT();
This we do after refactoring?
Afterwards we can work on improving the init function so that it behaves appropriately when given no arguments.
Anything relating to improving the init function or other things can not be dealt with until after we have fully completed the above steps for the play issue.
Yes that helps thanks. Knowing that it is the āshouldnātā test thatās failing, I can force the test and get it to always fail when itās the first of the videoPlayer tests to run.
The issue here is that the iframe variable hasnāt yet been defined. We can fix that by giving the resetPlayer function a suitable iframe element.