Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 测试Ember Data beta的自定义适配器_Javascript_Ember.js_Ember Data - Fatal编程技术网

Javascript 测试Ember Data beta的自定义适配器

Javascript 测试Ember Data beta的自定义适配器,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我希望为我为Ember数据编写的自定义适配器编写一些单元测试,但我遇到了错误。以下是我如何设置存储和测试模型: window.App = Ember.Application.create(); App.Store = DS.Store.extend({ adapter: DS.WebSqlStorageAdapter.extend({ logQueries: true }) }); App.createTables = function() { var db = store.adapter.

我希望为我为Ember数据编写的自定义适配器编写一些单元测试,但我遇到了错误。以下是我如何设置存储和测试模型:

window.App = Ember.Application.create();
App.Store = DS.Store.extend({ adapter: DS.WebSqlStorageAdapter.extend({ logQueries: true }) });
App.createTables = function() {
  var db = store.adapter.create().db;

  db.transaction(
    function(tx) {
      tx.executeSql('DROP TABLE IF EXISTS test_models;');
      tx.executeSql('CREATE TABLE IF NOT EXISTS test_models (' +
        'id INTEGER PRIMARY KEY AUTOINCREMENT,' +
        '"string" TEXT,' +
        '"number" REAL,' +
        '"date" TEXT,' +
        '"boolean" INTEGER' +
        ');');
    },
    function(err) {
      console.error(err);
      throw new Exception('Database error!');
    },
    function() {
      App.dbCreated = true;
    }
  );

}

App.TestModel = DS.Model.extend({
  number:   DS.attr('number'),
  date:     DS.attr('date'),
  string:   DS.attr('string'),
  boolean:  DS.attr('boolean')
});

App.dbCreated = false;
window.store = App.Store.create();
setTimeout(App.createTables, 500);
以下是我的测试设置和第一次测试:

var m;

function waitForDbInit() {
  waitsFor(function() { return App.dbCreated; }, 'DB initialization', 4000);
}

function waitsFor(fn, label, time) {
  QUnit.stop();
  var int2 = setInterval(function() {
    throw new Error(label + 'was not completed after ' + time + ' ms.');
  }, time);
  var int =  setInterval(function() {
    if (fn()) {
      clearInterval(int);
      clearInterval(int2);
      QUnit.start();
    }
  }, 50);
}
var inc = 0;
module('CRUD', {
  setup: function() {
    waitForDbInit();
    m = store.createRecord('test_model', {
      id:  ++inc,
      string: 'String!',
      number: 1234,
      date: new Date(),
      boolean: true
    });
  }
});

asyncTest('creates a record', function() {
  m.save().then(function() {
    ok(m.get('number') === 12345);
    start();
  }, function(err) {
    console.error(err);
    ok(false);
    start();
  });
});
当我运行测试时,每个测试都会出现以下错误:

Setup failed on retrieves a record: Cannot call method 'lookupFactory' of undefined
Source:
at DS.Store.Ember.Object.extend.modelFor (http://localhost:4567/lib/ember-data.js:2179:34)
at DS.Store.Ember.Object.extend.createRecord (http://localhost:4567/lib/ember-data.js:1343:17)
at Object.module.setup (http://localhost:4567/tests.js:24:15)
at Object.Test.setup (http://localhost:4567/lib/qunit.js:176:31)
at http://localhost:4567/lib/qunit.js:358:10
at process (http://localhost:4567/lib/qunit.js:1453:24)
at http://localhost:4567/lib/qunit.js:479:5