반응형
Vue Jest 테스트에서 navigato.geolocation.getCurrentposition을 "mock"하는 방법
vue에서 Google Maps 컴포넌트를 테스트하려고 하는데 navigator.geolocation.getCurrentPosition()이 메서드 내에 있습니다.
이 테스트는 실패하고 콘솔에 출력됩니다.
오류:TypeError: 정의되지 않은 속성 'getCurrentPosition'을 읽을 수 없습니다.
167 | },
168 | geolocate: function() {
> 169 | navigator.geolocation.getCurrentPosition(position => {
| ^
이건 내 코드야
export default {
name: "GoogleMap",
data() {
},
created() {
},
mounted() {
this.geolocate();
},
methods: {
..............
geolocate: function() {
navigator.geolocation.getCurrentPosition(position => {
this.center = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
});
...............
},
computed: {
}
};
</script>
나는 그것을 조롱하려 했지만 효과가 없다
describe("Maps.vue", () => {
it("renders ... Google maps ", () => {
const wrapper = shallowMount(Maps, {
mocks : {
getCurrentPosition:()=> jest.fn()
},
})
expect().....
})
})
어떻게 하면 이 네비게이터 방법을 '복제'하여 시험에 합격할 수 있을까요?
언급URL : https://stackoverflow.com/questions/54033294/how-to-mock-navigato-geolocation-getcurrentposition-in-a-vue-jest-test
반응형
'programing' 카테고리의 다른 글
Guice 바인딩 덮어쓰기 (0) | 2022.07.04 |
---|---|
Eslint 상태가 이미 선언된 [Vuex] (0) | 2022.07.04 |
유형 스크립트가 포함된 Vue 플러그인이 null의 속성 '_init'을 읽을 수 없습니다. (0) | 2022.07.04 |
C의 불투명 포인터는 무엇입니까? (0) | 2022.07.03 |
Vue JS의 계산된 필터에서 여러 값을 반환합니다. (0) | 2022.07.03 |