我使用Ember-konacha-rails来测试我的ember.js应用程序,
以下是我正在测试的模型:
//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模型中添加验证吗?
答案 0 :(得分:1)
尝试:
expect(Test.contact.get('isValid')).to.be.equal false
基本上添加.get('isValid')