Skip to content

Commit

Permalink
fix(commonTests): componentClassName for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Jul 18, 2016
1 parent 7e99141 commit c5b0425
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/specs/commonTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import faker from 'faker'
import _ from 'lodash'
import path from 'path'
import React, { createElement } from 'react'
import ReactDOMServer from 'react-dom/server'

import META from 'src/utils/Meta'
import * as stardust from 'stardust'
Expand All @@ -18,6 +19,13 @@ const componentInfo = componentCtx.keys().map(key => {
const Component = componentCtx(key).default
const { _meta, prototype } = Component

if (!_meta) {
throw new Error([
'Component is missing a static _meta object property. This should help identify it:',
`Rendered:\n${ReactDOMServer.renderToStaticMarkup(<Component />)}`,
].join('\n'))
}

const constructorName = prototype.constructor.name
const filePath = key
const filename = path.basename(key)
Expand All @@ -26,7 +34,12 @@ const componentInfo = componentCtx.keys().map(key => {
? _meta.name.replace(_meta.parent, '')
: null

const componentClassName = (subComponentName || constructorName).toLowerCase()
// name of the component, sub component, or plural parent for sub component groups
const componentClassName = (
META.isChild(Component)
? subComponentName.replace(/Group$/, `${_meta.parent}s`)
: _meta.name
).toLowerCase()

return {
_meta,
Expand All @@ -48,7 +61,6 @@ const componentInfo = componentCtx.keys().map(key => {
export const isConformant = (Component, requiredProps = {}) => {
// tests depend on Component constructor names, enforce them
if (!Component.prototype.constructor.name) {
const ReactDOMServer = require('react-dom/server')
throw new Error([
'Component is not a named function. This should help identify it:',
`static _meta = ${JSON.stringify(Component._meta, null, 2)}`,
Expand Down

0 comments on commit c5b0425

Please sign in to comment.