Skip to content

Commit

Permalink
fix: Check for uploader to prevent errors when calling upload() too e…
Browse files Browse the repository at this point in the history
…arly (#938)
  • Loading branch information
mmustafa-tse authored and rmi22186 committed Dec 17, 2024
1 parent bb63c83 commit 4342b0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mp-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ export default function mParticleInstance(instanceName) {
Constants.NativeSdkPaths.Upload
);
} else {
self._APIClient.uploader.prepareAndUpload(false, false);
self._APIClient?.uploader?.prepareAndUpload(false, false);
}
}
};
Expand Down
14 changes: 14 additions & 0 deletions test/src/tests-batchUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ describe('batch uploader', () => {
})
});

it('should not throw an error when upload is called while storage has not been created yet', async () => {
window.localStorage.clear();
window.sessionStorage.clear();

window.mParticle.init(apiKey, window.mParticle.config);

const mpInstance = window.mParticle.getInstance();
const uploader = mpInstance._APIClient.uploader;

expect(uploader).to.equal(null)

expect(() => { window.mParticle.upload() }).to.not.throw(TypeError, /Cannot read properties of null \(reading 'prepareAndUpload'\)/)
});

it('should return batches that fail to unknown HTTP errors', async () => {
window.mParticle.init(apiKey, window.mParticle.config);

Expand Down

0 comments on commit 4342b0a

Please sign in to comment.