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

Test issue #2

Open
coryhouse opened this issue May 28, 2020 · 7 comments
Open

Test issue #2

coryhouse opened this issue May 28, 2020 · 7 comments

Comments

@coryhouse
Copy link

Hi Arvind - Your tests run for me if I change line 4 in CourseFrom.Snapshot.test.js to this:

import { courses, authors } from "../../../tools/mockData";

If that doesn't fix it, please share this info:

Node version (run node -v to get this)
npm version (run npm -v to get this)
Terminal
Operating system

@coryhouse
Copy link
Author

Also, here's a thread with some ideas: jestjs/jest#9292

You could try moving the babel config out of package.json to a .babelrc file in your project root (same directory as package.json).

@arvndpal
Copy link
Owner

arvndpal commented May 29, 2020

import { courses, authors } from "../../../tools/mockData"; this does not fixed the issue

I tried with moving jest config and babel config out of package.json (same directory as package.json).
But that too, did not help me out.

Node: v12.13.1
npm: 3.10.7
OS: Windows 10 64-bit Operating System
Terminal: Winndows Powershell

@coryhouse
Copy link
Author

That's a very old version of npm. Can you update to the latest version?

@arvndpal
Copy link
Owner

arvndpal commented May 30, 2020

Thanks @coryhouse
Updating the npm version to 6.14.5 and moving the jest and babel config out of package.json
snapshot testing is working fine.
But with Enzyme test having the same issue in the src/components/courses/CourseForm.Enzyme.test.js commponent while the Enzyme Test is workiing fine for src/components/common/Header.test.js

I think the issue is due es6 destructuring syntax but I am not confirmed about it and event not able to resolve the issue.
Could you please provide help about it to resolve? (have updated code with latest commit)
image

@coryhouse
Copy link
Author

All tests pass for me now that I got your latest code. I suggest:

  1. Delete node_modules
  2. Run npm install
  3. try tests again

@coryhouse coryhouse reopened this May 30, 2020
@arvndpal
Copy link
Owner

No deleting node_modules and reinstalling did not fixed the issue,
Also tried the following config but that too did not help

  verbose: true,
  "setupFiles": [
    "./tools/testSetup.js"
  ],
  "moduleNameMapper": {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tools/fileMock.js",
    "\\.(css|less)$": "<rootDir>/tools/styleMock.js"
  },
  transform: {
    '^.+\\.(js|jsx)?$': 'babel-jest'
  },
  transformIgnorePatterns: ['<rootDir>/node_modules/']

}```

@arvndpal
Copy link
Owner

arvndpal commented May 30, 2020

Fixed the issue by destructuring saving value from args and put it in defaultArgs variable and used this as props
And comment out the code var props = { ...defaultProps, ...args }
File name: CourseForm.Enzyme.test.js
The running code: (Now my all test running accordingly)

function renderCourseForm(args) {
  const { saving } = args || false
  const defaultProps = {
    authors: [],
    course: {},
    saving,
    errors: {},
    onSave: jest.fn(),
    onChange: jest.fn()
  }

  return shallow(<CourseForm {...defaultProps} />)
}

The old code (that was failing)

function renderCourseForm(args) { 
  const defaultProps = {
    authors: [],
    course: {},
    saving,
    errors: {},
    onSave: jest.fn(),
    onChange: jest.fn()
  }

  const props = { ...defaultProps, ...args }
  return shallow(<CourseForm {...props } />)
}

I found the actual issue was in the const props = { ...defaultProps, ...args } line.
But i still not clear why is that? ( Have committed my latest code to matser branch)

Thanks once again @coryhouse for your great support and response.

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

No branches or pull requests

2 participants