Domanda

I Am using Ember-konacha-rails to test my ember.js application,

Here is the model i am testing:

//sales_rep.js

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

here is the test :

 #= 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

The Attributes tests are passing, but the expect(Test.contact.isValid).to.be.equal false is failing and here is the error :

    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

Hence I am new to JS in General, i don't know how to solve this problem ? Is it a Test Syntax error ?

or should i add validation to the Ember model ?

È stato utile?

Soluzione

try with:

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

basically add .get('isValid')

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top