question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test container with multiple components translated

See original GitHub issue

I am trying to test a container that has multiple components inside. When I mount the container all the nested containers will be mounted but I have an error:

TypeError: Cannot read property 'getFixedT' of undefined

Some of my components are exporting with the translation decorator:

export const TextAreaCounterComponent = TextAreaCounter;

export default translate(['defaultNamespace'])(TextAreaCounterComponent);

How can I test this containers?

  const mockT = () => 'Hello';
  const middlewares = [];
  const mockStore = configureStore(middlewares);

  const initialState = {
    login: {
      loggedIn: true,
    },
    app: {
      isLoading: false,
      popupIsOpen: false,
      tabSelected: 0
    }
  };
  const store = mockStore(initialState);

  const wrapper = mount(
    <Provider store={store}>
      <Partner t={mockT} />
    </Provider>
  );

  it.only('should mount partner page container', () => {
    expect(wrapper.find('.wrap').length).toBe(1);
  });

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
gilmillasseaucommented, Dec 19, 2016
  const mockI18n = {
    t(k) {
      return k;
    },
    on() {
    },
    getFixedT(k) {
      return (k) => k;
    },
    loadNamespaces(arg) {
      return (arg) => arg;
    }
  };
  const wrapper = mount(
    <I18nextProvider i18n={mockI18n}>
      <Provider store={store}>
        <Partner />
      </Provider>
    </I18nextProvider>
  );

This works

1reaction
jamuhlcommented, Jul 6, 2017

how do you import i18next? seems to be an issue related to import (using typescript?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Angular container components
Container components translate component -specific events to application state commands — or actions to put it in Redux/NgRx Store terms.
Read more >
How to use container components without sacrificing testability
Use few, high-level container components, which render presentational components. The reason for this is because presentational components are more reusable ( ...
Read more >
How to Perform Integration Testing using JUnit 5 and ...
These Docker containers are lightweight, and once the tests are finished the ... various other components like Kafka, SOLR, Redis, and more.
Read more >
NG0300: Multiple components match with the same tagname
If you're having trouble finding multiple components with this selector tag name, check for components from imported component libraries, such as Angular ...
Read more >
Common mistakes with React Testing Library
Not using Testing Library ESLint plugins. Importance: medium. If you'd like to avoid several of these common mistakes, then the official ESLint ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found