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

Issue #733 dont use index for keys testcases #823

Draft
wants to merge 8 commits into
base: staging
Choose a base branch
from

Conversation

mumbler6
Copy link
Contributor

Attempted to write test cases that supplement issue #733, but have errors from importing and from redux while rendering components.

@mumbler6 mumbler6 requested a review from harsh183 June 11, 2024 03:08
@harsh183
Copy link
Member

harsh183 commented Jun 11, 2024

Great start! Leaving a few comments for changes

@@ -0,0 +1,2 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to add this to the .gitignore, that way git won't accidently pick up config files.

@@ -204,7 +204,7 @@
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$",
"^.+\\.module\\.(css|sass|scss)$",
"node_modules\/(?!axios)"
"node_modules/(?!axios)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!


const test_uuid = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d';

jest.mock('uuid', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really good use of mock for a randomized ID from an external library. Once you merge this PR, you should definitely add this as an example test file in the Testing wiki

// Invariant Violation: Could not find "store"
render(<ChapterInfo {...baseProps} />);

const contents = getAllByTestId('content');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like jest isn't able to work without a redux state, which is unfortunately wrapped by DvaJS. This might need some research on how to mock but we'll figure this out later.

// Invariant Violation: Could not find "store"
render(<SubChapterItem {...baseProps} />);

const contents = getAllByTestId('content');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to be screen.getAllByTestId to fix the error



describe('ChapterContent Component', () => {
const mockDispatch = jest.fn();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we aren't using these variables anywhere else, might be simpler to just have jest.fn() in props directly similar to your other test files, though this works fine too since the readability is quite clear in both cases.

@harsh183
Copy link
Member

@mumbler6 doing the test cases looks like it's getting quite complicated since it's dealing with redux. I think we can put these on the back burner for now to if you want spend more time focusing on something else. Feel free to fix anything from the comments and merge the other PR before wrapping up and starting on another issue.

I can try taking a crack at this in a bit too, I haven't mocked anything redux level yet, so it might take a while to do the initial setup and then future tests will probably go much smoother once we've figured it out.

Copy link
Collaborator

@angrave angrave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Note in INoteChapter.test.js (line 26)- there was a build failure-

'getAllByTestId' is not defined

    contents.forEach((content) => {
      expect(content).toHaveAttribute('key', `ch-content-chapter-id-1-${test_uuid}}`);
    });```

@angrave
Copy link
Collaborator

angrave commented Jun 12, 2024

You will also want to rebase or merge in latest from staging

@mumbler6
Copy link
Contributor Author

mumbler6 commented Jun 12, 2024

LGTM. Note in INoteChapter.test.js (line 26)- there was a build failure-

'getAllByTestId' is not defined

    contents.forEach((content) => {
      expect(content).toHaveAttribute('key', `ch-content-chapter-id-1-${test_uuid}}`);
    });```

My bad, Harsh left a comment about it before. Hopefully this'll fix it. Though it looks like the test case errors are also part of the build failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants