跳过检查Jest快照中的特定属性

问题描述 投票:0回答:1

我需要测试一个快照,该快照也具有一个称为aria-labelledby的属性,并且由无法修改或模拟的某些函数创建。每次运行测试时,该属性都会获得一个新值,我也不在乎它是什么。

所以,有没有办法提及aria-labelledby不被检查?

Test

it('My Test', () => {
    let wrapper: ReactWrapper;
    wrapper = mount(<App />);
    expect(wrapper.find(App)).toMatchSnapshot();
});

快照

.....
    }
    unmountOnExit={false}
    >
    <div
-       aria-labelledby="pr_id_1_label"      <===== SNAPSHOT VALUE
+       aria-labelledby="pr_id_2_label"      <===== NEW VALUE WHICH CAUSES THE TEST FAIL!!!!
        className="p-dialog p-component"
.....
javascript reactjs jestjs enzyme snapshot
1个回答
0
投票

作为使用enzyme-to-json的一种解决方法,我们may specify .map() option能够过滤道具:

.map()
© www.soinside.com 2019 - 2024. All rights reserved.