Skip to content

Commit

Permalink
Add test to ensure components can be imported
Browse files Browse the repository at this point in the history
Add a failing test that tries to render every component using a different base path for Nunjucks - any imports that assume a particular base path will then throw exceptions.
  • Loading branch information
36degrees committed May 31, 2018
1 parent eaafaf9 commit 420f674
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/all.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-env jest */

const { allComponents } = require('../../lib/file-helper')

const configPaths = require('../../config/paths.json')

// We can't use the render function from jest-helpers, because we need control
// over the nunjucks environment.
const nunjucks = require('nunjucks')

describe('When nunjucks is configured with a different base path', () => {
beforeAll(() => {
// Create a new Nunjucks environment that uses the src directory as its
// base path, rather than the components folder itself
nunjucks.configure(configPaths.src)
})

allComponents.forEach((component) => {
describe(`the ${component} component`, () => {
it('can be rendered without erroring', () => {
expect(() => {
nunjucks.render(`components/${component}/template.njk`, {})
}).not.toThrow()
})
})
})
})

0 comments on commit 420f674

Please sign in to comment.