lundi 28 mars 2016

unit test cases when its mobile it should not rendering links

  • my gist entire code here http://ift.tt/1SgQVuF
  • I have an application where it shows different templates for desktop and mobile on basis of build environment.
  • I am successfully able to develop it where I need to hide the navigation menu for my mobile template.
  • right now I am able to write one test case where it fetches all the values through the proptypes and renders correctly
  • but not sure how to write the unit test cases when its mobile it should not render nav component.
  • provding code below.

    test case

    ```js import {expect} from 'chai'; import React from 'react'; import TestUtils from 'react-addons-test-utils'; import {SportsTopPortion} from '../../../src/components/sports-top-portion/sports-top-portion.jsx'; require('../../test-utils/dom');

    describe('"sports-top-portion" Unit Tests', function() { let shallowRenderer = TestUtils.createRenderer();

    let sportsContentContainerLayout ='mobile';
    let sportsContentContainerProfile = {'exists': 'hasSidebar'};
    let sportsContentContainerAuthExchange = {hasValidAccessToken: true};
    let sportsContentContainerHasValidAccessToken ='test'; 
    
    it('should render correctly', () => {
        shallowRenderer.render(<SportsTopPortion sportsWholeFramework={sportsContentContainerLayout} sportsPlayers={sportsContentContainerProfile} sportsAuthentication={sportsContentContainerAuthExchange} sportsUpperBar={{activeSportsLink:'test'}} />);
        //shallowRenderer.render(<SportsTopPortion sportsWholeFramework={sportsContentContainerLayout} sportsPlayers={sportsContentContainerProfile} hasValidAccessToken={sportsContentContainerHasValidAccessToken}  />);
    
        let renderedElement = shallowRenderer.getRenderOutput();
        console.log("renderedElement------->" + JSON.stringify(renderedElement));
    
        expect(renderedElement).to.exist;
    });
    
    

    }); ```

    • code snippet where test case need to be written

    js if (sports.build === 'mobile') { sportsNavigationComponent = <div />; sportsSideMEnu = <div />; searchComponent = <div />; sportsPlayersWidget = <div />; }

Aucun commentaire:

Enregistrer un commentaire