lightbeam-we
lightbeam-we copied to clipboard
Mock browser storage api in tests
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.
@jonathanKingston fil in the blanks:)
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.