Skip to content

Commit

Permalink
Add a clear error when fixture is not defined (closes #2913) (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev authored and AndreyBelym committed Nov 13, 2018
1 parent 591ed4c commit 26aee9f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/api/structure/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ export default class Test extends TestingUnit {
this.fn = null;
this.beforeFn = null;
this.afterFn = null;
this.requestHooks = this.fixture.requestHooks.length ? Array.from(this.fixture.requestHooks) : [];
this.requestHooks = [];

return this.apiOrigin;
}

_add (name, fn) {
assertType(is.string, 'apiOrigin', 'The test name', name);
assertType(is.function, 'apiOrigin', 'The test body', fn);
assertType(is.nonNullObject, 'apiOrigin', `The fixture of '${name}' test`, this.fixture);

this.name = name;
this.fn = wrapTestFunction(fn);
this.name = name;
this.fn = wrapTestFunction(fn);
this.requestHooks = union(this.requestHooks, Array.from(this.fixture.requestHooks));

if (this.testFile.collectedTests.indexOf(this) < 0)
this.testFile.collectedTests.push(this);
Expand Down
23 changes: 23 additions & 0 deletions test/server/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,29 @@ describe('API', function () {
});
});
});

it('Should raise an error if fixture is missing', function () {
const file = resolve('test/server/data/test-suites/fixture-is-missing/testfile.js');

return compile(file)
.then(function () {
throw new Error('Promise rejection expected');
})
.catch(function (err) {
assertAPIError(err, {
stackTop: file,

message: 'Cannot prepare tests due to an error.\n\n' +
'The fixture of \'Test\' test is expected to be a non-null object, but it was null.',

callsite: ' 1 |// fixture `Fixture`\n' +
' 2 |\n' +
' > 3 |test(\'Test\', () => {\n' +
' 4 | return \'yo\';\n' +
' 5 |});'
});
});
});
});

describe('Selector', function () {
Expand Down
6 changes: 6 additions & 0 deletions test/server/data/test-suites/fixture-is-missing/testfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// fixture `Fixture`

test('Test', () => {
return 'yo';
});

0 comments on commit 26aee9f

Please sign in to comment.