Coder Social home page Coder Social logo

robofriends-testing's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

robofriends-testing's Issues

testing MainPage as Functional Component

I wonder if there is someone who was able to write any tests for MainPage as Functional Component
I did manage to maintain the project used functional components only. However testing seems to be the most bizarre topic to me.
Andrei uses wrapper.instance() to get to the filterRobots function. As it turns out it doesn't work with Functional components. It returns null.

import React, { useEffect } from 'react';
import CardList from '../components/cards/CardList';
import SearchBox from '../components/SearchBox';
import Spinner from '../components/Spinner';
import Header from '../components/Header'
import { Suspense } from 'react';
import './MainPage.css';

const MainPage = ({ robots, fetchRobotsList, isPending, search, onSearchChange }) => {
  
  useEffect(() => {
    fetchRobotsList()
  }, []);
  
  const filteredRobots = robots.filter(({ name }) =>
      name.toLowerCase().includes(search))
  
  return (
    <Suspense fallback={Spinner}>
      <div className="tc">
        <Header />
        <SearchBox search={onSearchChange} />
        { isPending ? <Spinner /> : <CardList robots={filteredRobots} /> }
      </div>
    </Suspense>
  );
};
export default MainPage;

Now, my intentions were to find an input of type search simulating an actual input and then comparing a result with props search. I cannot do this. Wrapper returns found 0 nodes. I feel like I'm thrown in at the deep end. What? How? Whyyyyyyyyyyyy?

import { shallow, mount } from 'enzyme';
import React from 'react';
import MainPage from './MainPage';

let wrapper;

it('filters robots correctly', () => {
   const mockedProps = {
    robots: [
      {
        id: 1,
        name: 'Leanne Graham',
        username: 'Bret',
        email: '[email protected]'
      },
    ], 
    fetchRobotsList: jest.fn(), 
    isPending: false, 
    search: '', 
    onSearchChange: jest.fn(),
  }
  
  wrapper = shallow(<MainPage { ...mockedProps } />);
  wrapper.find('input[type="search"]').simulate('input', {target: { value: 'Leanne'}})
  expect(wrapper.props().search).toEqual('Leanne')
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.