React Native 프로젝트의 단위 테스트를 작성할 때 다른 플랫폼을 기반으로 다른 스냅 샷을 테스트 할 수 있기를 원합니다.React Native : Jest Mocking Platform
먼저 jest.mock
을 모의 Platform
으로 시도했지만 비동기로 보입니다. 이 방법은 두 개의 개별 파일이있을 때 작동하지만 가능하면 모든 파일을 한 파일에 보관하는 것을 선호합니다.
jest.doMock
을 시도 : 바벨-농담을 사용하는 경우
, 자동으로 코드 블록의 상단에 게양된다 조롱 호출합니다. 이 동작을 명시 적으로 피하려면이 방법을 사용하십시오. https://facebook.github.io/jest/docs/en/jest-object.html#jestdomockmodulename-factory-options
그러나 여전히 바람직하지 않은 결과가 표시됩니다. 내가 console.log
에서 안드로이드 테스트를 볼 때 Platform.OS
은 무엇이든간에 처음으로 doMock
으로 설정되었습니다. 나는 그 http://facebook.github.io/jest/docs/en/setup-teardown.html#scoping
describe('ios test',() => {
it('renders ui correctly',() => {
jest.doMock('Platform',() => {
const Platform = require.requireActual('Platform');
Platform.OS = 'ios';
return Platform;
});
const wrapper = shallow(<SomeComponent />);
const tree = renderer.create(wrapper).toJSON();
expect(tree).toMatchSnapshot();
});
});
describe('android test',() => {
it('renders ui correctly',() => {
jest.doMock('Platform',() => {
const Platform = require.requireActual('Platform');
Platform.OS = 'android';
return Platform;
});
const wrapper = shallow(<SomeComponent />);
const tree = renderer.create(wrapper).toJSON();
expect(tree).toMatchSnapshot();
});
});
나는 동일한 파일에 시험을위한 모의 플랫폼을 변경하는 방법에 어떤 아이디어를 범위 지정에 도움이 될 생각 변경할 수 없기
나는 또한describe
에
beforeEach
에서 모의을 포장하려고?