Skip to content

Commit

Permalink
added: returned function name is the name of the suite
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 28, 2020
1 parent fb4292a commit e6cccc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/vest/src/core/createSuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ const createSuite = (name, tests) => {
}

// returns validator function
return (...args) => {
const output = runWithContext(ctxRef, context => {
registerSuite();
const { suiteId } = context;
tests.apply(null, args);
mergeExcludedTests(suiteId);
// and sets the function name
// to the name of the suite
return Object.defineProperty(
(...args) => {
const output = runWithContext(ctxRef, context => {
registerSuite();
const { suiteId } = context;
tests.apply(null, args);
mergeExcludedTests(suiteId);

[...getSuiteState(suiteId).pending].forEach(runAsyncTest);
return produce(getSuiteState(suiteId));
});
return output;
};
[...getSuiteState(suiteId).pending].forEach(runAsyncTest);
return produce(getSuiteState(suiteId));
});
return output;
},
'name',
{ value: name }
);
};

export default createSuite;
4 changes: 4 additions & 0 deletions packages/vest/src/core/createSuite/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ describe('Test createSuite module', () => {
it('should be a function', () => {
expect(typeof createSuite('suiteName', noop)).toBe('function');
});

test("returned function name is the suite's name", () => {
expect(createSuite('boop', noop).name).toBe('boop');
});
});

describe('When returned function is invoked', () => {
Expand Down

0 comments on commit e6cccc9

Please sign in to comment.