Skip to content

Commit

Permalink
Merge pull request #333 from automerge/fix-import-test
Browse files Browse the repository at this point in the history
fix test: "throws an error if we try to import an invalid document"
  • Loading branch information
pvh authored Apr 22, 2024
2 parents dd8da64 + 08dd959 commit f669301
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/automerge-repo/test/Repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,30 @@ describe("Repo", () => {
expect(A.getHistory(v)).toEqual(A.getHistory(updatedDoc))
})

it("throws an error if we try to import an invalid document", async () => {
it("throws an error if we try to import a nonsensical byte array", async () => {
const { repo } = setup()
expect(() => {
repo.import<TestDoc>(A.init<TestDoc> as unknown as Uint8Array)
repo.import<TestDoc>(new Uint8Array([1, 2, 3]))
}).toThrow()
})

// TODO: not sure if this is the desired behavior from `import`.

it("makes an empty document if we try to import an automerge doc", async () => {
const { repo } = setup()
// @ts-ignore - passing something other than UInt8Array
const handle = repo.import<TestDoc>(A.from({ foo: 123 }))
const doc = await handle.doc()
expect(doc).toEqual({})
})

it("makes an empty document if we try to import a plain object", async () => {
const { repo } = setup()
// @ts-ignore - passing something other than UInt8Array
const handle = repo.import<TestDoc>({ foo: 123 })
const doc = await handle.doc()
expect(doc).toEqual({})
})
})

describe("flush behaviour", () => {
Expand Down

0 comments on commit f669301

Please sign in to comment.