diff --git a/tests/unit/fileUtils.spec.js b/tests/unit/fileUtils.spec.js index dd51ab8..030c072 100644 --- a/tests/unit/fileUtils.spec.js +++ b/tests/unit/fileUtils.spec.js @@ -3,7 +3,7 @@ import fu from '@/fileUtils.js' import sinon from 'sinon' describe('fileUtils.js', () => { - afterEach(()=> { + afterEach(() => { document.createElement.restore() URL.revokeObjectURL.restore() URL.createObjectURL.restore() @@ -18,16 +18,15 @@ describe('fileUtils.js', () => { sinon.spy(URL, 'createObjectURL') sinon.spy(URL, 'revokeObjectURL') sinon.spy(window, 'Blob') - - const str = 'foo' - fu.exportToFile('foo','foo.txt') - + + fu.exportToFile('foo', 'foo.txt') + expect(document.createElement.calledOnceWith('a')).to.equal(true) - + expect(window.Blob.calledOnceWith(['foo'], { type: 'octet/stream' })).to.equal(true) const blob = window.Blob.returnValues[0] - expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true) - + expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true) + const url = URL.createObjectURL.returnValues[0] expect(spyAnchor.href).to.equal(url) @@ -37,7 +36,7 @@ describe('fileUtils.js', () => { expect(spyAnchor.remove.calledOnce).to.equal(true) expect(URL.revokeObjectURL.calledOnceWith(url)).to.equal(true) - }), + }) it('exportToFile', () => { const spyAnchor = document.createElement('a') @@ -47,16 +46,15 @@ describe('fileUtils.js', () => { sinon.spy(URL, 'createObjectURL') sinon.spy(URL, 'revokeObjectURL') sinon.spy(window, 'Blob') - - const str = 'foo' - fu.exportToFile('foo','foo.html', 'text/html') - + + fu.exportToFile('foo', 'foo.html', 'text/html') + expect(document.createElement.calledOnceWith('a')).to.equal(true) - + expect(window.Blob.calledOnceWith(['foo'], { type: 'text/html' })).to.equal(true) const blob = window.Blob.returnValues[0] - expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true) - + expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true) + const url = URL.createObjectURL.returnValues[0] expect(spyAnchor.href).to.equal(url) diff --git a/tests/unit/storedQueries.spec.js b/tests/unit/storedQueries.spec.js index 130b284..0f4d65d 100644 --- a/tests/unit/storedQueries.spec.js +++ b/tests/unit/storedQueries.spec.js @@ -66,26 +66,28 @@ describe('storedQueries.js', () => { expect(storedQueries.isTabNeedName(tab)).to.equal(true) }) - it ('serialiseQueries', () => { - let queryList = [ - { id: 1, + it('serialiseQueries', () => { + const queryList = [ + { + id: 1, name: 'foo', query: 'SELECT from foo', chart: [], - createdAt:'2020-11-03T14:17:49.524Z', + createdAt: '2020-11-03T14:17:49.524Z', isPredefined: true }, - { id: 2, + { + id: 2, name: 'bar', query: 'SELECT from bar', chart: [], - createdAt:'2020-12-03T14:17:49.524Z' - }, + createdAt: '2020-12-03T14:17:49.524Z' + } ] const str = storedQueries.serialiseQueries(queryList) const parsedJson = JSON.parse(str) - + expect(parsedJson).to.have.lengthOf(2) expect(parsedJson[1]).to.eql(queryList[1]) expect(parsedJson[0].id).to.equal(queryList[0].id)