मैं कर्म/चमेली के साथ एक Vue 3 घटक के लिए एक परिकलित संपत्ति के लिए एक परीक्षण मुखर मूल्य लिखने की कोशिश कर रहा हूँ। परिकलित गुण करता है ऐप के चलने पर उसका पुनर्मूल्यांकन होता रहता है, लेकिन ऐसा लगता है कि परीक्षण में उसका पुनर्मूल्यांकन नहीं किया गया है। नीचे परीक्षण और परीक्षण दोनों घटकों के लिए एक बहुत ही सरल कोड है:
// Component to test
const Component1 = defineComponent({
setup() {
const someString = inject("someString");
return { someString };
},
computed: {
isSuccess(): boolean {
return this.someString == "success";
}
}
});
export default Component1;
// Test
import "Component1" from "/path/to/component";
describe("Component1 tests", function() {
let wrapper: VueWrapper<any>;
let inTest: any;
beforeEach(function(){
wrapper = mount(Component1, {
global: {
provide: {
someString: 'failure'
}
}
});
inTest = wrapper.vm;
});
describe("isSuccess should return true if someString is 'success'", function(){
expect(inTest.isSuccess).toBeFalse(); // this passes
inTest.someString = 'success';
expect(inTest.isSuccess).toBeTrue(); // but this fails
});
});
क्या मुझसे कोई चूक हो रही है?
1
natasha
9 अक्टूबर 2021, 00:59
1 उत्तर
सबसे बढ़िया उत्तर
बशर्ते मान तब तक प्रतिक्रियाशील नहीं होते जब तक आप एक ref
प्रॉपर्टी या reactive
ऑब्जेक्ट पास नहीं करते। यहां देखें।
तो मेरा मानना है कि आप इसे केवल कुछ मामूली बदलावों के साथ काम करने के लिए प्राप्त कर सकते हैं।
// Test
import { ref } from 'vue'
import "Component1" from "/path/to/component";
describe("Component1 tests", function() {
let wrapper: VueWrapper<any>;
let providedValue = ref('failure')
let inTest: any;
beforeEach(function(){
wrapper = mount(Component1, {
global: {
provide: {
someString: providedValue
}
}
});
inTest = wrapper.vm;
});
describe("isSuccess should return true if someString is 'success'", function(){
expect(inTest.isSuccess).toBeFalse(); // this passes
providedValue.value = 'success';
expect(inTest.isSuccess).toBeTrue(); // but this fails
});
});
1
Steven B.
9 अक्टूबर 2021, 02:03