2015-09-15 2 views
5

मैं निर्धारित करने के लिए क्यों एक sails.js अनुप्रयोग में मेरी इकाई परीक्षण अपेक्षित ढंग से काम नहीं कर रहा है कुछ मदद करना चाहते हैं।Bluebird वादा मोचा में प्रत्येक/चाय परीक्षण काम नहीं कर रहा

मैं mails, chai और bluebird वादा लाइब्रेरी का उपयोग sails.js ऐप पर कर रहा हूं।

  • TagsService.create (नाम) विधि है, जो एक नाम पैरामीटर स्वीकार करता है के लिए एक परीक्षण बनाएँ:

    क्या मैं हासिल करना चाहते हैं।

  • टेस्ट है कि इस विधि अमान्य नाम मैं
  • पारित नाम पैरामीटर की आवश्यकता है और कम से कम 121 वर्ण लंबा

मैं वर्तमान में क्या है होना चाहिए के आधार पर एक नया टैग रिकॉर्ड बनाने नहीं होगा:

// Test the 'create' method 
 
describe('Method \'create\' test result: \n', function() { 
 
    
 
    // Test that name is required and less than 121 chars long 
 
    it('Must receive the name parameter and be less than 121 chars long', function(done) { 
 
\t \t 
 
    // It should not accept any of the following names 
 
    var names = ['',' ','thisstringislongerthanthemaxof121characterslongthisstringislongerthanthemaxof121characterslongthisstringislongerthanthema',[],[{}],[{test: 'test'}],'wrongchars*[]$£%fsf','$%@~}[','£$%jkdfi',' $%"£asdwdFDE','hD8U £$&{DS ds']; 
 
    
 
    
 
     sails.bluebird.each(names,function(name){ 
 
     TagsService.create(name).then(function(data){ 
 
      assert.propertyVal(data,'status','err','An error was NOT returned - even though names provided should be invalid'); 
 
     }); 
 
     }).then(function(){ 
 
     done(); 
 
     }); 
 
    
 
\t \t 
 
    }); 
 
    
 
});

क्या होता है इसे पारित करने के लिए, भले ही मैं कोई मान्य नाम में पास या विधि से अशक्त लौटने लगता है।

उत्तर

5

ठीक है, लगता है जैसे मैं, इसे हल करने में कामयाब ज्यादा परीक्षण और त्रुटि के बाद।

बाहर निकलता है मुझे प्रत्येक विधि को निष्पादित करने के बाद वादे से() कॉलबैक को पकड़ने की आवश्यकता होती है। इसके अलावा परीक्षण TagsService वादा वस्तु से किए गए कार्य का परिणाम वापस जाने के लिए की जरूरत है। (फिर भी नहीं 100% यकीन है कि यह इसके बारे में सोचने के लिए सही तरीका क्या है ..)। वैसे भी परीक्षण अब ठीक ढंग से काम करने लगता है।

var names = ['',' ','thisstringislongerthanthemaxof121characterslongthisstringislongerthanthemaxof121characterslongthisstringislongerthanthema',[],[{}],[{test: 'test'}],'wrongchars*[]$%fsf','$%@~}[','�$%jkdfi',' $%"�asdwdFDE','hD8U �$&{DS ds']; 
 
\t \t \t 
 
sails.bluebird.each(names, function(name){ 
 
    return TagsService.create(name).then(function(data) { 
 
\t assert.property(data, 'status', 'create method did not return a status property'); 
 
\t assert(data.status === 'err', 'even with an invalid name parameter passed - it did not return an err status, which it must do with an invalid name.'); 
 
    }); 
 
}).then(function(){ 
 
\t done(); 
 
}).catch(done);

+0

भी देखें https://github.com/domenic/chai-as-promised:

यहाँ मेरी परिणाम है –

संबंधित मुद्दे