Re: Running React Locally And Setting Up Test

Hello,

I am trying to setup react locally and complete test while I am doing the exercises for FCC.

I’ve been able to setup everything except react test.

My repository:

These are the test I am trying to setup:

The constant JSX should return an h1 element.
assert(JSX.type === ‘h1’);
The h1 tag should include the text Hello JSX!
assert(Enzyme.shallow(JSX).contains(‘Hello JSX!’));

[freeCodeCamp/create-a-simple-jsx-element.md at main · freeCodeCamp/freeCodeCamp · GitHub]

This link provided some hints as how I could perform the test.
Where can I find the actual code source for the test?(having no luck setting it up)?

Code of interest in my repository:


// The constant JSX should return an h1 element.

// assert(JSX.type === 'h1');
// The h1 tag should include the text Hello JSX!

// assert(Enzyme.shallow(JSX).contains('Hello JSX!'));


// MyComponent.test.js
import React from 'react';
import Enzyme, {shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'
import JSX from './fccexercises/react01';

Enzyme.configure({adapter: new Adapter()})


describe("H1 tag should include the text: Hello JSX!", () => {
  it("should render my component", () => {
    const wrapper = shallow(<JSX />);

    assert(wrapper.type === 'h1');
    // assert(Enzyme.shallow(JSX).contains('Hello JSX!'));
  
  });
});

I’ve modified the code.

The boolean result is correct the test is still passing. I don’t know why.

import React from 'react';
import Enzyme, {shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'
import JSX from './fccexercises/react01';

Enzyme.configure({adapter: new Adapter()})


describe("H1 tag should include the text: Hello JSX!", () => {
  it("should render my component", () => {
    const wrapper = shallow(<JSX />);


    expect(Enzyme.shallow(<JSX />).contains('Hello JSX'));
    console.log(Enzyme.shallow(<JSX />).contains('Hello JSX'));
    console.log(Enzyme.shallow(<JSX />).contains('Hello JSX!'));

 
  });
});
> jest

 PASS  src/App.test.js
 PASS  src/sample.test.js
 PASS  src/react01.test.js
  ● Console

    console.log
      false

      at Object.<anonymous> (src/react01.test.js:24:13)

    console.log
      true

      at Object.<anonymous> (src/react01.test.js:25:13)


Test Suites: 3 passed, 3 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        1.71 s, estimated 2 s
Ran all test suites.