mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
1707bd240d
This could be done by each application, but it does cost only a few lines of code, and it helps standardizing the Owl ecosystem. For example, some library (such as o_spreadsheet) needs to mock side effects, and Odoo also needs to do that, so this prevents duplicated effort. closes #686
36 lines
914 B
TypeScript
36 lines
914 B
TypeScript
import { escape, debounce } from "../src/utils";
|
|
import { browser } from "../src/browser";
|
|
|
|
describe("escape", () => {
|
|
test("normal strings", () => {
|
|
const text = "abc";
|
|
expect(escape(text)).toBe(text);
|
|
});
|
|
|
|
test("special symbols", () => {
|
|
const text = "<ok>";
|
|
expect(escape(text)).toBe("<ok>");
|
|
});
|
|
});
|
|
|
|
describe("debounce", () => {
|
|
test("works as expected", () => {
|
|
jest.useFakeTimers();
|
|
// need to reset them on browser because they were mocked in window, but not
|
|
// on browser object
|
|
browser.setTimeout = window.setTimeout.bind(window);
|
|
browser.clearTimeout = window.clearTimeout.bind(window);
|
|
let n = 0;
|
|
let f = debounce(() => n++, 100);
|
|
expect(n).toBe(0);
|
|
f();
|
|
expect(n).toBe(0);
|
|
f();
|
|
expect(n).toBe(0);
|
|
jest.advanceTimersByTime(90);
|
|
expect(n).toBe(0);
|
|
jest.advanceTimersByTime(20);
|
|
expect(n).toBe(1);
|
|
});
|
|
});
|