के साथ डिबॉन्स फ़ंक्शन का उपयोग करके एंगुलरजेएस घड़ी का परीक्षण कैसे करें मेरे पास एक घड़ी वाला नियंत्रक है जो 500ms तक सूची फ़िल्टर करने में देरी से लॉसैश से बहस का उपयोग करता है।जैस्मीन
$scope.$watch('filter.keywords', _.debounce(function() {
$scope.$apply(function() {
$scope.filtered = _.where(list, filter);
});
}, 500));
मैं एक जैस्मीन परीक्षण simulates कि फ़िल्टर कीवर्ड कि जो कीवर्ड पाए जाते हैं, जिसके बाद पाया नहीं कर रहे हैं में प्रवेश लिखने की कोशिश कर रहा हूँ।
मेरा प्रारंभिक प्रयास कीवर्ड के लिए एक नया मूल्य निर्दिष्ट करने के बाद $ पाचन का उपयोग करना था, जो मुझे लगता है कि बहस के कारण काम नहीं किया गया था।
it('should filter list by reference', function() {
expect(scope.filtered).toContain(item);
scope.filter.keywords = 'rubbish';
scope.$digest();
expect(scope.filtered).not.toContain(item);
scope.filter.keywords = 'test';
scope.$digest();
expect(scope.filtered).toContain(item);
});
तो मैंने $ टाइमआउट का उपयोग करने का प्रयास किया, लेकिन यह या तो काम नहीं करता है।
it('should filter list by reference', function() {
expect(scope.filtered).toContain(item);
$timeout(function() {
scope.filter.keywords = 'rubbish';
});
$timeout.flush();
expect(scope.filtered).not.toContain(item);
$timeout(function() {
scope.filter.keywords = 'test';
});
$timeout.flush();
expect(scope.filtered).toContain(item);
});
मैं भी $ टाइमआउट 500ms debounce पर सेट से अधिक मूल्य देने की कोशिश की है।
दूसरों ने इस समस्या को हल कैसे किया है?
संपादित करें: मुझे एक समाधान मिला है जो $ टाइमआउट फ़ंक्शन में अपेक्षा को लपेटना था और फिर दायरे पर $ $ पर कॉल करना था।
it('should filter list by reference', function() {
expect(scope.filtered).toContain(item);
scope.filter.keywords = 'rubbish';
$timeout(function() {
expect(scope.filtered).not.toContain(item);
});
scope.$apply();
scope.filter.keywords = 'test';
$timeout(function() {
expect(scope.filtered).toContain(item);
});
scope.$apply();
});
मैं अब भी जानना आवश्यक है कि इस दृष्टिकोण हालांकि सबसे अच्छा है इच्छुक हूँ।