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

          Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

          밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

          1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴