deno.land / x / dormlite@0.0.2 / mod.test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { assertEquals } from "https://deno.land/std@0.165.0/testing/asserts.ts";
import { Database, Model } from "./mod.ts";
class Dinosaur extends Model { static tableName = "dinosaurs";
name: string; coolness: number;
constructor( name: string, coolness: number, ) { super(); this.name = name; this.coolness = coolness; }}
class User extends Model { static tableName = "users";
name: string; email: string;
constructor( name: string, email: string, ) { super(); this.name = name; this.email = email; }}
Deno.test("Test library", async (test) => { await Database.init( "test", [ Dinosaur, User, ], );
await test.step("Get one model", async () => { await User.clear();
const user = new User("Getme", "john@doe.es");
await User.create(user);
const user2: any = await User.find(1);
assertEquals(user2[3], "Getme"); });
await test.step("Create models", async () => { await User.clear();
const user = new User("John Doe", "john@doe.es"); const user2 = new User("John Doe", "john@eod.es");
await User.create(user); await User.create(user2);
const users = await User.all();
assertEquals(users.length, 2); });
Database.db.close(); Deno.removeSync("./test.db", { recursive: true });});
dormlite

Version Info

Tagged at
a year ago