0
votes

https://gist.github.com/js08/dfeab2df8b68240297eb

  • i am trying to write a test case for a jsx file
  • in this I am able to pass proptypes...
  • but not where I have passed proptypes propely...
  • i am getting an error when i run my test case..
  • providing my error, test case and code below...
  • Warning: Failed propType: Invalid prop rrrr supplied to sportsMockUpStandard.
  • not sure how to make it work ..
  • its happing at this function dispatch..
  • can you tell me how should i need to put it in my test case

    **error** 
    ---
     1) shallow renderer tests for sports-template-standard  should render correctly:
    

    Warning: Failed propType: Invalid prop rrrr supplied to sportsMockUpStandard.

    test cases
    ---
    
    
    describe('shallow renderer tests for sports-template-standard ', function() {
        let shallowRenderer = TestUtils.createRenderer();
        console.log("shallowRenderer" + JSON.stringify(shallowRenderer));
    
        it('should render correctly', () => {
    
           // var rightPanel ="some string";
            var layout ="some string";        
             var hasSidebar = function(){
                done();
        }
            console.log("here1");
          //  this.props.layout.rightPanel.exists = 'some value';
    
        shallowRenderer.render(<sportsMockUpStandard
    
            sidebar= {[{hasSidebar},{id: 100, text: 'hello world'}]} 
    

    />);

               // shallowRenderer.render(<sportsMockUpStandard
    
                //layout= {{id: 100, text: 'hello world'}}  />); 
    
             console.log("here2");
    
        });
    
    });
    

    ```

1
why did you change the error about 'sidebar' in your question to 'rrrr'? It makes the answer given before the change appear as if it's not about the question. - Simon Groenewolt

1 Answers

1
votes

Start off by looking at the warning you get:

Warning: Failed propType: Invalid prop rrrr supplied to sportsMockUpStandard.

This tells you that something is wrong with the rrrr property that you supply to sportsMockUpStandard. So let's take a look at that. In sportsMockUpStandard you have

rrrr: React.PropTypes.oneOfType([
    React.PropTypes.func,
    React.PropTypes.object
]),

so it is expecting either a function or an object. However, in the test case you create a sportsMockUpStandard element with rrrr being an array:

rrrr= {[{rrrr},{id: 100, text: 'hello world'}]}

Just add React.PropTypes.array, and you should be good.

Update: I really recommend starting by understanding how Mocha works. Your current test doesn't check anything, but just finishes when done() is executed. When you use chai the normal setup is something like this:

describe('the thing you want to test', () => {
  it('should do something', () => {
    /* Run some code */
    expect(/*something*/).to.equal(/*something*/);
  })
})

So let's say you have a function:

function addOne(number){
  return number + 1;
}

Then your test will look like this:

describe('addOne', () => {
  it('should take a number and increment it by one', () => {
    var number = 5;
    var newNumber = addOne(number);
    expect(newNumber).to.equal(6); // Success!!
  })
})

Once you have the basics down, testing React components should be a lot easier.