That paramIsString variable isnât needed. It was only used to help you place the comparison in there.
You can âinline the variableâ, which is a very common technique to remove unwanted variables. What you do is you copy the code that is assigned to the variable, and replace other occurrences of that variable with the copied code instead.
And now, the paramType variable really isnât needed. You can inline the paramType variable, by copying the code that is assigned to the variable, and replace paramType in the return statement with that copied code.
function isVideoId(videoIds) {
return typeof videoIds === "string";
}
Are we up to doing the next test?
xit("when init is a video id and has data-id", function() {
//given
video.dataset.id = "0dgNc5S8cLI";
//when
initVideoPlayer();
//then
expect(options.videoId).toBe("0dgNc5S8cLI");
//cleanup
delete video.dataset.id;
});
Look at the description of the test, and you will see that the test doesnât yet do what the description describes.
Also the description isnât specific enough, and needs to explain that the video id will be used instead of the data-id. We can add a comma to the end the description and add âwill use video idâ.
After that, give the initVideoPlayer() function call a different video id from the one that dataset is using.
Then in the expectation, change the video id there. It shouldnât be the data-id one, it needs to be the different one used to init the video player.
xit("when init is a video id and has data-id, will use video id", function() {
//given
video.dataset.id = "0dgNc5S8cLI";
//when
initVideoPlayer("0dgNc5S8cLI");
//then
expect(options.videoId).toBe("mnfmQe8Mv1g");
//cleanup
delete video.dataset.id;
});
it("when init is a video id and has data-id, will use video id", function() {
//given
video.dataset.id = "0dgNc5S8cLI";
//when
initVideoPlayer("mnfmQe8Mv1g");
//then
expect(options.videoId).toBe("mnfmQe8Mv1g");
//cleanup
delete video.dataset.id;
});
We need instead to put together a test that accurately simulates the problem, so that when we page that test pass, we can then be sure that weâve fixed the problem.
What is wanted here is an onready event on the videoPlayer code, so that the manageCover code can put stuff into that onready event. That way when the videoPlayer is ready, it will run the onready event causing the manageCover to then do its thing.
First we add tests to provide support for managePlayer onready events. That support being to provide an interface by which onready events can be added.
Then we add tests for manageCover to check if onready events can be added. If the canât then manageCover just runs as normal. If they can then manageCover delays running by adding its run code as an onready event instead.
That is the pathway. Now we step along it with slow but careful steps. The first step is adding a new describe section to the videoPlayer code called âonreadyâ and in that section, we add a test called âadd onreadyâ