Reputation: 41
Below is the basic idea of what I'm trying to achieve.
suite.tmpl.js:
export default function(config) {
describe('suite', function() {
it('does something', function() {
expect(config.items.length).toBe(config.mockedItems.length);
});
};
something.spec.js
import getSomeData from 'here';
import suite from 'suite.tmpl';
fdescribe('the page', function() {
let data, config, mockedItems = [1, 2, 3];
describe('test', function() {
getSomeData.then(result => data = result);
config = {
data: data,
mockedItems: mockedItems
};
suite(config);
});
});
The reason for this is I have many elements throughout the app using the same design and needing to copy tests all over the place.
How can I create a reusable set of tests?
Upvotes: 2
Views: 413
Reputation: 41
My example seems to work well as an additional layer of abstraction. Here's an example of my implementation...
suite.tmpl.js:
export default {
suite: function(config) {
describe('suite', function() {
it('does something', function() {
expect(config.data.length).toBe(config.mockedItems.length);
});
});
}
};
something.spec.js
import something from 'here';
import tests from 'suite.tmpl';
describe('the page', function() {
let data, config, mockedItems = [1, 2, 3];
describe('suite', function() {
something.then(result => data = result);
config = {
data: data,
mockedItems: mockedItems
};
tests.suite(config);
});
});
Upvotes: 1