local-store-test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. var application, container, service;
  5. module('Acceptance: LocalStore', {
  6. beforeEach: function() {
  7. application = startApp();
  8. container = application.__container__;
  9. service = container.lookup('store:local');
  10. },
  11. afterEach: function() {
  12. Ember.run(application, 'destroy');
  13. }
  14. });
  15. test('getItem and setItem', function(assert) {
  16. assert.expect(2);
  17. assert.equal(service.getItem('undefinedKey'), null);
  18. var testKey = 'definedKey';
  19. var testValue = 'definedValue';
  20. service.setItem(testKey, testValue);
  21. assert.equal(service.getItem(testKey), testValue);
  22. });
  23. test('registered watcher is fired', function(assert) {
  24. var done = assert.async();
  25. assert.expect(1);
  26. var testKey = 'watchedKey';
  27. var testValue = 'watchedValue';
  28. service.watchItem(testKey, function(newValue) {
  29. assert.equal(testValue, newValue);
  30. done();
  31. });
  32. service._handleStorageEvent({key: 'unwatchedKey'});
  33. service._handleStorageEvent({
  34. key: service.prefixKey(testKey),
  35. newValue: testValue
  36. });
  37. });