describedefines the name of the subject that you want to test. Its value can be any string that is relevant to your exercise. You can have multiple
describecalls in your evaluation if you need to test different subjects.
describe, you can define as many tests as you want that are related to that same subject, by calling the
itfunction. The string argument that
itreceives describes how the subject is expected to behave.
describeyou have access to the React component. You can:
shallow()to create a component without creating its child React components.
mount()to create a component including its child React components.
itto give a meaningful description of the test. In the above example, if any of the tests fail, this is what the student will see:
expectfunction is what actually decides whether a test fails or succeeds. Once you have a reference to a piece of the DOM (or other value) generated by student's code, you can assert whether it behaves as it should by calling:
toEqual()is called a Jest "matcher" and there are many more that you can use, like:
notif you want a negative assertion.
expectcalls fail inside a test, that test will be marked as failed by Jest and reported back to the student. If you want to give the student more granular feedback about a failing assertion, in your own words, you can pass an additional string argument to the matcher.
expect()where you pass in a message. This is provided by the jest-expect-message library.
Foothat is expected to return
Foo, and another one with a function
Barthat is expected to return