Day 28: 初始化要测试的component

来,今天我们来聊一下怎麽帮redux在测试时添加初始化的状态资料,借用昨天的程序,并增加store的code.

// strore.js

import { createStore } from 'redux';
import reducer from './reducer';

const store = createStore(reducer);

export default store;

接下来借用一下昨天的部分.这部分我们就不要按照昨天的点选按钮,这下我们就可以取得,初始化状态下的元件

import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import store from './store';
import Avatar from '....';
import store from './store';
import reducer from './reducer';

test('should render initialState data in component', () => {
	const store = createStore(reducer, {name: 'example'});

  const { getByTestId, getByText } = render(
    <Provider store={store}>
      <Avatar />
    </Provider>
  );
  expect(getByTestId('name')).toHaveTextContent('example')
})

晚点想到再补一点东西


<<:  Countdown Clock

>>:  Day 28 Heroku Docker

IOS、Python自学心得30天 Day-27 IOS导入Firebase套件

https://github.com/firebase/firebase-ios-sdk 然後选择...

[Day 12] 开关 Switch

Day11 开关通常用於两个状态的切换 以笔者常用个功能 会在nav中加入切换语系的开关 首先先在u...

# Day5--Funny Function!一招函式打天下?

函式是每个程序语言都会有的一个语法,非常的实用,只要是编写功能,一定与函式脱离不了关系,而函式的内容...

EP25 - EKS 日志蒐集使用 Loki 和 Grafana(一)

前四天我们经历一番折腾, 终於把 Octopus Deploy 架起来, 从 Octopus Dep...

[Day30] 完赛心得

感谢订阅我文章的5位邦友,希望能对你们有一点点小帮助,忏悔一下後来 Vue 先前累积的文章写完之後,...