Skip to content

Commit

Permalink
#6701 js-storage teardown
Browse files Browse the repository at this point in the history
The first time js-storage is required it evaluates if it's running in the browser or not: https://github.com/julien-maurel/js-storage/blob/master/js.storage.js#L423 and will define the localstorage getters and setters accordingly. This becomes an issue if testing localstorage between UI and non-UI tests. reportstorage.test.js was requiring it before hashauth.test.js causing a conflict.
  • Loading branch information
mg80 committed Jan 30, 2021
1 parent 480ae33 commit 43534c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions tests/hashauth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('hashauth', function ( ) {
});

after(function (done) {
// cleanup js-storage as it evaluates if the test is running in the window or not when first required
delete require.cache[require.resolve('js-storage')];
done( );
});

Expand Down
18 changes: 9 additions & 9 deletions tests/reportstorage.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const should = require('should');
const reportstorage = require('../lib/report/reportstorage');
let storage = require('js-storage').localStorage;
let mockStorage = require('./fixtures/localstorage');
const defaultValues = {
insulin: true,
carbs: true,
Expand All @@ -18,17 +15,20 @@ const defaultValues = {
};

describe('reportstorage unit tests', () => {
let reportstorage, storage, mockStorage;

beforeEach(() => {
storage._get = storage.get;
storage._set = storage.set;
before(() => {
reportstorage = require('../lib/report/reportstorage');
storage = require('js-storage').localStorage;
mockStorage = require('./fixtures/localstorage');
storage.get = mockStorage.get;
storage.set = mockStorage.set;
});

afterEach(() => {
storage.get = storage._get;
storage.set = storage._set;
after(() => {
// cleanup js-storage as it evaluates if the test is running in the window or not when first required
delete require.cache[require.resolve('js-storage')];
delete require.cache[require.resolve('./fixtures/localstorage')];
});

it('reportstorage definition - returns saveProps and getValue function', () => {
Expand Down

0 comments on commit 43534c0

Please sign in to comment.