lightbeam-we icon indicating copy to clipboard operation
lightbeam-we copied to clipboard

Mock browser storage api in tests

Open princiya opened this issue 7 years ago • 2 comments

The current implementation of tests mocks the whole store object.

A proposed change is to have the tests use the actual store object and mock only the browser storage api calls.

princiya avatar Jun 20 '17 15:06 princiya

@jonathanKingston fil in the blanks:)

princiya avatar Jun 20 '17 15:06 princiya

Sorry missed this @princiya.

So my idea was that we could have:

const browser = {
  storage: {
    local: {
      storageFake: {},
      async get(key) {
        // return in memory JS
        return storageFake.key[key];
      }
      // more stuff here ...
    }
  }
};

We need to import this code somehow in here along with the store too into: https://github.com/electrolyfish/lightbeam-we/blob/master/karma.conf.js

Then the test (maybe we might need to use imports here perhaps?):

  describe('store set method', () => {
    it('should set firstParty c1.com', (done) => {
      store.setFirstParty("c1.com", {...})
      assert.deepEquals(store.get('c1.com'), expectedOutcome, "Should have stored stuff");
    });
  });
});

As this is test code and not part of the addon, I'm happy to have a karma import module installed which would allow for importing the js files.

jonathanKingston avatar Jun 21 '17 15:06 jonathanKingston