【发布时间】:2019-01-08 10:15:03
【问题描述】:
我有一个 Unit 组件,它使用 moment.js 设置日期格式:
let bdate= moment(this.props.person.birthDate).format(
'hh:mm A, DD MMM YYYY'
);
稍后此 bdate 会在组件中呈现。
这个组件有一个单元测试:
describe('Unit', () => {
it('should render correctly', () => {
const person =
{
birthDate: '2018-06-14T00:00:00.000Z',
}
const wrapper = shallow(
<Unit
person={person}
/>
);
expect(wrapper).toMatchSnapshot();
});
});
问题是 Unit 的快照输出当前日期?为什么不是模拟日期?我该如何解决这个问题,以便快照保持不变?
【问题讨论】:
-
你能分享
Unit的代码吗?