This commit is contained in:
Antonio Scandurra 2015-11-11 20:24:56 +01:00
parent b895baacbf
commit c6cb37ac88

View File

@ -597,38 +597,48 @@ describe "Config", ->
atom.config.onDidChange("foo.bar.baz", changeSpy)
it "allows only one change event for the duration of the given promise if it gets resolved", ->
waitsForPromise ->
atom.config.transactAsync ->
atom.config.set("foo.bar.baz", 1)
atom.config.set("foo.bar.baz", 2)
atom.config.set("foo.bar.baz", 3)
Promise.resolve()
promiseResult = null
transactionPromise = atom.config.transactAsync ->
atom.config.set("foo.bar.baz", 1)
atom.config.set("foo.bar.baz", 2)
atom.config.set("foo.bar.baz", 3)
Promise.resolve("a result")
waitsForPromise -> transactionPromise.then (r) -> promiseResult = r
runs ->
expect(promiseResult).toBe("a result")
expect(changeSpy.callCount).toBe(1)
expect(changeSpy.argsForCall[0][0]).toEqual(newValue: 3, oldValue: undefined)
it "allows only one change event for the duration of the given promise if it gets rejected", ->
waitsForPromise shouldReject: true, ->
atom.config.transactAsync ->
atom.config.set("foo.bar.baz", 1)
atom.config.set("foo.bar.baz", 2)
atom.config.set("foo.bar.baz", 3)
Promise.reject()
promiseError = null
transactionPromise = atom.config.transactAsync ->
atom.config.set("foo.bar.baz", 1)
atom.config.set("foo.bar.baz", 2)
atom.config.set("foo.bar.baz", 3)
Promise.reject("an error")
waitsForPromise -> transactionPromise.catch (e) -> promiseError = e
runs ->
expect(promiseError).toBe("an error")
expect(changeSpy.callCount).toBe(1)
expect(changeSpy.argsForCall[0][0]).toEqual(newValue: 3, oldValue: undefined)
it "allows only one change event even when the given callback throws", ->
waitsForPromise shouldReject: true, ->
atom.config.transactAsync ->
atom.config.set("foo.bar.baz", 1)
atom.config.set("foo.bar.baz", 2)
atom.config.set("foo.bar.baz", 3)
throw new Error("Oops!")
error = new Error("Oops!")
promiseError = null
transactionPromise = atom.config.transactAsync ->
atom.config.set("foo.bar.baz", 1)
atom.config.set("foo.bar.baz", 2)
atom.config.set("foo.bar.baz", 3)
throw error
waitsForPromise -> transactionPromise.catch (e) -> promiseError = e
runs ->
expect(promiseError).toBe(error)
expect(changeSpy.callCount).toBe(1)
expect(changeSpy.argsForCall[0][0]).toEqual(newValue: 3, oldValue: undefined)