How to test function component with a react-data-gridHow should I unit test threaded code?How do I test a private function or a class that has private methods, fields or inner classes?How do you test that a Python function throws an exception?Unit tests vs Functional testsCan you force a React component to rerender without calling setState?How to conditionally add attributes to React components?Invariant Violation error during testing react component which consumes prop from context apiTesting component function in React with Enzyme and JestInvariant Violation: Element type is invalid: error with Enzyme - help diagnosing?D3js in a React Component Unit Testing using Jest/Enzyme

How do amateur satellites stay consistently in the amateur-sat bands acoss the globe?

How to get the speed of my spaceship?

How do I explain how I handle unrealistic expectations from superiors in an interview?

Why is there paternal, for fatherly, fraternal, for brotherly, but no similar word for sons?

How to factor a fourth degree polynomial

How predictable is $RANDOM really?

Passwordless authentication - how invalidate login code

What is the fundamental difference between catching whales and hunting other animals?

Park the computer

Are "confidant" and "confident" homophones?

White's last move?

What is the highest level of accuracy in motion control a Victorian society could achieve?

Wearing special clothes in public while in niddah- isn't this a lack of tznius?

How do I talk to my wife about unrealistic expectations?

How do I check that users don't write down their passwords?

Gory anime with pink haired girl escaping an asylum

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Can I Ready an attack action to trigger when the target Blinks back to the Material plane?

Who goes first? Person disembarking bus or the bicycle?

How to say "just a precision" properly in English?

Do grungs have a written language?

What's the difference between a type and a kind?

Do Goblin tokens count as Goblins?

How can I use my cell phone's light as a reading light?



How to test function component with a react-data-grid


How should I unit test threaded code?How do I test a private function or a class that has private methods, fields or inner classes?How do you test that a Python function throws an exception?Unit tests vs Functional testsCan you force a React component to rerender without calling setState?How to conditionally add attributes to React components?Invariant Violation error during testing react component which consumes prop from context apiTesting component function in React with Enzyme and JestInvariant Violation: Element type is invalid: error with Enzyme - help diagnosing?D3js in a React Component Unit Testing using Jest/Enzyme






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have created a data grid with react using React-data-grid (link)



My code is as follows:



import React, useState from "react";
import ReactDataGrid from 'react-data-grid';

const ROW_COUNT = 20;
const MIN_WIDTH = 100;

const defaultColumnProperties =
resizable: true,
sortable: true
;

const columns = [

key: "eventTypeNameI18n",
name: "Type",
,

key: "nameI18n",
name: "Name",
width: 160
,

key: "dateCreated",
name: "Time",
width: 220
,

key: "locationNameI18n",
name: "Location",
width: 200

].map(col => (...col, ...defaultColumnProperties));

const sortRows = (initialRows, sortColumn, sortDirection) => rows =>
const comparer = (a, b) =>
if (sortDirection === "ASC")
return a[sortColumn] > b[sortColumn] ? 1 : -1;

else if (sortDirection === "DESC")
return a[sortColumn] < b[sortColumn] ? 1 : -1;

;
return sortDirection === "NONE" ? initialRows : [...rows].sort(comparer);
;

function DataGrid(initialRows)

const [rows, setRows] = useState(initialRows);

return (

<ReactDataGrid
id="EventDataGrid"
columns=columns
rowGetter=i => rows[i]
rowsCount=ROW_COUNT
minColumnWidth=MIN_WIDTH
onGridSort=(sortColumn, sortDirection) =>
setRows(sortRows(initialRows, sortColumn, sortDirection))

/>

);


export default DataGrid;



I am new to writing unit tests and have been writing very basic unit tests as of recent. I am wondering what is the best way to test the onGridSort method using Jest/Enzyme



In my tests I currently have the following:



import React from 'react';
import ReactDOM from 'react-dom';
import Enzyme, mount from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import EventsGrid from '../EventsGrid';
import sampleData from './sampleData/transformedEventSample';

Enzyme.configure(adapter: new Adapter());


describe('Tests for <EventDataGrid/>', () =>

it('sort data grid by ascending ', () =>

const wrapper = mount(<EventsGrid initialRows=sampleData/>);
const instance = wrapper.instance();
jest.spyOn(instance, 'sortRows');

const column = 'eventTypeNameI18n';
const sortDirection = 'ASC';

wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

expect(instance.sortRows).toHaveBeenCalled();

);

it('sort data grid by descending', () =>

const wrapper = mount(<EventsGrid initialRows=sampleData/>);
const instance = wrapper.instance();
jest.spyOn(instance, 'sortRows');

const column = 'eventTypeNameI18n';
const sortDirection = 'DESC';

wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

expect(instance.sortRows).toHaveBeenCalled();
);

);




I want to test to make sure that the grid is ordered correctly (ordered by ascending/descending)










share|improve this question






























    2















    I have created a data grid with react using React-data-grid (link)



    My code is as follows:



    import React, useState from "react";
    import ReactDataGrid from 'react-data-grid';

    const ROW_COUNT = 20;
    const MIN_WIDTH = 100;

    const defaultColumnProperties =
    resizable: true,
    sortable: true
    ;

    const columns = [

    key: "eventTypeNameI18n",
    name: "Type",
    ,

    key: "nameI18n",
    name: "Name",
    width: 160
    ,

    key: "dateCreated",
    name: "Time",
    width: 220
    ,

    key: "locationNameI18n",
    name: "Location",
    width: 200

    ].map(col => (...col, ...defaultColumnProperties));

    const sortRows = (initialRows, sortColumn, sortDirection) => rows =>
    const comparer = (a, b) =>
    if (sortDirection === "ASC")
    return a[sortColumn] > b[sortColumn] ? 1 : -1;

    else if (sortDirection === "DESC")
    return a[sortColumn] < b[sortColumn] ? 1 : -1;

    ;
    return sortDirection === "NONE" ? initialRows : [...rows].sort(comparer);
    ;

    function DataGrid(initialRows)

    const [rows, setRows] = useState(initialRows);

    return (

    <ReactDataGrid
    id="EventDataGrid"
    columns=columns
    rowGetter=i => rows[i]
    rowsCount=ROW_COUNT
    minColumnWidth=MIN_WIDTH
    onGridSort=(sortColumn, sortDirection) =>
    setRows(sortRows(initialRows, sortColumn, sortDirection))

    />

    );


    export default DataGrid;



    I am new to writing unit tests and have been writing very basic unit tests as of recent. I am wondering what is the best way to test the onGridSort method using Jest/Enzyme



    In my tests I currently have the following:



    import React from 'react';
    import ReactDOM from 'react-dom';
    import Enzyme, mount from 'enzyme';
    import Adapter from 'enzyme-adapter-react-16';
    import EventsGrid from '../EventsGrid';
    import sampleData from './sampleData/transformedEventSample';

    Enzyme.configure(adapter: new Adapter());


    describe('Tests for <EventDataGrid/>', () =>

    it('sort data grid by ascending ', () =>

    const wrapper = mount(<EventsGrid initialRows=sampleData/>);
    const instance = wrapper.instance();
    jest.spyOn(instance, 'sortRows');

    const column = 'eventTypeNameI18n';
    const sortDirection = 'ASC';

    wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

    expect(instance.sortRows).toHaveBeenCalled();

    );

    it('sort data grid by descending', () =>

    const wrapper = mount(<EventsGrid initialRows=sampleData/>);
    const instance = wrapper.instance();
    jest.spyOn(instance, 'sortRows');

    const column = 'eventTypeNameI18n';
    const sortDirection = 'DESC';

    wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

    expect(instance.sortRows).toHaveBeenCalled();
    );

    );




    I want to test to make sure that the grid is ordered correctly (ordered by ascending/descending)










    share|improve this question


























      2












      2








      2


      1






      I have created a data grid with react using React-data-grid (link)



      My code is as follows:



      import React, useState from "react";
      import ReactDataGrid from 'react-data-grid';

      const ROW_COUNT = 20;
      const MIN_WIDTH = 100;

      const defaultColumnProperties =
      resizable: true,
      sortable: true
      ;

      const columns = [

      key: "eventTypeNameI18n",
      name: "Type",
      ,

      key: "nameI18n",
      name: "Name",
      width: 160
      ,

      key: "dateCreated",
      name: "Time",
      width: 220
      ,

      key: "locationNameI18n",
      name: "Location",
      width: 200

      ].map(col => (...col, ...defaultColumnProperties));

      const sortRows = (initialRows, sortColumn, sortDirection) => rows =>
      const comparer = (a, b) =>
      if (sortDirection === "ASC")
      return a[sortColumn] > b[sortColumn] ? 1 : -1;

      else if (sortDirection === "DESC")
      return a[sortColumn] < b[sortColumn] ? 1 : -1;

      ;
      return sortDirection === "NONE" ? initialRows : [...rows].sort(comparer);
      ;

      function DataGrid(initialRows)

      const [rows, setRows] = useState(initialRows);

      return (

      <ReactDataGrid
      id="EventDataGrid"
      columns=columns
      rowGetter=i => rows[i]
      rowsCount=ROW_COUNT
      minColumnWidth=MIN_WIDTH
      onGridSort=(sortColumn, sortDirection) =>
      setRows(sortRows(initialRows, sortColumn, sortDirection))

      />

      );


      export default DataGrid;



      I am new to writing unit tests and have been writing very basic unit tests as of recent. I am wondering what is the best way to test the onGridSort method using Jest/Enzyme



      In my tests I currently have the following:



      import React from 'react';
      import ReactDOM from 'react-dom';
      import Enzyme, mount from 'enzyme';
      import Adapter from 'enzyme-adapter-react-16';
      import EventsGrid from '../EventsGrid';
      import sampleData from './sampleData/transformedEventSample';

      Enzyme.configure(adapter: new Adapter());


      describe('Tests for <EventDataGrid/>', () =>

      it('sort data grid by ascending ', () =>

      const wrapper = mount(<EventsGrid initialRows=sampleData/>);
      const instance = wrapper.instance();
      jest.spyOn(instance, 'sortRows');

      const column = 'eventTypeNameI18n';
      const sortDirection = 'ASC';

      wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

      expect(instance.sortRows).toHaveBeenCalled();

      );

      it('sort data grid by descending', () =>

      const wrapper = mount(<EventsGrid initialRows=sampleData/>);
      const instance = wrapper.instance();
      jest.spyOn(instance, 'sortRows');

      const column = 'eventTypeNameI18n';
      const sortDirection = 'DESC';

      wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

      expect(instance.sortRows).toHaveBeenCalled();
      );

      );




      I want to test to make sure that the grid is ordered correctly (ordered by ascending/descending)










      share|improve this question
















      I have created a data grid with react using React-data-grid (link)



      My code is as follows:



      import React, useState from "react";
      import ReactDataGrid from 'react-data-grid';

      const ROW_COUNT = 20;
      const MIN_WIDTH = 100;

      const defaultColumnProperties =
      resizable: true,
      sortable: true
      ;

      const columns = [

      key: "eventTypeNameI18n",
      name: "Type",
      ,

      key: "nameI18n",
      name: "Name",
      width: 160
      ,

      key: "dateCreated",
      name: "Time",
      width: 220
      ,

      key: "locationNameI18n",
      name: "Location",
      width: 200

      ].map(col => (...col, ...defaultColumnProperties));

      const sortRows = (initialRows, sortColumn, sortDirection) => rows =>
      const comparer = (a, b) =>
      if (sortDirection === "ASC")
      return a[sortColumn] > b[sortColumn] ? 1 : -1;

      else if (sortDirection === "DESC")
      return a[sortColumn] < b[sortColumn] ? 1 : -1;

      ;
      return sortDirection === "NONE" ? initialRows : [...rows].sort(comparer);
      ;

      function DataGrid(initialRows)

      const [rows, setRows] = useState(initialRows);

      return (

      <ReactDataGrid
      id="EventDataGrid"
      columns=columns
      rowGetter=i => rows[i]
      rowsCount=ROW_COUNT
      minColumnWidth=MIN_WIDTH
      onGridSort=(sortColumn, sortDirection) =>
      setRows(sortRows(initialRows, sortColumn, sortDirection))

      />

      );


      export default DataGrid;



      I am new to writing unit tests and have been writing very basic unit tests as of recent. I am wondering what is the best way to test the onGridSort method using Jest/Enzyme



      In my tests I currently have the following:



      import React from 'react';
      import ReactDOM from 'react-dom';
      import Enzyme, mount from 'enzyme';
      import Adapter from 'enzyme-adapter-react-16';
      import EventsGrid from '../EventsGrid';
      import sampleData from './sampleData/transformedEventSample';

      Enzyme.configure(adapter: new Adapter());


      describe('Tests for <EventDataGrid/>', () =>

      it('sort data grid by ascending ', () =>

      const wrapper = mount(<EventsGrid initialRows=sampleData/>);
      const instance = wrapper.instance();
      jest.spyOn(instance, 'sortRows');

      const column = 'eventTypeNameI18n';
      const sortDirection = 'ASC';

      wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

      expect(instance.sortRows).toHaveBeenCalled();

      );

      it('sort data grid by descending', () =>

      const wrapper = mount(<EventsGrid initialRows=sampleData/>);
      const instance = wrapper.instance();
      jest.spyOn(instance, 'sortRows');

      const column = 'eventTypeNameI18n';
      const sortDirection = 'DESC';

      wrapper.find('#EventDataGrid').at(1).prop('onGridSort')(column, sortDirection);

      expect(instance.sortRows).toHaveBeenCalled();
      );

      );




      I want to test to make sure that the grid is ordered correctly (ordered by ascending/descending)







      reactjs unit-testing jestjs enzyme react-data-grid






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 20:15









      Juan Rivas

      3871 gold badge2 silver badges11 bronze badges




      3871 gold badge2 silver badges11 bronze badges










      asked Mar 25 at 16:38









      KristianKristian

      7010 bronze badges




      7010 bronze badges






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342557%2fhow-to-test-function-component-with-a-react-data-grid%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342557%2fhow-to-test-function-component-with-a-react-data-grid%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현