2017-11-20 14 views
0

なぜ.findは以下のコードコンテキストの関数ではありませんか?酵素試験:TypeError:expect(...)。findは関数ではありません

import React from 'react'; 
import { shallow } from 'enzyme'; 
import toJson from 'enzyme-to-json'; 
import { AuthorizedRoutesJest } from './AuthorizedRoutes'; 

// Components 
import { 
    Main 
} from '../../components'; 

const wrapper = shallow(<AuthorizedRoutesJest />); 

describe('<AuthorizedRoutes /> component',() => { 
    it('should render',() => { 
    const tree = toJson(wrapper); 
    expect(tree).toMatchSnapshot(); 
    expect(wrapper).toHaveLength(1); 
    }); 

    it('should contain a Main component',() => { 
    expect(wrapper).find(Main).toHaveLength(1); 
    }); 
}); 

Summary of all failing tests FAIL client/containers/Routes/AuthorizedRoutes.test.js

AuthorizedRoutes component › should contain a Main component

TypeError: expect(...).find is not a function

答えて

0

私はここで間違って

.findを使用した検索を使用する方法の例です:

it('should contain a ConnectedRouter component',() => { 
    expect(wrapper.find(ConnectedRouter)).toHaveLength(1); 
}); 

it('should contain a Switch component',() => { 
    expect(wrapper.find(Switch)).toHaveLength(1); 
}); 

it('should contain 7 Route components',() => { 
    expect(wrapper.find(Route)).toHaveLength(7); 
}); 
関連する問題