coderaiser/minify

Split tests from libOptions.js

Closed this issue · 3 comments

Split tests from test/libOptions.js so there was one assertion and t.end() similar to test/minify

Ahh I forgot to call t.end().. embarrassing :D

I'm not sure I see the value in splitting these tests such that each only has one assertion though?

The assertions in place ensure that the single call made by each unit went exactly as expected.?

Using test.end() it’s a convention started from tape, yes we can avoid it, and there is such place in @putout/test. But it uses destructructoring on test function argument, because:

  • one assertion per test, Single Responsibility Principle: Do one thing and do it well do ☝️;
  • when you have only one assertion, what purpose of using variable t? It just have no sense;
test(‘minify: options: no’, ({deepEqual}) => {
    const error = assign(Error(‘Cannot read file’), {
        code: ‘ENOENT’
    });
    const options = readOptions({
        readFile: stub().throws(error), 
    });
   
   const expected = {};
   
    deepEqual(data, expected);
});

But I don’t know either it’s more readable 🤷🏽 then:

test(‘minify: options: no’, ({deepEqual}) => {
    const error = assign(Error(‘Cannot read file’), {
        code: ‘ENOENT’
    });
    const options = readOptions({
        readFile: stub().throws(error), 
    });
   
   const expected = {};
   
    t.deepEqual(data, expected);
    t.end(); 
});

t.end() shows that there will be no more assertions, only one is allowed.

Landed in v7.2.0 🎉