2013-08-28 66 views
1

我使用的灰燼,konacha-軌測試我ember.js應用,燼-konacha護欄的isValid Asse田

這裏是模型我測試:

//sales_rep.js 

App.SalesRep = DS.Model.extend({ 
firstName: DS.attr('string'), 
lastName: DS.attr('string'), 
}); 

這裏是測試:

#= require spec_helper 

describe "App.SalesRep", -> 
    beforeEach(-> 
    Test.store = TestUtil.lookupStore() 
) 

    it "is a DS.Model", -> 
    assert.ok App.SalesRep 
    assert.ok DS.Model.detect(App.SalesRep) 

    describe "attribute: firstName", -> 
    it "can be created with valid value", -> 
     Ember.run(-> 
     Test.contact = App.SalesRep.createRecord firstName: 'Joe' 
    ) 
     expect(Test.contact.get 'firstName').to.equal 'Joe' 




    describe "attribute: lastName", -> 
     it "can be created with valid value", -> 
      Ember.run(-> 
      Test.contact = App.SalesRep.createRecord lastName: 'swanson' 
     ) 
      expect(Test.contact.get 'lastName').to.equal 'swanson' 


     it "can NOT be created with invalid value", -> 
      Ember.run(-> 
      Test.contact = App.SalesRep.createRecord firstName: '123' 
     ) 
      expect(Test.contact.get 'firstName').to.not.equal 'Joe' 
      expect(Test.contact.isValid).to.be.equal false 

屬性測試都通過,但expect(Test.contact.isValid).to.be.equal false失敗 這裏是錯誤:

can NOT be created with invalid value ‣ 
AssertionError: expected undefined to equal false 
    at Assertion.assertEqual (http://localhost:3500/assets/chai.js:862:12) 
    at Assertion.ctx.(anonymous function) [as equal] (http://localhost:3500/assets/chai.js:3048:25) 
    at Context.<anonymous> (http://localhost:3500/assets/app/models/sales_rep_spec.js?body=1:36:51) 
    at Test.Runnable.run (http://localhost:3500/assets/mocha.js:4065:32) 
    at Runner.runTest (http://localhost:3500/assets/mocha.js:4430:10) 
    at http://localhost:3500/assets/mocha.js:4476:12 
    at next (http://localhost:3500/assets/mocha.js:4356:14) 
    at http://localhost:3500/assets/mocha.js:4365:7 
    at next (http://localhost:3500/assets/mocha.js:4313:23) 
    at http://localhost:3500/assets/mocha.js:4333:5 

因此我是新來的JS總的來說,我不知道如何解決這個問題? 它是一個測試語法錯誤嗎?

或者我應該添加驗證到Ember模型?

回答

1

嘗試:

expect(Test.contact.get('isValid')).to.be.equal false 

基本上添加獲得(「參考isValid」)

+0

謝謝你,它的工作!但我仍然得到真正的,而應該是假的,因爲我的服務器沒有按不接受沒有lastName的對象,可能會發生這種情況,因爲我沒有「提交」對象,它仍然是客戶端,並且客戶端沒有任何驗證,任何建議? – Mawaheb