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

DatePicker#React does not change “intialDate” when receiving changed props from parent #749

Closed
BjornBakke opened this issue Feb 5, 2020 · 1 comment · Fixed by #882
Assignees
Labels
🐝 Bug Noe er feil eller ikke som det skal

Comments

@BjornBakke
Copy link

BjornBakke commented Feb 5, 2020

   it("should change date on new props", () => {
        const { container, getByTestId } = render(<DatePicker initialDate={new Date("02.02.2019")} />);
        render(<DatePicker initialDate={new Date("12.09.2019")} />, { container });

        const input = getByTestId("jkl-datepicker__input");
        expect(input).toHaveProperty("value", "12.09.2019");
    });

testing-library/react-testing-library#65 (comment)

@piofinn piofinn added the 🐝 Bug Noe er feil eller ikke som det skal label Mar 11, 2020
@SercanSercan
Copy link
Contributor

SercanSercan commented Apr 2, 2020

I noticed that Datepicker-react did not have useEffect() for initialDate and hence, it was not updated after re-initialisation of the value. So, this has been fixed. Plus, @piofinn noticed the unit test written above had a bug as well. See his fix below:

`
it("should change date on new props", () => {
// New date takes MM.DD.YYYY values
const { container, getByTestId } = render(<DatePicker initialDate={new Date("02.02.2019")} />);
render(<DatePicker initialDate={new Date("09.12.2019")} />, { container });

    const input = getByTestId("jkl-datepicker__input");

    // Check for date formatted as DD.MM.YYYY
    expect(input).toHaveProperty("value", "12.09.2019");
});

`

Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐝 Bug Noe er feil eller ikke som det skal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants