| undefined>(undefined),
}) {}
test("applyDelete", () => {
- const events: any = []
+ const events: any[] = []
const p = new P({ obj: { a: 1, b: 2 } })
diff --git a/packages/lib/test/action/applyMethodCall.test.ts b/packages/lib/test/action/applyMethodCall.test.ts
index 0dc6f814..952c15c3 100644
--- a/packages/lib/test/action/applyMethodCall.test.ts
+++ b/packages/lib/test/action/applyMethodCall.test.ts
@@ -17,7 +17,7 @@ export class P extends Model({
}) {}
test("applyCall", () => {
- const events: any = []
+ const events: any[] = []
const p = new P({ arr: [1, 2, 3] })
diff --git a/packages/lib/test/action/applySet.test.ts b/packages/lib/test/action/applySet.test.ts
index 60c27297..e07bedae 100644
--- a/packages/lib/test/action/applySet.test.ts
+++ b/packages/lib/test/action/applySet.test.ts
@@ -5,11 +5,11 @@ import { autoDispose, testModel } from "../utils"
export class P extends Model({
y: prop(0),
ch: prop(undefined),
- obj: prop<{ [k: string]: number } | undefined>(undefined),
+ obj: prop | undefined>(undefined),
}) {}
test("applySet", () => {
- const events: any = []
+ const events: any[] = []
const p = new P({})
diff --git a/packages/lib/test/actionMiddlewares/actionSerialization.test.ts b/packages/lib/test/actionMiddlewares/actionSerialization.test.ts
index 5138235d..892710b7 100644
--- a/packages/lib/test/actionMiddlewares/actionSerialization.test.ts
+++ b/packages/lib/test/actionMiddlewares/actionSerialization.test.ts
@@ -21,6 +21,7 @@ import { testModel } from "../utils"
test("serializeActionCallArgument and deserializeActionCallArgument", () => {
// unserializable args
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
class RandomClass {}
const rc = new RandomClass()
@@ -142,7 +143,7 @@ test("serializeActionCallArgument and deserializeActionCallArgument", () => {
}
expect(serializeActionCallArgument(map)).toEqual(serMap)
- const mapBack = deserializeActionCallArgument(serMap)
+ const mapBack: Map = deserializeActionCallArgument(serMap)
expect(mapBack instanceof Map).toBe(true)
expect(Array.from(mapBack.entries())).toEqual(mapKV)
@@ -155,7 +156,7 @@ test("serializeActionCallArgument and deserializeActionCallArgument", () => {
}
expect(serializeActionCallArgument(set)).toEqual(serSet)
- const setBack = deserializeActionCallArgument(serSet)
+ const setBack: Set = deserializeActionCallArgument(serSet)
expect(setBack instanceof Set).toBe(true)
expect(Array.from(setBack.keys())).toEqual(setK)
@@ -310,9 +311,9 @@ describe("concurrency", () => {
// remove
replicate(captured[0])
// trying to change a deleted item
- expect(() => replicate(captured[1])).toThrow(
- 'object at path ["list",1] with ids [null,"id-2"] could not be resolved'
- )
+ expect(() => {
+ replicate(captured[1])
+ }).toThrow('object at path ["list",1] with ids [null,"id-2"] could not be resolved')
})
test("remove same item twice", () => {
@@ -324,9 +325,9 @@ describe("concurrency", () => {
// remove
replicate(captured[0])
// trying to remove already removed item
- expect(() => replicate(captured[1])).toThrow(
- 'object at path ["list",1] with ids [null,"id-2"] could not be resolved'
- )
+ expect(() => {
+ replicate(captured[1])
+ }).toThrow('object at path ["list",1] with ids [null,"id-2"] could not be resolved')
})
test("remove two and change text on third item", () => {
@@ -338,9 +339,9 @@ describe("concurrency", () => {
// remove
replicate(captured[0])
// trying to change an item that moved to index 0 from index 2
- expect(() => replicate(captured[1])).toThrow(
- 'object at path ["list",2] with ids [null,"id-3"] could not be resolved'
- )
+ expect(() => {
+ replicate(captured[1])
+ }).toThrow('object at path ["list",2] with ids [null,"id-3"] could not be resolved')
})
test("remove 0,1 and 1,2", () => {
@@ -352,8 +353,8 @@ describe("concurrency", () => {
// remove
replicate(captured[0])
// trying to remove an item that no longer exists
- expect(() => replicate(captured[1])).toThrow(
- 'object at path ["list",1] with ids [null,"id-2"] could not be resolved'
- )
+ expect(() => {
+ replicate(captured[1])
+ }).toThrow('object at path ["list",1] with ids [null,"id-2"] could not be resolved')
})
})
diff --git a/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-flow.test.ts b/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-flow.test.ts
index f7e13ccf..00a914b3 100644
--- a/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-flow.test.ts
+++ b/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-flow.test.ts
@@ -152,7 +152,7 @@ test("actionTrackingMiddleware - flow", async () => {
if (ctx.actionName === "addXY") {
return {
result: ActionTrackingResult.Return,
- value: ret.value + 1000,
+ value: (ret.value as number) + 1000,
}
}
return undefined
diff --git a/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-sync.test.ts b/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-sync.test.ts
index fe179fa8..481906e4 100644
--- a/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-sync.test.ts
+++ b/packages/lib/test/actionMiddlewares/actionTrackingMiddleware-sync.test.ts
@@ -128,7 +128,7 @@ test("actionTrackingMiddleware - sync", () => {
if (ctx.actionName === "addXY") {
return {
result: ActionTrackingResult.Return,
- value: ret.value + 1000,
+ value: (ret.value as number) + 1000,
}
}
return undefined
@@ -192,7 +192,9 @@ test("actionTrackingMiddleware - sync", () => {
// throwing
reset()
- expect(() => p1.throw("some error")).toThrow("some error")
+ expect(() => {
+ p1.throw("some error")
+ }).toThrow("some error")
expect(events.map(eventToString)).toMatchInlineSnapshot(`
[
"throw (filter)",
diff --git a/packages/lib/test/actionMiddlewares/onActionMiddleware.test.ts b/packages/lib/test/actionMiddlewares/onActionMiddleware.test.ts
index 2a45e39d..aafe2f3c 100644
--- a/packages/lib/test/actionMiddlewares/onActionMiddleware.test.ts
+++ b/packages/lib/test/actionMiddlewares/onActionMiddleware.test.ts
@@ -214,6 +214,7 @@ test("onActionMiddleware", () => {
// unserializable args
reset()
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
class RandomClass {}
const rc = new RandomClass()
diff --git a/packages/lib/test/actionMiddlewares/readonlyMiddleware.test.ts b/packages/lib/test/actionMiddlewares/readonlyMiddleware.test.ts
index c5558818..8d978469 100644
--- a/packages/lib/test/actionMiddlewares/readonlyMiddleware.test.ts
+++ b/packages/lib/test/actionMiddlewares/readonlyMiddleware.test.ts
@@ -54,10 +54,14 @@ test("subnode", () => {
autoDispose(dispose)
const oldY1 = p.p2.y
- expect(() => p.p2.setY(300)).toThrow("tried to invoke action 'setY' over a readonly node")
+ expect(() => {
+ p.p2.setY(300)
+ }).toThrow("tried to invoke action 'setY' over a readonly node")
expect(p.p2.y).toBe(oldY1)
- allowWrite(() => p.p2.setY(300))
+ allowWrite(() => {
+ p.p2.setY(300)
+ })
expect(p.p2.y).toBe(300)
expect(() => p.setXY(50, 400)).toThrow("tried to invoke action 'setY' over a readonly node")
@@ -81,10 +85,14 @@ test("root node", () => {
autoDispose(dispose)
const oldY1 = p.p2.y
- expect(() => p.p2.setY(300)).toThrow("tried to invoke action 'setY' over a readonly node")
+ expect(() => {
+ p.p2.setY(300)
+ }).toThrow("tried to invoke action 'setY' over a readonly node")
expect(p.p2.y).toBe(oldY1)
- allowWrite(() => p.p2.setY(300))
+ allowWrite(() => {
+ p.p2.setY(300)
+ })
expect(p.p2.y).toBe(300)
const oldX2 = p.x
diff --git a/packages/lib/test/actionMiddlewares/transactionMiddleware.test.ts b/packages/lib/test/actionMiddlewares/transactionMiddleware.test.ts
index e2283755..499a7b93 100644
--- a/packages/lib/test/actionMiddlewares/transactionMiddleware.test.ts
+++ b/packages/lib/test/actionMiddlewares/transactionMiddleware.test.ts
@@ -101,7 +101,11 @@ describe("transactionMiddleware - sync", () => {
})
async function delay(x: number) {
- return new Promise((r) => setTimeout(() => r(x), x))
+ return new Promise((r) =>
+ setTimeout(() => {
+ r(x)
+ }, x)
+ )
}
@testModel("P2Flow")
diff --git a/packages/lib/test/actionMiddlewares/undoMiddleware.test.ts b/packages/lib/test/actionMiddlewares/undoMiddleware.test.ts
index 34f58aaa..ff9132b0 100644
--- a/packages/lib/test/actionMiddlewares/undoMiddleware.test.ts
+++ b/packages/lib/test/actionMiddlewares/undoMiddleware.test.ts
@@ -80,10 +80,14 @@ function expectUndoManagerRedoToBe(manager: UndoManager, undoLevels: number, red
expect(manager.redoQueue.length).toBe(redoLevels)
if (undoLevels <= 0) {
- expect(() => manager.undo()).toThrow("nothing to undo")
+ expect(() => {
+ manager.undo()
+ }).toThrow("nothing to undo")
}
if (redoLevels <= 0) {
- expect(() => manager.redo()).toThrow("nothing to redo")
+ expect(() => {
+ manager.redo()
+ }).toThrow("nothing to redo")
}
}
@@ -102,7 +106,9 @@ test("undoMiddleware - sync", () => {
},
})
expect(manager instanceof UndoManager).toBeTruthy()
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function getEvents(): { undo: ReadonlyArray; redo: ReadonlyArray } {
return {
@@ -134,7 +140,9 @@ test("undoMiddleware - sync", () => {
snapshots.push(getSnapshot(p))
attachedState = "beforeIncXY3,20"
- expect(() => p.incXY(3, 20)).toThrow("incXY")
+ expect(() => {
+ p.incXY(3, 20)
+ }).toThrow("incXY")
snapshots.push(getSnapshot(p))
expect(p.x).toBe(1 + 2 + 3)
@@ -267,7 +275,9 @@ test("undoMiddleware - async", async () => {
const manager = undoMiddleware(r, r.undoData)
expect(manager instanceof UndoManager).toBeTruthy()
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function getEvents(): { undo: ReadonlyArray; redo: ReadonlyArray } {
return {
@@ -493,7 +503,9 @@ test("does not generate steps if using withoutUndo", () => {
const p = r.p
const manager = undoMiddleware(r, r.undoData)
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function expectUndoRedoToBe(undoLevels: number, redoLevels: number) {
expectUndoManagerRedoToBe(manager, undoLevels, redoLevels)
@@ -520,7 +532,9 @@ test("withGroup", () => {
const p = r.p
const manager = undoMiddleware(r, r.undoData)
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function expectUndoRedoToBe(undoLevels: number, redoLevels: number) {
expectUndoManagerRedoToBe(manager, undoLevels, redoLevels)
@@ -558,7 +572,9 @@ test("createGroup", () => {
const p = r.p
const manager = undoMiddleware(r, r.undoData)
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function expectUndoRedoToBe(undoLevels: number, redoLevels: number) {
expectUndoManagerRedoToBe(manager, undoLevels, redoLevels)
@@ -623,7 +639,9 @@ test("withGroupFlow - simple case", async () => {
const p = r.p
const manager = undoMiddleware(r, r.undoData)
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function expectUndoRedoToBe(undoLevels: number, redoLevels: number) {
expectUndoManagerRedoToBe(manager, undoLevels, redoLevels)
@@ -668,7 +686,9 @@ test("withGroupFlow - throwing", async () => {
const p = r.p
const manager = undoMiddleware(r, r.undoData)
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function expectUndoRedoToBe(undoLevels: number, redoLevels: number) {
expectUndoManagerRedoToBe(manager, undoLevels, redoLevels)
@@ -684,14 +704,14 @@ test("withGroupFlow - throwing", async () => {
yield* _await(
manager.withGroupFlow(function* () {
yield* _await(p.incX(3))
- // eslint-disable-next-line no-throw-literal
+ // eslint-disable-next-line no-throw-literal, @typescript-eslint/only-throw-error
throw "inside"
})
)
fail("should have thrown")
} catch (err) {
expect(err).toBe("inside")
- // eslint-disable-next-line no-throw-literal
+ // eslint-disable-next-line no-throw-literal, @typescript-eslint/only-throw-error
throw "outside"
}
})
@@ -720,7 +740,9 @@ test("withGroupFlow - concurrent", async () => {
const p = r.p
const manager = undoMiddleware(r, r.undoData)
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function expectUndoRedoToBe(undoLevels: number, redoLevels: number) {
expectUndoManagerRedoToBe(manager, undoLevels, redoLevels)
@@ -816,7 +838,9 @@ test("concurrent async actions", async () => {
const manager = undoMiddleware(r, r.undoData)
expect(manager instanceof UndoManager).toBeTruthy()
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function getEvents(): { undo: ReadonlyArray; redo: ReadonlyArray } {
return {
@@ -980,7 +1004,9 @@ test("limit undo/redo steps", () => {
maxRedoLevels: 1,
maxUndoLevels: 2,
})
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
function expectUndoRedoToBe(undoLevels: number, redoLevels: number) {
expectUndoManagerRedoToBe(manager, undoLevels, redoLevels)
diff --git a/packages/lib/test/computedTree/computedTree.test.ts b/packages/lib/test/computedTree/computedTree.test.ts
index 98b94f7e..169f05c5 100644
--- a/packages/lib/test/computedTree/computedTree.test.ts
+++ b/packages/lib/test/computedTree/computedTree.test.ts
@@ -1,3 +1,4 @@
+/* eslint-disable @typescript-eslint/class-literal-property-style */
import { computed, reaction, toJS } from "mobx"
import {
computedTree,
@@ -389,7 +390,9 @@ describe("tree utility functions", () => {
}
}
)
- autoDispose(() => disposer(true))
+ autoDispose(() => {
+ disposer(true)
+ })
expect(counter).toBe(1)
@@ -405,7 +408,9 @@ describe("tree utility functions", () => {
test("computed tree cannot be detached", () => {
const r = new R({})
- expect(() => detach(r.model)).toThrow("tried to invoke action '$$detach' over a readonly node")
+ expect(() => {
+ detach(r.model)
+ }).toThrow("tried to invoke action '$$detach' over a readonly node")
})
})
@@ -507,9 +512,9 @@ test("computed tree is reactive", () => {
test("computed tree is readonly", () => {
const r = new R({})
- expect(() => r.model.setValue(11)).toThrow(
- "tried to invoke action 'setValue' over a readonly node"
- )
+ expect(() => {
+ r.model.setValue(11)
+ }).toThrow("tried to invoke action 'setValue' over a readonly node")
})
test("computed tree works with an array of models", () => {
diff --git a/packages/lib/test/dataModel/dataModel.test.ts b/packages/lib/test/dataModel/dataModel.test.ts
index c07e2030..11b09eac 100644
--- a/packages/lib/test/dataModel/dataModel.test.ts
+++ b/packages/lib/test/dataModel/dataModel.test.ts
@@ -114,7 +114,7 @@ test("without type", async () => {
expect(viewRuns).toBe(1)
viewRuns = 0
- const events: any = []
+ const events: any[] = []
autoDispose(
addActionMiddleware({
@@ -463,7 +463,7 @@ test("with type", async () => {
expect(viewRuns).toBe(1)
viewRuns = 0
- const events: any = []
+ const events: any[] = []
autoDispose(
addActionMiddleware({
@@ -789,7 +789,9 @@ test("parent/child", () => {
const tc = new ChildModel({ x: 10 })
- expect(() => pm.setSubObj(tc)).toThrow(
+ expect(() => {
+ pm.setSubObj(tc)
+ }).toThrow(
"data models are not directly supported. you may insert the data in the tree instead ('$' property)."
)
pm.setSubObj(tc.$)
@@ -817,7 +819,7 @@ test("extends works", () => {
const bm = new Base({ x: 10 })
expect(bm.x).toBe(10)
- const events: any = []
+ const events: any[] = []
autoDispose(
addActionMiddleware({
diff --git a/packages/lib/test/model/modelDecorator.test.ts b/packages/lib/test/model/modelDecorator.test.ts
index 22668ce7..7755c0d1 100644
--- a/packages/lib/test/model/modelDecorator.test.ts
+++ b/packages/lib/test/model/modelDecorator.test.ts
@@ -72,9 +72,9 @@ test("model decorator sets model type static prop and toString methods", () => {
expect(`${MyModel}`).toBe(`class MyModel#${type}`)
expect(`${MyModel2}`).toBe(`class MyModel#${type}`)
- const inst = new MyModel2({}) as MyModel
+ const inst = new MyModel2({})
expect(`${inst}`).toBe(`[MyModel#${type} ${JSON.stringify(getSnapshot(inst))}]`)
- expect(`${inst.toString({ withData: false })}`).toBe(`[MyModel#${type}]`)
+ expect(inst.toString({ withData: false })).toBe(`[MyModel#${type}]`)
})
test("decoratedModel", () => {
diff --git a/packages/lib/test/model/onChildAttachedTo.test.ts b/packages/lib/test/model/onChildAttachedTo.test.ts
index 4a77fbfa..c1623032 100644
--- a/packages/lib/test/model/onChildAttachedTo.test.ts
+++ b/packages/lib/test/model/onChildAttachedTo.test.ts
@@ -38,9 +38,9 @@ beforeEach(() => {
const d = onChildAttachedTo(
() => node,
(child) => {
- const path = getParentToChildPath(node, child)!
+ const path = getParentToChildPath(node, child)
if (!path) {
- fail("path between " + node + " and " + child + " could not be found")
+ fail("path between node and child could not be found")
}
log("attached", node, child, path)
return () => {
@@ -120,7 +120,9 @@ beforeEach(() => {
expect(events).toMatchSnapshot("new arr")
// disposer
- disposers.forEach((d) => d(false))
+ disposers.forEach((d) => {
+ d(false)
+ })
events.length = 0
r.a.b.setArr([4, 5, 6])
expect(events).toHaveLength(0)
@@ -190,7 +192,9 @@ test("dynamic target", () => {
expect(events).toMatchSnapshot("remove Todo")
// disposer
- disposers.forEach((d) => d(false))
+ disposers.forEach((d) => {
+ d(false)
+ })
events.length = 0
todoList.removeTodo(todoList.todos[0])
expect(events).toHaveLength(0)
diff --git a/packages/lib/test/model/setter.test.ts b/packages/lib/test/model/setter.test.ts
index 7f66ef5b..b6a90663 100644
--- a/packages/lib/test/model/setter.test.ts
+++ b/packages/lib/test/model/setter.test.ts
@@ -31,7 +31,7 @@ export class P extends Model({
}
test("setter", () => {
- const events: any = []
+ const events: any[] = []
const p = new P({})
diff --git a/packages/lib/test/model/subclassing.test.ts b/packages/lib/test/model/subclassing.test.ts
index a471d3f1..97dfca8d 100644
--- a/packages/lib/test/model/subclassing.test.ts
+++ b/packages/lib/test/model/subclassing.test.ts
@@ -439,7 +439,7 @@ test("abstract model classes with factory", () => {
@computed
public get error(): string | undefined {
- return this.validate!(this.value)
+ return this.validate(this.value)
}
}
diff --git a/packages/lib/test/model/valueType.test.ts b/packages/lib/test/model/valueType.test.ts
index 056c50b9..321b46fc 100644
--- a/packages/lib/test/model/valueType.test.ts
+++ b/packages/lib/test/model/valueType.test.ts
@@ -72,7 +72,7 @@ test("value type", () => {
// (it had no previous parent)
expect(r.setProp(p1)!).toBe(p1)
- const p3 = expectClonedValueType(r.arrPush(p1)!, () => r.p_arr[r.p_arr.length - 1])
+ const p3 = expectClonedValueType(r.arrPush(p1), () => r.p_arr[r.p_arr.length - 1])
const p3_2 = r.arrPop()
expect(p3_2).toBe(p3)
diff --git a/packages/lib/test/patch/patch.test.ts b/packages/lib/test/patch/patch.test.ts
index 6677c100..844c8bdb 100644
--- a/packages/lib/test/patch/patch.test.ts
+++ b/packages/lib/test/patch/patch.test.ts
@@ -56,7 +56,9 @@ describe("onPatches and applyPatches", () => {
pInvPatches
.slice()
.reverse()
- .forEach((invpatches) => applyPatches(p, invpatches, true))
+ .forEach((invpatches) => {
+ applyPatches(p, invpatches, true)
+ })
})
expect(getSnapshot(p)).toStrictEqual(sn)
}
@@ -996,7 +998,9 @@ test("patches with reserved prop names", () => {
pInvPatches
.slice()
.reverse()
- .forEach((invpatches) => applyPatches(p, invpatches, true))
+ .forEach((invpatches) => {
+ applyPatches(p, invpatches, true)
+ })
})
expect(getSnapshot(p)).toStrictEqual(sn)
}
@@ -1074,7 +1078,9 @@ test("patches with action in onAttachedToRootStore", () => {
}
const r = new R({})
- autoDispose(() => unregisterRootStore(r))
+ autoDispose(() => {
+ unregisterRootStore(r)
+ })
registerRootStore(r)
const sn = getSnapshot(r)
@@ -1151,7 +1157,9 @@ test("patches with action in onAttachedToRootStore", () => {
rInvPatches
.slice()
.reverse()
- .forEach((invpatches) => applyPatches(r, invpatches, true))
+ .forEach((invpatches) => {
+ applyPatches(r, invpatches, true)
+ })
})
expect(getSnapshot(r)).toStrictEqual(sn)
})
@@ -1242,7 +1250,9 @@ test("global patches should not include $ in their path", () => {
const disposeOnGlobalPatches = onGlobalPatches((_, p) => {
globalPatches.push(...p)
})
- autoDispose(() => disposeOnGlobalPatches())
+ autoDispose(() => {
+ disposeOnGlobalPatches()
+ })
fromSnapshot(ParentModel, {})
diff --git a/packages/lib/test/redux/connectReduxDevTools.test.ts b/packages/lib/test/redux/connectReduxDevTools.test.ts
index 13f9fdf2..5928eabc 100644
--- a/packages/lib/test/redux/connectReduxDevTools.test.ts
+++ b/packages/lib/test/redux/connectReduxDevTools.test.ts
@@ -28,7 +28,7 @@ test("waitAsync helper works", async () => {
test("waitAsyncReject helper works", async () => {
try {
await waitAsyncReject(10)
- throw fail("should have failed")
+ fail("should have failed")
} catch {
// do nothing
}
@@ -199,7 +199,9 @@ function addStandardTests() {
})
test("m.setXThrow()", () => {
- expect(() => m.setXThrow()).toThrow()
+ expect(() => {
+ m.setXThrow()
+ }).toThrow()
expect(devTools.send.mock.calls).toMatchSnapshot()
})
@@ -211,7 +213,7 @@ function addStandardTests() {
test("m.setXAsyncThrowSync()", async () => {
try {
await m.setXAsyncThrowSync()
- throw fail("should have thrown")
+ fail("should have thrown")
} catch {
// ignore
}
@@ -221,7 +223,7 @@ function addStandardTests() {
test("m.setXAsyncThrowAsync()", async () => {
try {
await m.setXAsyncThrowAsync()
- throw fail("should have thrown")
+ fail("should have thrown")
} catch {
// ignore
}
@@ -249,7 +251,7 @@ function addStandardTests() {
test("m.setXYAsyncThrowSync() -> m.setXAsyncThrowSync()", async () => {
try {
await m.setXYAsyncThrowSync()
- throw fail("should have thrown")
+ fail("should have thrown")
} catch {
// ignore
}
@@ -259,7 +261,7 @@ function addStandardTests() {
test("m.setXYAsyncThrowAsync() -> m.setXYAsyncThrowAsync()", async () => {
try {
await m.setXYAsyncThrowAsync()
- throw fail("should have thrown")
+ fail("should have thrown")
} catch {
// ignore
}
@@ -273,7 +275,7 @@ function addStandardTests() {
test('m.addtoArray({ a: "otherA" }), m.array[0].setA()', () => {
m.addToArray(new M2({ a: "otherA" }))
- m.array[0]!.setA()
+ m.array[0].setA()
expect(devTools.send.mock.calls).toMatchSnapshot()
})
@@ -282,7 +284,7 @@ function addStandardTests() {
x: "snapshotX",
y: "snapshotY",
array: [],
- [modelIdKey]: m.$modelId!,
+ [modelIdKey]: m.$modelId,
})
applySnapshot(m, snapshot)
expect(devTools.send.mock.calls).toMatchSnapshot()
diff --git a/packages/lib/test/ref/customRef.test.ts b/packages/lib/test/ref/customRef.test.ts
index 426367b0..e05ca706 100644
--- a/packages/lib/test/ref/customRef.test.ts
+++ b/packages/lib/test/ref/customRef.test.ts
@@ -25,7 +25,7 @@ interface Country {
@testModel("Countries")
class Countries extends Model({
- countries: prop<{ [k: string]: Country }>(() => ({})),
+ countries: prop>(() => ({})),
selectedCountryRef: prop[ | undefined>(),
selectedCountriesRef: prop][[]>(() => []),
}) {
@@ -73,7 +73,7 @@ const countryRef = customRef("countryRef", {
getId(target) {
const targetParentPath = getParentPath(target)
- return "" + targetParentPath!.path
+ return String(targetParentPath!.path)
},
onResolvedValueChange(ref, newValue, oldValue) {
@@ -84,7 +84,7 @@ const countryRef = customRef("countryRef", {
},
})
-const initialCountries: () => { [k: string]: Country } = () => ({
+const initialCountries: () => Record = () => ({
spain: {
weather: "sunny",
},
@@ -104,7 +104,7 @@ test("single ref works", () => {
expect(c.selectedCountryRef).toBeUndefined()
expect(c.selectedCountry).toBeUndefined()
- const spain = c.countries["spain"]
+ const spain = c.countries.spain
c.setSelectedCountry(spain)
expect(c.selectedCountry).toBe(spain)
@@ -121,9 +121,9 @@ test("single ref works", () => {
// cloning should be ok
const cloneC = clone(c)
- expect(cloneC.countries["spain"]).toBeTruthy()
+ expect(cloneC.countries.spain).toBeTruthy()
const cloneCSelectedCountry = cloneC.selectedCountry
- expect(cloneCSelectedCountry).toBe(cloneC.countries["spain"])
+ expect(cloneCSelectedCountry).toBe(cloneC.countries.spain)
// remove referenced country
c.removeCountry("spain")
@@ -140,7 +140,7 @@ test("single ref works", () => {
)
// clone should not be affected
- expect(cloneC.selectedCountry).toBe(cloneC.countries["spain"])
+ expect(cloneC.selectedCountry).toBe(cloneC.countries.spain)
})
test("array ref works", () => {
@@ -151,8 +151,8 @@ test("array ref works", () => {
expect(c.selectedCountriesRef).toEqual([])
expect(c.selectedCountries).toEqual([])
- const spain = c.countries["spain"]
- const uk = c.countries["uk"]
+ const spain = c.countries.spain
+ const uk = c.countries.uk
c.setSelectedCountries([spain, uk])
expect(c.selectedCountries).toEqual([spain, uk])
@@ -175,9 +175,9 @@ test("array ref works", () => {
// cloning should be ok
const cloneC = clone(c)
- expect(cloneC.countries["spain"]).toBeTruthy()
- expect(cloneC.countries["uk"]).toBeTruthy()
- expect(cloneC.selectedCountries).toEqual([cloneC.countries["spain"], cloneC.countries["uk"]])
+ expect(cloneC.countries.spain).toBeTruthy()
+ expect(cloneC.countries.uk).toBeTruthy()
+ expect(cloneC.selectedCountries).toEqual([cloneC.countries.spain, cloneC.countries.uk])
// remove referenced country
const oldR = r.slice()
@@ -201,7 +201,7 @@ test("array ref works", () => {
expect(oldR[1].current).toBe(uk)
// clone should not be affected
- expect(cloneC.selectedCountries).toEqual([cloneC.countries["spain"], cloneC.countries["uk"]])
+ expect(cloneC.selectedCountries).toEqual([cloneC.countries.spain, cloneC.countries.uk])
})
test("single selection with getRefId", () => {
@@ -285,7 +285,7 @@ const countryRef2 = customRef("countryRef2", {
getId(target) {
const targetParentPath = getParentPath(target)
- return "" + targetParentPath!.path
+ return String(targetParentPath!.path)
},
})
@@ -294,7 +294,7 @@ describe("resolution", () => {
const c = new Countries({
countries: initialCountries(),
})
- const cSpain = c.countries["spain"]
+ const cSpain = c.countries.spain
const ref = countryRef2(cSpain)
@@ -334,7 +334,7 @@ test("isRefOfType", () => {
const c = new Countries({
countries: initialCountries(),
})
- const cSpain = c.countries["spain"]
+ const cSpain = c.countries.spain
const ref = countryRef(cSpain)
const ref2 = countryRef2(cSpain)
diff --git a/packages/lib/test/ref/rootRef.test.ts b/packages/lib/test/ref/rootRef.test.ts
index 232b253a..797cbb18 100644
--- a/packages/lib/test/ref/rootRef.test.ts
+++ b/packages/lib/test/ref/rootRef.test.ts
@@ -39,7 +39,7 @@ class Country extends Model({
@testModel("Countries")
class Countries extends Model({
- countries: prop<{ [k: string]: Country }>(() => ({})),
+ countries: prop>(() => ({})),
selectedCountryRef: prop][ | undefined>(),
selectedCountriesRef: prop][[]>(() => []),
}) {
@@ -90,7 +90,7 @@ const countryRef = rootRef("countryRef", {
},
})
-const initialCountries: () => { [k: string]: Country } = () => ({
+const initialCountries: () => Record = () => ({
spain: new Country({
id: "spain",
weather: "sunny",
@@ -113,7 +113,7 @@ test("single ref works", () => {
expect(c.selectedCountryRef).toBeUndefined()
expect(c.selectedCountry).toBeUndefined()
- const spain = c.countries["spain"]
+ const spain = c.countries.spain
c.setSelectedCountry(spain)
expect(c.selectedCountry).toBe(spain)
@@ -131,9 +131,9 @@ test("single ref works", () => {
// cloning should be ok
const cloneC = clone(c)
- expect(cloneC.countries["spain"]).toBeTruthy()
+ expect(cloneC.countries.spain).toBeTruthy()
const cloneCSelectedCountry = cloneC.selectedCountry
- expect(cloneCSelectedCountry).toBe(cloneC.countries["spain"])
+ expect(cloneCSelectedCountry).toBe(cloneC.countries.spain)
// remove referenced country
c.removeCountry("spain")
@@ -150,7 +150,7 @@ test("single ref works", () => {
)
// clone should not be affected
- expect(cloneC.selectedCountry).toBe(cloneC.countries["spain"])
+ expect(cloneC.selectedCountry).toBe(cloneC.countries.spain)
})
test("array ref works", () => {
@@ -161,8 +161,8 @@ test("array ref works", () => {
expect(c.selectedCountriesRef).toEqual([])
expect(c.selectedCountries).toEqual([])
- const spain = c.countries["spain"]
- const uk = c.countries["uk"]
+ const spain = c.countries.spain
+ const uk = c.countries.uk
c.setSelectedCountries([spain, uk])
expect(c.selectedCountries).toEqual([spain, uk])
@@ -185,9 +185,9 @@ test("array ref works", () => {
// cloning should be ok
const cloneC = clone(c)
- expect(cloneC.countries["spain"]).toBeTruthy()
- expect(cloneC.countries["uk"]).toBeTruthy()
- expect(cloneC.selectedCountries).toEqual([cloneC.countries["spain"], cloneC.countries["uk"]])
+ expect(cloneC.countries.spain).toBeTruthy()
+ expect(cloneC.countries.uk).toBeTruthy()
+ expect(cloneC.selectedCountries).toEqual([cloneC.countries.spain, cloneC.countries.uk])
// remove referenced country
const oldR = r.slice()
@@ -211,7 +211,7 @@ test("array ref works", () => {
expect(oldR[1].current).toBe(uk)
// clone should not be affected
- expect(cloneC.selectedCountries).toEqual([cloneC.countries["spain"], cloneC.countries["uk"]])
+ expect(cloneC.selectedCountries).toEqual([cloneC.countries.spain, cloneC.countries.uk])
})
test("single selection with custom getId", () => {
@@ -276,12 +276,12 @@ test("moving ref between roots", () => {
const c1 = new Countries({
countries: initialCountries(),
})
- const c1Spain = c1.countries["spain"]
+ const c1Spain = c1.countries.spain
const c2 = new Countries({
countries: initialCountries(),
})
- const c2Spain = c2.countries["spain"]
+ const c2Spain = c2.countries.spain
const ref = countryRef(c1Spain)
expect(ref.isValid).toBe(false)
@@ -314,7 +314,7 @@ describe("resolution", () => {
const c = new Countries({
countries: initialCountries(),
})
- const cSpain = c.countries["spain"]
+ const cSpain = c.countries.spain
const ref = countryRef2(cSpain)
@@ -367,7 +367,7 @@ describe("resolution", () => {
const c = new Countries({
countries: initialCountries(),
})
- const cSpain = c.countries["spain"]
+ const cSpain = c.countries.spain
const ref = countryRef2(cSpain)
@@ -407,7 +407,7 @@ test("isRefOfType", () => {
const c = new Countries({
countries: initialCountries(),
})
- const cSpain = c.countries["spain"]
+ const cSpain = c.countries.spain
const ref = countryRef(cSpain)
const ref2 = countryRef2(cSpain)
@@ -590,9 +590,11 @@ test("undo manager can undo removal of a referenced object in a single step", ()
})
const manager = undoMiddleware(c)
- autoDispose(() => manager.dispose())
+ autoDispose(() => {
+ manager.dispose()
+ })
- const spain = c.countries["spain"]
+ const spain = c.countries.spain
c.setSelectedCountry(spain)
expect(manager.undoQueue).toMatchInlineSnapshot(`
@@ -696,7 +698,7 @@ test("backrefs can be updated in the middle of an action if the target and ref a
const c = new Countries({
countries: initialCountries(),
})
- const cSpain = c.countries["spain"]
+ const cSpain = c.countries.spain
c.setSelectedCountryRef(countryRef2(cSpain))
const ref = c.selectedCountryRef!
diff --git a/packages/lib/test/rootStore/rootStore.test.ts b/packages/lib/test/rootStore/rootStore.test.ts
index 5b41cf49..5a058f4f 100644
--- a/packages/lib/test/rootStore/rootStore.test.ts
+++ b/packages/lib/test/rootStore/rootStore.test.ts
@@ -184,9 +184,9 @@ test("array as rootStore", () => {
expect(registerRootStore(arr)).toBe(arr)
expect(isRootStore(arr)).toBeTruthy()
- expect(isRootStore(arr[0]!)).toBeFalsy()
+ expect(isRootStore(arr[0])).toBeFalsy()
expect(getRootStore(arr)).toBe(arr)
- expect(getRootStore(arr[0]!)).toBe(arr)
+ expect(getRootStore(arr[0])).toBe(arr)
expect(events).toMatchInlineSnapshot(`
[
"p3Attached",
@@ -195,7 +195,7 @@ test("array as rootStore", () => {
// detach p3 from root store
resetEvents()
- const oldP3 = arr[0]!
+ const oldP3 = arr[0]
runUnprotected(() => {
arr.splice(0, 1)
})
@@ -217,9 +217,9 @@ test("array as rootStore", () => {
})
expect(isRootStore(arr)).toBeTruthy()
- expect(isRootStore(arr[0]!)).toBeFalsy()
+ expect(isRootStore(arr[0])).toBeFalsy()
expect(getRootStore(arr)).toBe(arr)
- expect(getRootStore(arr[0]!)).toBe(arr)
+ expect(getRootStore(arr[0])).toBe(arr)
expect(events).toMatchInlineSnapshot(`
[
"p3Attached",
@@ -230,9 +230,9 @@ test("array as rootStore", () => {
resetEvents()
unregisterRootStore(arr)
expect(isRootStore(arr)).toBeFalsy()
- expect(isRootStore(arr[0]!)).toBeFalsy()
+ expect(isRootStore(arr[0])).toBeFalsy()
expect(getRootStore(arr)).toBeUndefined()
- expect(getRootStore(arr[0]!)).toBeUndefined()
+ expect(getRootStore(arr[0])).toBeUndefined()
expect(events).toMatchInlineSnapshot(`
[
"p3Detached",
@@ -366,7 +366,7 @@ test("bug #384", () => {
const todos: Todo[] = []
for (let i = 0; i < 5000; i++) {
- todos.push(new Todo({ text: "Todo #" + i }))
+ todos.push(new Todo({ text: `Todo #${i}` }))
}
const store = new Store({})
diff --git a/packages/lib/test/snapshot/getSnapshot.test.ts b/packages/lib/test/snapshot/getSnapshot.test.ts
index 808fb998..31ab58bc 100644
--- a/packages/lib/test/snapshot/getSnapshot.test.ts
+++ b/packages/lib/test/snapshot/getSnapshot.test.ts
@@ -4,6 +4,7 @@ import { createP } from "../testbed"
import { autoDispose, testModel } from "../utils"
test("basic types", () => {
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
expect(getSnapshot(undefined)).toBe(undefined)
expect(getSnapshot(null)).toBe(null)
expect(getSnapshot(7)).toBe(7)
diff --git a/packages/lib/test/snapshot/modelProcessor.test.ts b/packages/lib/test/snapshot/modelProcessor.test.ts
index 0d10c3ff..5204b812 100644
--- a/packages/lib/test/snapshot/modelProcessor.test.ts
+++ b/packages/lib/test/snapshot/modelProcessor.test.ts
@@ -161,7 +161,7 @@ test("output snapshot processor", () => {
toSnapshotProcessor(sn, instance) {
expect(instance instanceof IP4).toBe(true)
return {
- y: sn.arr.map((x) => "" + x).join(","),
+ y: sn.arr.map((x) => String(x)).join(","),
}
},
}
@@ -182,7 +182,7 @@ test("output snapshot processor", () => {
toSnapshotProcessor(sn, instance) {
expect(instance instanceof P4).toBe(true)
return {
- y: sn.arr.map((x) => "" + x).join(","),
+ y: sn.arr.map((x) => String(x)).join(","),
child: sn.child,
}
},
diff --git a/packages/lib/test/snapshot/noModelType.test.ts b/packages/lib/test/snapshot/noModelType.test.ts
index a03ae5e9..d33d0a63 100644
--- a/packages/lib/test/snapshot/noModelType.test.ts
+++ b/packages/lib/test/snapshot/noModelType.test.ts
@@ -1,7 +1,11 @@
import {
+ AnyDataModel,
+ AnyModel,
+ AnyStandardType,
fromSnapshot,
getSnapshot,
Model,
+ ModelClass,
modelIdKey,
modelSnapshotInWithMetadata,
modelSnapshotOutWithMetadata,
@@ -9,6 +13,7 @@ import {
SnapshotInOf,
tProp,
types,
+ TypeToData,
} from "../../src"
import { testModel } from "../utils"
@@ -31,7 +36,7 @@ test("model without model type thanks to a tProp", () => {
)
expect(m2.m1 instanceof M1).toBe(true)
- expect(m2.m1!.x).toBe(6)
+ expect(m2.m1.x).toBe(6)
expect(getSnapshot(m2)).toStrictEqual(
modelSnapshotOutWithMetadata(M2, {
@@ -59,9 +64,9 @@ test("model without model type thanks to a tProp", () => {
})
)
- const sn1 = getSnapshot(types.model(M1), m2.m1!)
+ const sn1 = getSnapshot(types.model(M1), m2.m1)
// multiple calls should yield the same result
- expect(getSnapshot(types.model(M1), m2.m1!)).toBe(sn1)
+ expect(getSnapshot(types.model(M1), m2.m1)).toBe(sn1)
expect(sn1).toStrictEqual(
modelSnapshotOutWithMetadata(M1, {
@@ -85,13 +90,19 @@ test("model without model type thanks to a type passed to fromSnapshot", () => {
// const m2Sn: SnapshotInOf = { y: 1 }
- const testType = (type: any, sn: any, getInstance?: (val: any) => M1) => {
+ const testType = <
+ TType extends AnyStandardType | ModelClass | ModelClass,
+ >(
+ type: TType,
+ sn: SnapshotInOf>,
+ getInstance?: (val: TypeToData) => M1 | M2 | undefined | null
+ ) => {
const fsn = fromSnapshot(type, sn)
const m1 = getInstance?.(fsn)
if (m1 !== undefined) {
expect(m1 instanceof M1).toBe(true)
- expect(m1!.x).toBe(m1Sn.x)
+ expect((m1 as M1).x).toBe(m1Sn.x)
expect(getSnapshot(m1)).toStrictEqual(modelSnapshotOutWithMetadata(M1, m1Sn))
// TODO: do we need a getSnapshot that will skip modelType?
} else {
diff --git a/packages/lib/test/snapshot/propProcessor.test.ts b/packages/lib/test/snapshot/propProcessor.test.ts
index c2565656..f8481ee4 100644
--- a/packages/lib/test/snapshot/propProcessor.test.ts
+++ b/packages/lib/test/snapshot/propProcessor.test.ts
@@ -20,7 +20,7 @@ test("input snapshot processor", () => {
@testModel("customInputSnapshot")
class P3 extends Model({
arr: prop(() => []).withSnapshotProcessor({
- fromSnapshot: (sn: string) => sn?.split(",").map((x) => +x),
+ fromSnapshot: (sn: string) => sn.split(",").map((x) => +x),
}),
}) {}
@@ -85,7 +85,7 @@ test("output snapshot processor", () => {
class IP4 extends Model({
arr: prop(() => []).withSnapshotProcessor({
toSnapshot: (sn) => {
- return sn.map((x) => "" + x).join(",")
+ return sn.map((x) => String(x)).join(",")
},
}),
}) {
@@ -99,7 +99,7 @@ test("output snapshot processor", () => {
class P4 extends Model({
arr: prop(() => []).withSnapshotProcessor({
toSnapshot: (sn) => {
- return sn.map((x) => "" + x).join(",")
+ return sn.map((x) => String(x)).join(",")
},
}),
child: prop(),
@@ -210,6 +210,7 @@ test("model without model type", () => {
if (!sn) return sn
const snCopy = { ...sn }
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete (snCopy as any)[modelTypeKey]
return snCopy
},
diff --git a/packages/lib/test/snapshot/snapshot.test.ts b/packages/lib/test/snapshot/snapshot.test.ts
index 66699eec..b2b2102c 100644
--- a/packages/lib/test/snapshot/snapshot.test.ts
+++ b/packages/lib/test/snapshot/snapshot.test.ts
@@ -432,11 +432,11 @@ test("applySnapshot can create a new submodel", () => {
test("undefined should not be allowed in arrays, but null should", () => {
const p = createP()
- expect(() =>
+ expect(() => {
runUnprotected(() => {
p.arr.push(undefined as any)
})
- ).toThrow("undefined is not supported inside arrays")
+ }).toThrow("undefined is not supported inside arrays")
expect(p.arr.length).toBe(0)
runUnprotected(() => {
@@ -493,9 +493,7 @@ test("types", () => {
assert(
_ as SnapshotInOf>,
_ as {
- items?: {
- [k: string]: number
- }
+ items?: Record
[modelTypeKey]?: string
[modelIdKey]: string
}
@@ -504,9 +502,7 @@ test("types", () => {
assert(
_ as SnapshotOutOf>,
_ as {
- items: {
- [k: string]: number
- }
+ items: Record
[modelTypeKey]?: string
[modelIdKey]: string
}
diff --git a/packages/lib/test/spread/spread.test.ts b/packages/lib/test/spread/spread.test.ts
index 2eb26465..2095ae1b 100644
--- a/packages/lib/test/spread/spread.test.ts
+++ b/packages/lib/test/spread/spread.test.ts
@@ -288,7 +288,7 @@ test("reassigning an object via spreading", () => {
@testModel("SpreadObj")
class SpreadObj extends Model({
[modelIdKey]: idProp,
- spreadObj: prop<{ [k: string]: Obj }>(() => ({})),
+ spreadObj: prop>(() => ({})),
}) {
@modelAction
add(n: string, x: number) {
@@ -300,7 +300,7 @@ test("reassigning an object via spreading", () => {
}
@modelAction
- set(spreadObj: { [k: string]: Obj }) {
+ set(spreadObj: Record) {
this.spreadObj = spreadObj
}
}
@@ -319,9 +319,9 @@ test("reassigning an object via spreading", () => {
const o2 = o.add("two", 2)
const o3 = o.add("three", 3)
- expect(o.spreadObj["one"].x).toBe(1)
- expect(o.spreadObj["two"].x).toBe(2)
- expect(o.spreadObj["three"].x).toBe(3)
+ expect(o.spreadObj.one.x).toBe(1)
+ expect(o.spreadObj.two.x).toBe(2)
+ expect(o.spreadObj.three.x).toBe(3)
expect(getSnapshot(o)).toMatchInlineSnapshot(`
{
diff --git a/packages/lib/test/standardActions/standaloneActions.test.ts b/packages/lib/test/standardActions/standaloneActions.test.ts
index f1a41e46..de90e53f 100644
--- a/packages/lib/test/standardActions/standaloneActions.test.ts
+++ b/packages/lib/test/standardActions/standaloneActions.test.ts
@@ -17,7 +17,7 @@ import {
} from "../../src"
import { autoDispose, testModel } from "../utils"
-test("without type", async () => {
+test("without type", () => {
interface Todo {
done: boolean
text: string
@@ -65,7 +65,7 @@ test("without type", async () => {
myTodoTag.toggleDone()
expect(todo.done).toBe(false)
- const events: any = []
+ const events: any[] = []
autoDispose(
addActionMiddleware({
@@ -361,7 +361,7 @@ test("without type", async () => {
expect(todo.text).toBe("4")
})
-test("with type", async () => {
+test("with type", () => {
const todoType = types.object(() => ({
done: types.boolean,
text: types.string,
@@ -389,7 +389,7 @@ test("with type", async () => {
const todo = toTreeNode(todoType, { done: false, text: "1" })
registerRootStore(todo)
- const events: any = []
+ const events: any[] = []
autoDispose(
addActionMiddleware({
@@ -712,13 +712,13 @@ test("standaloneFlow", async () => {
const root = new DataModel({})
const pr = fetchData(root, 3)
- assert(pr, _ as Promise]