-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Description
🚀 Feature Proposal
Allow unit tests to be exported with configuration options.
Motivation
Allow Library-A to export unit tests, so that Library-B (acting as a port of Library-B) can treat the unit tests as a spec, but provide configuration options.
Example
Library-A has a set of HTML templates in a templating language such as handlebars, nunjucks, along with a set of unit tests ensuring the HTML output of a given render function meets certain criteria.
Library-B is a port of Library-A using React. Library-B would like to run the spec provided by Library-A, but provide a custom render function.
Library-A
const nunjucksRender = require('../util/nunjucks-render')
const cheerio = require('cheerio')
const spec = ({render}) => describe('Button', () => {
it('renders the default example', () => {
const $ = cheerio.load(render('button', {text: 'Save and continue'}))
const $component = $('.button')
expect($component.get(0).tagName).toEqual('button')
expect($component.text()).toContain('Save and continue')
})
})
// Not sure best way this would be handled:
if(???) {
// In Library-A we want to execute the unit tests with the default renderer
spec({render: nunjucksRender})
}
// We want to export the tests to be used by ports
module.exports = spec
Library-B
const reactRender = require('../util/react-render')
const libraryASpec = require('library-a/spec/button')
describe('Button', () => {
it('matches library-a spec') {
libraryASpec({render: reactRender});
}
})