相关疑难解决方法(0)

React&Jest,如何测试更改状态和检查另一个组件

反应 - 测试实用程序文档

我有一个Login组件,如果为true ,将显示Notification组件this.state.error.

我现在正在写一个Jest测试来测试它.

import React from 'react'
import ReactTestUtils from 'react-dom/test-utils';
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
import Login from './Login'
import Notification from '../common/Notification'

describe('<Login /> component', () => {
    it('should render', () => {
        const loginComponent = shallow(<Login />);
        const tree = toJson(loginComponent);
        expect(tree).toMatchSnapshot();
    });

    it('should contains the words "Forgot Password"', () => {
        const loginComponent = shallow(<Login />);
        expect(loginComponent.contains('Forgot Password')).toBe(true);
    });

    // This test …
Run Code Online (Sandbox Code Playgroud)

javascript testing reactjs jestjs

22
推荐指数
1
解决办法
3万
查看次数

标签 统计

javascript ×1

jestjs ×1

reactjs ×1

testing ×1