My apologies - that was a typing error on my part. The casing is important, so it needs to be toHaveClass instead of tohaveClass. I’ll update the previous post now.
Not quite yet. Continuing to work our way up through the tests, we have the no-parameters test that still uses toThrow(), which can be much easier to understand when we use toThrowError() instead.
It’s going to be similar to the “needs a coverSelector parameter” test, but is instead about needing a container parameter.
Two things need to occur there that haven’t been done. Right now the test doesn’t tell us which error is expected to be thrown. You can have the test show you the error that’s thrown by giving toThrowError() a function parameter of /foo/ or something similar. That way you can then use the error message that’s shown to you to replace foo, with suitable text from the error instead.
The second thing that should occur from a test that expects an error, is to tell us what it needs to avoid that error. In this case it needs a function parameter similar to the other test that expects an error, but you really need to rename the test so that it tells us what function parameter it needs.
it("needs a function parameter of container", function() {
const fnCall = () => manageCover.init();
expect(fnCall).toThrowError(/foo/);
});
Where I then get this error:
Expected function to throw an exception with a message matching /foo/, but it threw an exception with message ‘Cannot read properties of undefined (reading ‘container’)’.
it("needs a function parameter of container", function() {
const fnCall = () => manageCover.init();
expect(fnCall).toThrowError(/Cannot read properties of undefined/);
});
We now seem to be in a pretty good state to move on to the addCoverHandler test. First we look at the addCoverHandler test called “needs a coverSelector parameter”. The next test after that should be called “with a coverSelector parameter” where we give the addEventHandler a coverSelector string as it’s parameter.
Yes that is wrong. The addCoverHandler function is being given an object as the argument to the function.
That is not a defined variable. What coverSelector is there, is a property of the object.
That is not an element. That is a string which is used as a selector. That selector would target a cover element, so it’s called a cover selector.
Are you able to better understand the instruction being given to you now?
Remember the recent post where I clearly pointed out the significant difference between property and parameter?
More accurately, that instruction should be to give addEventHandler a coverSelector string as its argument. For when you call functions they are called using arguments, and when you define functions, they are defined using parameters.