Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject layout through onLayout's View #1708

Closed
ALWAL12 opened this issue Sep 15, 2016 · 2 comments
Closed

Inject layout through onLayout's View #1708

ALWAL12 opened this issue Sep 15, 2016 · 2 comments

Comments

@ALWAL12
Copy link

ALWAL12 commented Sep 15, 2016

I have a component that vary its rendering depending on its width. To achieve this, I use the onLayout property of View component. Hence, in my tests, I don't seem to be able to inject a mocked layout and the method onLayout does not seem to be called at all.

Example of a snapshot test:

import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';
// my components
import RequirementAssignees from '../RequirementAssignees';
import Account from '../../../authentication/domain/Account';
import Assignment from '../../domain/Assignment';

describe('<RequirementAssignees />', () => {
  it('can render few assignments ', () => {
    const assignments = [
      new Assignment({ id: 1, account: new Account({ id: 100, firstName: 'John', lastName: 'Doe' }) }),
      new Assignment({ id: 2, account: new Account({ id: 200, firstName: 'Jane', lastName: 'Doe' }) }),
      new Assignment({ id: 3, account: new Account({ id: 300, firstName: 'Uncle', lastName: 'Sam' }) }),
      new Assignment({ id: 4, account: new Account({ id: 400, firstName: 'Aunt', lastName: 'Nina' }) }),
    ];

    const tree = renderer.create(
      <RequirementAssignees assignments={assignments} />
    ).toJSON();

    expect(tree).toMatchSnapshot();
  });
});

I'm not sure how to approach this.

Version
jest: 15.1.1
node: v5.3.0
npm: 3.3.12
OS: Windows 10

@cpojer
Copy link
Member

cpojer commented Sep 15, 2016

We are not going to be able to help you without a repository that shows this issue. Note that this is unlikely a Jest issue but rather a testing question on how to write a test for a specific react-native component. Feel free to add more info but I'm going to close this to manage our queue.

Happy to reopen if this turns out to be a Jest issue.

@cpojer cpojer closed this as completed Sep 15, 2016
This was referenced Nov 17, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants