mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REM] utils: remove patch/unpatch
They are out of the scope for Owl.
This commit is contained in:
+1
-59
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
escape,
|
||||
debounce,
|
||||
patch,
|
||||
unpatch
|
||||
} from "../src/utils";
|
||||
import { escape, debounce } from "../src/utils";
|
||||
|
||||
describe("escape", () => {
|
||||
test("normal strings", () => {
|
||||
@@ -33,56 +28,3 @@ describe("debounce", () => {
|
||||
expect(n).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("patch/unpatch", () => {
|
||||
test("can monkey patch a class", () => {
|
||||
class Test {
|
||||
n = 1;
|
||||
|
||||
doSomething(): string {
|
||||
return "hey";
|
||||
}
|
||||
}
|
||||
|
||||
patch(Test, "some_custo", {
|
||||
doSomething(): string {
|
||||
this.n = this.n + 1;
|
||||
return this._super();
|
||||
}
|
||||
});
|
||||
|
||||
const t = new Test();
|
||||
expect(t.n).toBe(1);
|
||||
expect(t.doSomething()).toBe("hey");
|
||||
expect(t.n).toBe(2);
|
||||
});
|
||||
|
||||
test("cannot patch a class twice with same patch name", () => {
|
||||
class Test {}
|
||||
|
||||
patch(Test, "some_custo", {});
|
||||
expect(() => {
|
||||
patch(Test, "some_custo", {});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
test("can unpatch a class", () => {
|
||||
class Test {
|
||||
doSomething(): number {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
patch(Test, "some_custo", {
|
||||
doSomething(): number {
|
||||
return this._super() + 2;
|
||||
}
|
||||
});
|
||||
|
||||
const t = new Test();
|
||||
expect(t.doSomething()).toBe(3);
|
||||
|
||||
unpatch(Test, "some_custo");
|
||||
expect(t.doSomething()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user