Answer the question
In order to leave comments, you need to log in
How do you go about testing a transform function?
There is a function that takes two data structures as input, attaches the data of the second structure to the first and converts the final result to a different format. All actions are performed by a set of smaller functions, each of which is responsible for its part. If I have to write a test that checks the correctness of the final result, what is the correct approach? Actually, what approach generally should be?
Similar to the example from the Jest documentation
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
Answer the question
In order to leave comments, you need to log in
It depends on the details, but in general - the first option, yes. You need to lock the input data, lock the expected output, and test like that. But this does not mean that smaller internal functions should not be tested.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question