Rewrite tests with async/await

jh-changes
Shin'ya Ueoka 7 years ago
parent 70ed31f35e
commit 88238005ab
  1. 37
      test/shared/versions/index.test.js
  2. 27
      test/shared/versions/storage.test.js

@ -7,49 +7,34 @@ describe("shared/versions/storage", () => {
return browser.storage.local.remove('version'); return browser.storage.local.remove('version');
}); });
it('return true if no previous versions', () => { it('return true if no previous versions', async() => {
return Promise.resolve().then(() => { let updated = await versions.checkUpdated();
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.true; expect(updated).to.be.true;
}); });
});
it('return true if updated', () => { it('return true if updated', async() => {
return Promise.resolve().then(() => { await browser.storage.local.set({ version: '0.001' });
return browser.storage.local.set({ version: '0.001' }); let updated = await versions.checkUpdated();
}).then(() => {
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.true; expect(updated).to.be.true;
}); });
});
it('return false if not updated', () => { it('return false if not updated', async() => {
return Promise.resolve().then(() => { await browser.storage.local.set({ version: manifest.version });
return browser.storage.local.set({ version: manifest.version }); let updated = await versions.checkUpdated();
}).then(() => {
return versions.checkUpdated();
}).then((updated) => {
expect(updated).to.be.false; expect(updated).to.be.false;
}); });
}); });
});
describe('#commit', () => { describe('#commit', () => {
beforeEach(() => { beforeEach(() => {
return browser.storage.local.remove('version'); return browser.storage.local.remove('version');
}); });
it('saves current version from manifest.json', () => { it('saves current version from manifest.json', async() => {
return Promise.resolve().then(() => { await versions.commit();
return versions.commit(); let { version } = await browser.storage.local.get('version');
}).then(() => {
return browser.storage.local.get('version');
}).then(({version}) => {
expect(version).to.be.a('string'); expect(version).to.be.a('string');
expect(version).to.equal(manifest.version); expect(version).to.equal(manifest.version);
}); });
}); });
});
}); });

@ -6,34 +6,23 @@ describe("shared/versions/storage", () => {
return browser.storage.local.remove('version'); return browser.storage.local.remove('version');
}); });
it('loads saved version', () => { it('loads saved version', async() => {
return Promise.resolve().then(() => { await browser.storage.local.set({ version: '1.2.3' });
return browser.storage.local.set({ version: '1.2.3' }); let version = await storage.load();
}).then(() => {
return storage.load();
}).then((version) => {
expect(version).to.equal('1.2.3'); expect(version).to.equal('1.2.3');
}); });
});
it('returns undefined if no versions in storage', () => { it('returns undefined if no versions in storage', async() => {
return Promise.resolve().then(() => { let version = await storage.load();
return storage.load();
}).then((version) => {
expect(version).to.be.a('undefined'); expect(version).to.be.a('undefined');
}); });
}); });
});
describe('#save', () => { describe('#save', () => {
it('saves version string', () => { it('saves version string', async() => {
return Promise.resolve().then(() => { await storage.save('2.3.4');
return storage.save('2.3.4'); let { version } = await browser.storage.local.get('version');
}).then(() => {
return browser.storage.local.get('version');
}).then(({version}) => {
expect(version).to.equal('2.3.4'); expect(version).to.equal('2.3.4');
}); });
}); });
});
}); });