Skip to content
Myr

test: avoid async/await for node 6

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by aleclarson · committed by aleclarson · parent 327d659 · Browse files · 1 file+38 added−34 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+38 added−34 removed

  • tests:+38 added−34 removed

1 file+38 added−34 removed

modified:__tests__/base.js+38 added-34 removed
831 unmodified lines
832 }).toThrow("Immer forbids circular references")833 })834 })835836 // TODO: rewrite tests with async/await once node 6 support is dropped837 describe("async recipe function", () => {837 it("can modify the draft", async () => {838 it("can modify the draft", () => {839 const base = {a: 0, b: 0}839 const res = await produce(base, async d => {840 return produce(base, d => {841 d.a = 1841 await Promise.resolve()842 d.b = 1842 return Promise.resolve().then(() => {843 d.b = 1844 })845 }).then(res => {846 expect(res).not.toBe(base)847 expect(res).toEqual({a: 1, b: 1})848 })844 expect(res).not.toBe(base)845 expect(res).toEqual({a: 1, b: 1})849 })850848 it("works with rejected promises", async () => {851 it("works with rejected promises", () => {852 let draft853 const base = {a: 0, b: 0}854 const err = new Error("passed")852 try {853 await produce(base, async d => {854 draft = d855 draft.b = 1856 await Promise.reject(err)857 })858 throw "failed"859 } catch (e) {860 expect(e).toBe(err)861 expect(() => draft.a).toThrowError(/revoked/)862 }855 return produce(base, d => {856 draft = d857 draft.b = 1858 return Promise.reject(err)859 }).then(860 () => {861 throw "failed"862 },863 e => {864 expect(e).toBe(err)865 expect(() => draft.a).toThrowError(/revoked/)866 }867 )868 })869865 it("supports recursive produce calls after await", async () => {870 it("supports recursive produce calls after await", () => {871 const base = {obj: {k: 1}}867 const res = await produce(base, async d => {872 return produce(base, d => {873 const obj = d.obj874 delete d.obj875 return Promise.resolve().then(() => {876 d.a = produce({}, d => {877 d.b = obj // Assign a draft owned by the parent scope.878 })879871 // Force the recipe function to return.872 await Promise.resolve()880 // Auto-freezing is prevented when an unowned draft exists.881 expect(Object.isFrozen(d.a)).toBeFalsy()882874 d.a = produce({}, d => {875 d.b = obj // Assign a draft owned by the parent scope.883 // Ensure `obj` is not revoked.884 obj.c = 1885 })877878 // Auto-freezing is prevented when an unowned draft exists.879 expect(Object.isFrozen(d.a)).toBeFalsy()880881 // Ensure `obj` is not revoked.882 obj.c = 1886 }).then(res => {887 expect(res).not.toBe(base)888 expect(res).toEqual({889 a: {b: {k: 1, c: 1}}890 })891 })884 expect(res).not.toBe(base)885 expect(res).toEqual({886 a: {b: {k: 1, c: 1}}887 })892 })893 })894895 it("throws when the draft is modified and another object is returned", () => {
315 unmodified lines