반응형
Vuex에서 AssertionError를 {개체(유형, 텍스트)}과(와) 동일하게 던지는 단위 테스트
지금까지 유닛의 Vuex 동작 테스트는 악몽이었습니다.실제로 무엇을 찾고 있는지 이해할 수 없습니다.저는 https://vuex.vuejs.org/en/testing.html를 팔로우하여 액션 도우미 기능을 사용하고 있습니다.
버튼에 텍스트를 추가하는 간단한 작업이 있습니다.
createButton({ commit, state }, payload) {
let btnString = '';
if (payload.hasCookie) {
btnString = 'Welcome back';
} else if (payload.isLoggedIn) {
btnString = 'Sign out';
} else {
btnString = 'Sign up';
}
commit({ type: 'CREATE_BUTTON_TEXT', text: btnText });
},
제 시험에서는...
describe('Create Button Text', () => {
it('should render the buttons string ', (done) => {
const expectedString = 'Welcome back';
const mock = {
hasCookie: true,
isLoggedIn: false,
};
testAction(actions.createButton, mock, state, [
{ type: 'CREATE_BUTTON_TEXT', text: expectedString },
], done);
});
});
돌아오고 있다AssertionError: expected 'CREATE_BUTTON_TEXT' to equal { Object (type, text) }
...내가 기대했던 것을 제공하지 않는가?text
와 함께expectedString
맞습니까?이 문제에 대한 어떤 지침이라도 주시면 대단히 감사하겠습니다.
(문서 권장사항에 따라 Mocha + Chai 사용).
커밋 구문이 잘못된 것 같습니다.를 사용했을 경우testAction
도우미, 인수expectedMutations
는 유형 및 페이로드가 있는 오브젝트 목록을 요구합니다.다음 코드를 사용할 수 있습니다.
createButton({ commit, state }, payload) {
let btnString = ''
if (payload.hasCookie) {
btnString = 'Welcome back'
} else if (payload.isLoggedIn) {
btnString = 'Sign out'
} else {
btnString = 'Sign up'
}
commit('CREATE_BUTTON_TEXT', btnString)
}
그리고 테스트 방법:
describe('Create Button Text', () => {
it('should render the buttons string ', (done) => {
const expectedString = 'Welcome back'
const mock = {
hasCookie: true,
isLoggedIn: false
}
testAction(actions.createButton, mock, {}, [
{ type: 'CREATE_BUTTON_TEXT', payload: expectedString }
], done)
})
})
언급URL : https://stackoverflow.com/questions/42863283/unit-testing-in-vuex-throwing-assertionerror-to-equal-object-type-text
반응형
'programing' 카테고리의 다른 글
자바를 사용하여 문자열의 첫 글자를 대문자화하려면 어떻게 해야 합니까? (0) | 2022.07.21 |
---|---|
Vue 2에서 비반응 구성 요소 데이터를 설정하는 방법 (0) | 2022.07.21 |
C의 거듭제곱으로? (0) | 2022.07.21 |
동적으로 등록된 모듈의 순서 설정 (0) | 2022.07.21 |
Nuxt를 사용하는 구성 요소에서 Vuex 저장소 상태에 액세스 (0) | 2022.07.21 |