Не удается прочитать свойство 'styledComponentId' из неопределенного - PullRequest
0 голосов
/ 16 января 2019

Я использую styleled-component, но не смог найти способ найти элемент match. Я получил ошибку

TypeError: Cannot read property 'styledComponentId' of undefined

Это мой index.js const Container = styled.h1` размер шрифта: 14px;

import React from 'react'
import styled from 'styled-components'
const Container = styled.h1`
  font-size: 14px;
`

export default () => (<div>
    <Container>Hello</Container>
</div>)
export { Container }

Это мой тест (index.spec.js)

import React from 'react'
import { shallow } from 'enzyme'
import IndexPage from './index'
import { Container } from './index'
import { enzymeFind } from 'styled-components/test-utils'

describe('Pages', () => {
  describe('Index page', () => {
    it('should have a container', function() {
      const wrapper = shallow(<IndexPage />)
      expect(enzymeFind(wrapper, Container).exists()).toBe(true)
    })
  })
})

1 Ответ

0 голосов
/ 16 января 2019

В вашем index.spec.js у вас есть:

import IndexPage from './index'
import { Container } from './index'

Тем не менее, код, который вы разместили, имеет экспорт по умолчанию только в index.js - возможно, вы смешиваете файлы, из которых вы импортируете.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...