私はjestスナップショットテストを実装しました。私が解決できないのは、私のコンポーネントが自分のCI上で別のスナップショットをレンダリングしているということだけです。CIとローカルでテストするときにJestスナップショットが異なる
/* eslint-env jest */
/* eslint import/no-extraneous-dependencies: "off" */
import React from 'react';
import { shallow } from 'enzyme';
import { shallowToJson } from 'enzyme-to-json';
import Combobox from '../Combobox';
describe('<Combobox />',() => {
it('renders correctly',() => {
const wrapper = shallow(
<Combobox
items={[]}
placeholder=""
valueKey=""
labelKey=""
/>
);
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
});
とコンポーネントは次のとおりです:私のテストがある
import React, { PropTypes } from 'react';
import Select from 'react-select';
export default class Combobox extends React.Component {
constructor(props) {
super(props);
this.state = {
currentValue: null,
};
this.updateValue = this.updateValue.bind(this);
}
updateValue(newValue) {
this.setState({
currentValue: newValue,
});
}
render() {
return (
<Select
placeholder={this.props.placeholder}
valueKey={this.props.valueKey}
labelKey={this.props.labelKey}
options={this.props.items}
value={this.state.currentValue}
onChange={this.updateValue}
/>
);
}
}
Combobox.propTypes = {
items: PropTypes.array.isRequired,
placeholder: React.PropTypes.string.isRequired,
valueKey: React.PropTypes.string.isRequired,
labelKey: React.PropTypes.string.isRequired,
};
私はスナップショットを生成するためにenzyme
とenzyme-to-json
を使用しています。コンポーネント自体はreact-select
のラッパーです。ローカルでテストするとすべてが正常であるが、と私のCIのそれのエラーに関する:
FAIL src/components/__tests__/Combobox.test.jsx
● <Combobox /> › renders correctly
Received value does not match the stored snapshot 1.
- Snapshot
+ Received
<Select
// ...
- optionComponent={[Function anonymous]}
+ optionComponent={[Function Constructor]}
// ...
- valueComponent={[Function anonymous]}
+ valueComponent={[Function Constructor]}
valueKey="" />
at Object.<anonymous> (src/components/__tests__/Combobox.test.jsx:20:82)
at process._tickCallback (internal/process/next_tick.js:103:7)
のでoptionComponent
とvalueComponent
は私のローカルスナップショットと比較して、異なる値を持っています。ローカルテストとリモートテストの間にこの不一致が生じる原因は何ですか?
最初はモジュールの違いがありましたが、リモートは新しいモジュールをインストールしていましたが、 'rm -rf node_modules && npm i'はローカルスナップショットを変更しませんでした。 – vkjb38sjhbv98h4jgvx98hah3fef