diff --git a/ui/desktop/tests/unit/services/origin-test.js b/ui/desktop/tests/unit/services/origin-test.js index 1355719a2..4d8703cf6 100644 --- a/ui/desktop/tests/unit/services/origin-test.js +++ b/ui/desktop/tests/unit/services/origin-test.js @@ -1,12 +1,27 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; +import sinon from 'sinon'; module('Unit | Service | origin', function (hooks) { setupTest(hooks); - // TODO: Replace this with your real tests. - test('it exists', function (assert) { - let service = this.owner.lookup('service:origin'); - assert.ok(service); + let service, ipcService; + + hooks.beforeEach(function () { + service = this.owner.lookup('service:origin'); + ipcService = this.owner.lookup('service:ipc'); + }); + + test('resets origin on error', async function (assert) { + assert.expect(4); + const ipcServiceStubbed = sinon.stub(ipcService, 'invoke'); + await service.setOrigin(window.location.origin); + assert.equal(service.rendererOrigin, window.location.origin); + assert.equal(service.adapter.host, window.location.origin); + ipcServiceStubbed.withArgs('setOrigin').rejects(); + service.setOrigin('invalid-origin').catch(() => { + assert.notOk(service.rendererOrigin); + assert.equal(service.adapter.host, window.location.origin); + }); }); });