diff --git a/doc/learning/overview.md b/doc/learning/overview.md index 1f87a1d9..a9448cb9 100644 --- a/doc/learning/overview.md +++ b/doc/learning/overview.md @@ -111,7 +111,7 @@ class Parent extends Component { static components = { OrderLine }; orders = useState([ { id: 1, name: "Coffee", quantity: 0 }, - { id: 2, name: "Tea", quantity: 0 } + { id: 2, name: "Tea", quantity: 0 }, ]); addToOrder(event) { diff --git a/doc/learning/quick_start.md b/doc/learning/quick_start.md index 236773a9..e4f99246 100644 --- a/doc/learning/quick_start.md +++ b/doc/learning/quick_start.md @@ -281,7 +281,7 @@ import { Component } from "@odoo/owl"; import "regenerator-runtime/runtime"; export async function nextTick() { - return new Promise(function(resolve) { + return new Promise(function (resolve) { setTimeout(() => Component.scheduler.requestAnimationFrame(() => resolve())); }); } @@ -361,26 +361,26 @@ const HtmlWebpackPlugin = require("html-webpack-plugin"); const host = process.env.HOST || "localhost"; -module.exports = function(env, argv) { +module.exports = function (env, argv) { const mode = argv.mode || "development"; return { mode: mode, entry: "./src/main.js", output: { filename: "main.js", - path: path.resolve(__dirname, "dist") + path: path.resolve(__dirname, "dist"), }, module: { rules: [ { test: /\.jsx?$/, loader: "babel-loader", - exclude: /node_modules/ - } - ] + exclude: /node_modules/, + }, + ], }, resolve: { - extensions: [".js", ".jsx"] + extensions: [".js", ".jsx"], }, devServer: { contentBase: path.resolve(__dirname, "public/index.html"), @@ -388,14 +388,14 @@ module.exports = function(env, argv) { hot: true, host, port: 3000, - publicPath: "/" + publicPath: "/", }, plugins: [ new HtmlWebpackPlugin({ inject: true, - template: path.resolve(__dirname, "public/index.html") - }) - ] + template: path.resolve(__dirname, "public/index.html"), + }), + ], }; }; ``` diff --git a/doc/learning/tutorial_todoapp.md b/doc/learning/tutorial_todoapp.md index 1aa4d3a7..90b507cf 100644 --- a/doc/learning/tutorial_todoapp.md +++ b/doc/learning/tutorial_todoapp.md @@ -62,7 +62,7 @@ our application. `app.js` is where we will write all our code. For now, let's just put the following code: ```js -(function() { +(function () { console.log("hello owl", owl.__info__.version); })(); ``` @@ -170,13 +170,13 @@ class App extends Component { { id: 1, title: "buy milk", - isCompleted: true + isCompleted: true, }, { id: 2, title: "clean house", - isCompleted: false - } + isCompleted: false, + }, ]; } ``` @@ -562,23 +562,23 @@ const actions = { const task = { id: state.nextId++, title: title, - isCompleted: false + isCompleted: false, }; state.tasks.push(task); } }, toggleTask({ state }, id) { - const task = state.tasks.find(t => t.id === id); + const task = state.tasks.find((t) => t.id === id); task.isCompleted = !task.isCompleted; }, deleteTask({ state }, id) { - const index = state.tasks.findIndex(t => t.id === id); + const index = state.tasks.findIndex((t) => t.id === id); state.tasks.splice(index, 1); - } + }, }; const initialState = { nextId: 1, - tasks: [] + tasks: [], }; // ------------------------------------------------------------------------- @@ -616,7 +616,7 @@ class App extends Component { static components = { Task }; inputRef = useRef("add-input"); - tasks = useStore(state => state.tasks); + tasks = useStore((state) => state.tasks); dispatch = useDispatch(); mounted() { @@ -811,7 +811,7 @@ For reference, here is the final code: ``` ```js -(function() { +(function () { const { Component, Store } = owl; const { xml } = owl.tags; const { whenReady } = owl.utils; @@ -827,24 +827,24 @@ For reference, here is the final code: const task = { id: state.nextId++, title: title, - isCompleted: false + isCompleted: false, }; state.tasks.push(task); } }, toggleTask({ state }, id) { - const task = state.tasks.find(t => t.id === id); + const task = state.tasks.find((t) => t.id === id); task.isCompleted = !task.isCompleted; }, deleteTask({ state }, id) { - const index = state.tasks.findIndex(t => t.id === id); + const index = state.tasks.findIndex((t) => t.id === id); state.tasks.splice(index, 1); - } + }, }; const initialState = { nextId: 1, - tasks: [] + tasks: [], }; // ------------------------------------------------------------------------- @@ -897,7 +897,7 @@ For reference, here is the final code: static components = { Task }; inputRef = useRef("add-input"); - tasks = useStore(state => state.tasks); + tasks = useStore((state) => state.tasks); filter = useState({ value: "all" }); dispatch = useDispatch(); @@ -916,9 +916,9 @@ For reference, here is the final code: get displayedTasks() { switch (this.filter.value) { case "active": - return this.tasks.filter(t => !t.isCompleted); + return this.tasks.filter((t) => !t.isCompleted); case "completed": - return this.tasks.filter(t => t.isCompleted); + return this.tasks.filter((t) => t.isCompleted); case "all": return this.tasks; } diff --git a/doc/miscellaneous/comparison.md b/doc/miscellaneous/comparison.md index 80ec5978..123ac7fe 100644 --- a/doc/miscellaneous/comparison.md +++ b/doc/miscellaneous/comparison.md @@ -257,11 +257,11 @@ to the store like in redux, with the `useStore` hook (see the [store documentati const actions = { increment({ state }, val) { state.counter.value += val; - } + }, }; const state = { - counter: { value: 0 } + counter: { value: 0 }, }; const store = new owl.Store({ state, actions }); @@ -270,7 +270,7 @@ class Counter extends Component { `; - counter = useStore(state => state.counter); + counter = useStore((state) => state.counter); dispatch = useDispatch(); } diff --git a/doc/reference/component.md b/doc/reference/component.md index b03712f1..a9136f79 100644 --- a/doc/reference/component.md +++ b/doc/reference/component.md @@ -204,7 +204,7 @@ to be called in the constructor. class Counter extends owl.Component { static props = { initialValue: Number, - optional: true + optional: true, }; } ``` @@ -217,7 +217,7 @@ to be called in the constructor. ```js class Counter extends owl.Component { static defaultProps = { - initialValue: 0 + initialValue: 0, }; } ``` @@ -804,8 +804,8 @@ class RootNode extends Component { children: [ { label: "b" }, { label: "c", children: [{ label: "d" }, { label: "e" }] }, - { label: "f", children: [{ label: "g" }] } - ] + { label: "f", children: [{ label: "g" }] }, + ], }; } ``` diff --git a/doc/reference/environment.md b/doc/reference/environment.md index 1c639a05..90bbee0b 100644 --- a/doc/reference/environment.md +++ b/doc/reference/environment.md @@ -113,10 +113,10 @@ async function myEnv() { qweb: qweb, services: { localStorage: localStorage, - rpc: rpc + rpc: rpc, }, debug: false, - inMobileMode: true + inMobileMode: true, }; } diff --git a/doc/reference/error_handling.md b/doc/reference/error_handling.md index 5c64b577..adf858f4 100644 --- a/doc/reference/error_handling.md +++ b/doc/reference/error_handling.md @@ -74,7 +74,7 @@ broadcasted to the application by an event on the `qweb` instance. It may be useful, for example, to log the error somewhere. ```js -env.qweb.on("error", null, function(error) { +env.qweb.on("error", null, function (error) { // do something // react to the error }); diff --git a/doc/reference/event_bus.md b/doc/reference/event_bus.md index 1704b5f8..25dfb6d0 100644 --- a/doc/reference/event_bus.md +++ b/doc/reference/event_bus.md @@ -7,7 +7,7 @@ triggering events, and callbacks. ```js const bus = new owl.core.EventBus(); -bus.on("some-event", null, function(...args) { +bus.on("some-event", null, function (...args) { console.log(...args); }); diff --git a/doc/reference/hooks.md b/doc/reference/hooks.md index 8be666c3..149c4296 100644 --- a/doc/reference/hooks.md +++ b/doc/reference/hooks.md @@ -259,7 +259,7 @@ function useLoader() { } onWillStart(() => updateRecord(component.props.id)); - onWillUpdateProps(nextProps => updateRecord(nextProps.id)); + onWillUpdateProps((nextProps) => updateRecord(nextProps.id)); return record; } diff --git a/doc/reference/qweb_engine.md b/doc/reference/qweb_engine.md index 02b807ae..164b6633 100644 --- a/doc/reference/qweb_engine.md +++ b/doc/reference/qweb_engine.md @@ -114,9 +114,9 @@ For example: const translations = { hello: "bonjour", yes: "oui", - no: "non" + no: "non", }; -const translateFn = str => translations[str] || str; +const translateFn = (str) => translations[str] || str; const qweb = new QWeb({ translateFn }); ``` diff --git a/doc/reference/store.md b/doc/reference/store.md index 845e06e7..a94553c9 100644 --- a/doc/reference/store.md +++ b/doc/reference/store.md @@ -40,14 +40,14 @@ const actions = { state.todos.push({ id: state.nextId++, message, - isCompleted: false + isCompleted: false, }); - } + }, }; const state = { todos: [], - nextId: 1 + nextId: 1, }; const store = new owl.Store({ state, actions }); @@ -90,7 +90,7 @@ const config = { state, actions, getters, - env + env, }; const store = new Store(config); ``` @@ -110,7 +110,7 @@ const actions = { } catch (e) { state.loginState = "error"; } - } + }, }; ``` @@ -144,7 +144,7 @@ const actions = { state.recordId = recordId; const data = await doSomeRPC("/read/", recordId); state.recordData = data; - } + }, }; ``` @@ -159,7 +159,7 @@ const actions = { const data = await doSomeRPC("/read/", recordId); state.recordId = recordId; state.recordData = data; - } + }, }; ``` @@ -187,14 +187,14 @@ transform the data contained in the store. ```js const getters = { getPost({ state }, id) { - const post = state.posts.find(p => p.id === id); - const author = state.authors.find(a => a.id === post.id); + const post = state.posts.find((p) => p.id === id); + const author = state.authors.find((a) => a.id === post.id); return { id, author, - content: post.content + content: post.content, }; - } + }, }; // somewhere else @@ -224,11 +224,11 @@ Assume we have this store: const actions = { increment({ state }, val) { state.counter.value += val; - } + }, }; const state = { - counter: { value: 0 } + counter: { value: 0 }, }; const store = new owl.Store({ state, actions }); ``` @@ -245,7 +245,7 @@ A counter component can then select this value and dispatch an action like this: ```js class Counter extends Component { - counter = useStore(state => state.counter); + counter = useStore((state) => state.counter); dispatch = useDispatch(); } diff --git a/doc/reference/utils.md b/doc/reference/utils.md index c874df64..61668e87 100644 --- a/doc/reference/utils.md +++ b/doc/reference/utils.md @@ -19,7 +19,7 @@ not ready yet, resolved directly otherwise). If called with a callback as argument, it executes it as soon as the DOM ready (or directly). ```js -Promise.all([loadFile("templates.xml"), owl.utils.whenReady()]).then(function([templates]) { +Promise.all([loadFile("templates.xml"), owl.utils.whenReady()]).then(function ([templates]) { const qweb = new owl.QWeb({ templates }); const app = new App({ qweb }); app.mount(document.body); @@ -29,7 +29,7 @@ Promise.all([loadFile("templates.xml"), owl.utils.whenReady()]).then(function([t or alternatively: ```js -owl.utils.whenReady(function() { +owl.utils.whenReady(function () { const qweb = new owl.QWeb(); const app = new App({ qweb }); app.mount(document.body); diff --git a/package.json b/package.json index a7d303f5..79802836 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "jest-environment-jsdom": "^24.7.1", "live-server": "^1.2.1", "npm-run-all": "^4.1.5", - "prettier": "^1.19.1", + "prettier": "^2.0.4", "rollup": "^1.6.0", "rollup-plugin-typescript2": "^0.20.1", "sass": "^1.16.1", @@ -78,6 +78,7 @@ ] }, "prettier": { - "printWidth": 100 + "printWidth": 100, + "endOfLine": "auto" } } diff --git a/src/browser.ts b/src/browser.ts index 46797042..f47a6620 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -19,5 +19,5 @@ export const browser: Browser = { random: Math.random, Date: window.Date, fetch: (window.fetch || (() => {})).bind(window), - localStorage: window.localStorage + localStorage: window.localStorage, }; diff --git a/src/component/component.ts b/src/component/component.ts index 0b3f4a36..ed3ae310 100644 --- a/src/component/component.ts +++ b/src/component/component.ts @@ -203,7 +203,7 @@ export class Component { renderFn: qweb.render.bind(qweb, template), classObj: null, refs: null, - scope: null + scope: null, }; if (constr.style) { this.__applyStyles(constr); @@ -514,7 +514,7 @@ export class Component { const ev = new OwlEvent(component, eventType, { bubbles: true, cancelable: true, - detail: payload + detail: payload, }); const triggerHook = this.env[portalSymbol as any]; if (triggerHook) { @@ -549,7 +549,7 @@ export class Component { } await Promise.all([ this.willUpdateProps(nextProps), - __owl__.willUpdatePropsCB && __owl__.willUpdatePropsCB(nextProps) + __owl__.willUpdatePropsCB && __owl__.willUpdatePropsCB(nextProps), ]); if (fiber.isCompleted) { return; @@ -646,7 +646,7 @@ export class Component { try { let vnode = __owl__.renderFn!(this, { handlers: __owl__.boundHandlers, - fiber: fiber + fiber: fiber, }); // we iterate over the children to detect those that no longer belong to the // current rendering: those ones, if not mounted yet, can (and have to) be diff --git a/src/component/directive.ts b/src/component/directive.ts index 8cfbc731..c4707b39 100644 --- a/src/component/directive.ts +++ b/src/component/directive.ts @@ -7,7 +7,7 @@ import { makeHandlerCode, MODS_CODE } from "../qweb/extensions"; //------------------------------------------------------------------------------ const T_COMPONENT_MODS_CODE = Object.assign({}, MODS_CODE, { - self: "if (e.target !== vn.elm) {return}" + self: "if (e.target !== vn.elm) {return}", }); QWeb.utils.defineProxy = function defineProxy(target, source) { @@ -18,7 +18,7 @@ QWeb.utils.defineProxy = function defineProxy(target, source) { }, set(val) { source[k] = val; - } + }, }); } }; @@ -238,7 +238,7 @@ QWeb.addDirective({ // computing the props string representing the props object let propStr = Object.keys(props) - .map(k => k + ":" + props[k]) + .map((k) => k + ":" + props[k]) .join(","); let componentID = ctx.generateID(); @@ -280,7 +280,7 @@ QWeb.addDirective({ let classDef = classAttr .trim() .split(/\s+/) - .map(a => `'${a}':true`) + .map((a) => `'${a}':true`) .join(","); classObj = `_${ctx.generateID()}`; ctx.addLine(`let ${classObj} = {${classDef}};`); @@ -298,7 +298,7 @@ QWeb.addDirective({ } } let eventsCode = events - .map(function([name, value]) { + .map(function ([name, value]) { const capture = name.match(/\.capture/); name = capture ? name.replace(/\.capture/, "") : name; const { event, handler } = makeHandlerCode( @@ -469,5 +469,5 @@ QWeb.addDirective({ ctx.addLine(`w${componentID}.__owl__.parentLastFiberId = extra.fiber.id;`); return true; - } + }, }); diff --git a/src/component/fiber.ts b/src/component/fiber.ts index c50407ad..84d11cfa 100644 --- a/src/component/fiber.ts +++ b/src/component/fiber.ts @@ -193,7 +193,7 @@ export class Fiber { // build patchQueue const patchQueue: Fiber[] = []; - const doWork: (Fiber) => Fiber | null = function(f) { + const doWork: (Fiber) => Fiber | null = function (f) { patchQueue.push(f); return f.child; }; @@ -280,7 +280,7 @@ export class Fiber { * Cancel a fiber and all its children. */ cancel() { - this._walk(f => { + this._walk((f) => { if (!f.isRendered) { f.root.counter--; } diff --git a/src/component/props_validation.ts b/src/component/props_validation.ts index 058ed30d..996ffb03 100644 --- a/src/component/props_validation.ts +++ b/src/component/props_validation.ts @@ -11,7 +11,7 @@ import { QWeb } from "../qweb/index"; * This is why it is only done in 'dev' mode. */ -QWeb.utils.validateProps = function(Widget, props: Object) { +QWeb.utils.validateProps = function (Widget, props: Object) { const propsDef = (Widget).props; if (propsDef instanceof Array) { // list of strings (prop names) diff --git a/src/component/scheduler.ts b/src/component/scheduler.ts index 68147856..b8117d6b 100644 --- a/src/component/scheduler.ts +++ b/src/component/scheduler.ts @@ -50,7 +50,7 @@ export class Scheduler { return reject(fiber.error); } resolve(); - } + }, }); if (!this.isRunning) { this.start(); @@ -60,7 +60,7 @@ export class Scheduler { rejectFiber(fiber: Fiber, reason: string) { fiber = fiber.root; - const index = this.tasks.findIndex(t => t.fiber === fiber); + const index = this.tasks.findIndex((t) => t.fiber === fiber); if (index >= 0) { const [task] = this.tasks.splice(index, 1); fiber.cancel(); @@ -76,7 +76,7 @@ export class Scheduler { flush() { let tasks = this.tasks; this.tasks = []; - tasks = tasks.filter(task => { + tasks = tasks.filter((task) => { if (task.fiber.isCompleted) { task.callback(); return false; diff --git a/src/component/styles.ts b/src/component/styles.ts index c9c1e604..9fd25f33 100644 --- a/src/component/styles.ts +++ b/src/component/styles.ts @@ -8,7 +8,7 @@ export const STYLESHEETS: { [id: string]: HTMLStyleElement } = {}; export function processSheet(str: string): string { - const tokens = str.split(/(\{|\}|;)/).map(s => s.trim()); + const tokens = str.split(/(\{|\}|;)/).map((s) => s.trim()); const selectorStack: string[][] = []; const parts: string[] = []; let rules: string[] = []; diff --git a/src/config.ts b/src/config.ts index 209674ab..69dc8402 100644 --- a/src/config.ts +++ b/src/config.ts @@ -26,5 +26,5 @@ Object.defineProperty(config, "mode", { } else { console.log(`Owl is now running in 'prod' mode.`); } - } + }, }); diff --git a/src/context.ts b/src/context.ts index ffe4e088..2ae74e38 100644 --- a/src/context.ts +++ b/src/context.ts @@ -79,9 +79,9 @@ export class Context extends EventBus { async __notifyComponents() { const rev = ++this.rev; const subscriptions = this.subscriptions.update; - const groups = partitionBy(subscriptions, s => (s.owner ? s.owner.__owl__.depth : -1)); + const groups = partitionBy(subscriptions, (s) => (s.owner ? s.owner.__owl__.depth : -1)); for (let group of groups) { - const proms = group.map(sub => sub.callback.call(sub.owner, rev)); + const proms = group.map((sub) => sub.callback.call(sub.owner, rev)); // at this point, each component in the current group has registered a // top level fiber in the scheduler. It could happen that rendering these // components is done (if they have no children). This is why we manually @@ -116,7 +116,7 @@ export function useContextWithCB(ctx: Context, component: Component, method): an __owl__.observer.notifyCB = component.render.bind(component); } const currentCB = __owl__.observer.notifyCB; - __owl__.observer.notifyCB = function() { + __owl__.observer.notifyCB = function () { if (ctx.rev > mapping[id]) { // in this case, the context has been updated since we were rendering // last, and we do not need to render here with the observer. A @@ -128,18 +128,18 @@ export function useContextWithCB(ctx: Context, component: Component, method): an mapping[id] = 0; const renderFn = __owl__.renderFn; - __owl__.renderFn = function(comp, params) { + __owl__.renderFn = function (comp, params) { mapping[id] = ctx.rev; return renderFn(comp, params); }; - ctx.on("update", component, async contextRev => { + ctx.on("update", component, async (contextRev) => { if (mapping[id] < contextRev) { mapping[id] = contextRev; await method(); } }); const __destroy = component.__destroy; - component.__destroy = parent => { + component.__destroy = (parent) => { ctx.off("update", component); delete mapping[id]; __destroy.call(component, parent); diff --git a/src/core/event_bus.ts b/src/core/event_bus.ts index 4e3b6895..ccb4d6f5 100644 --- a/src/core/event_bus.ts +++ b/src/core/event_bus.ts @@ -44,7 +44,7 @@ export class EventBus { } this.subscriptions[eventType].push({ owner, - callback + callback, }); } @@ -54,7 +54,7 @@ export class EventBus { off(eventType: string, owner: any) { const subs = this.subscriptions[eventType]; if (subs) { - this.subscriptions[eventType] = subs.filter(s => s.owner !== owner); + this.subscriptions[eventType] = subs.filter((s) => s.owner !== owner); } } diff --git a/src/core/observer.ts b/src/core/observer.ts index 398004aa..df642ad7 100644 --- a/src/core/observer.ts +++ b/src/core/observer.ts @@ -67,14 +67,14 @@ export class Observer { self.notifyCB(); } return true; - } + }, }); const metadata = { value, proxy, rev: this.rev, - parent + parent, }; this.weakMap.set(value, metadata); diff --git a/src/hooks.ts b/src/hooks.ts index c87db484..3deaafbd 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -36,11 +36,11 @@ export function useState(state: T): T { // ----------------------------------------------------------------------------- function makeLifecycleHook(method: string, reverse: boolean = false) { if (reverse) { - return function(cb) { + return function (cb) { const component: Component = Component.current!; if (component.__owl__[method]) { const current = component.__owl__[method]; - component.__owl__[method] = function() { + component.__owl__[method] = function () { current.call(component); cb.call(component); }; @@ -49,11 +49,11 @@ function makeLifecycleHook(method: string, reverse: boolean = false) { } }; } else { - return function(cb) { + return function (cb) { const component: Component = Component.current!; if (component.__owl__[method]) { const current = component.__owl__[method]; - component.__owl__[method] = function() { + component.__owl__[method] = function () { cb.call(component); current.call(component); }; @@ -65,11 +65,11 @@ function makeLifecycleHook(method: string, reverse: boolean = false) { } function makeAsyncHook(method: string) { - return function(cb) { + return function (cb) { const component: Component = Component.current!; if (component.__owl__[method]) { const current = component.__owl__[method]; - component.__owl__[method] = function(...args) { + component.__owl__[method] = function (...args) { return Promise.all([current.call(component, ...args), cb.call(component, ...args)]); }; } else { @@ -114,7 +114,7 @@ export function useRef(name: string): Ref { get comp(): Component | null { const val = __owl__.refs && __owl__.refs[name]; return val instanceof Component ? val : null; - } + }, }; } diff --git a/src/index.ts b/src/index.ts index e5cb40bf..df54acae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,6 @@ export const hooks = Object.assign({}, _hooks, { useContext: _context.useContext, useDispatch: _store.useDispatch, useGetters: _store.useGetters, - useStore: _store.useStore + useStore: _store.useStore, }); export const __info__ = {}; diff --git a/src/misc/portal.ts b/src/misc/portal.ts index 7ff7340d..9820e6c7 100644 --- a/src/misc/portal.ts +++ b/src/misc/portal.ts @@ -26,8 +26,8 @@ export class Portal extends Component { static template = xml``; static props = { target: { - type: String - } + type: String, + }, }; // boolean to indicate whether or not we must listen to 'dom-appended' event @@ -55,12 +55,12 @@ export class Portal extends Component { // put a callback in the env that is propagated to children s.t. portal can // register an handler to those events just before children will trigger them useSubEnv({ - [portalSymbol]: ev => { + [portalSymbol]: (ev) => { if (!this._handledEvents.has(ev.type)) { this.portal!.elm!.addEventListener(ev.type, this._handlerTunnel); this._handledEvents.add(ev.type); } - } + }, }); } /** diff --git a/src/qweb/base_directives.ts b/src/qweb/base_directives.ts index c13f75b5..febca300 100644 --- a/src/qweb/base_directives.ts +++ b/src/qweb/base_directives.ts @@ -96,7 +96,7 @@ QWeb.addDirective({ let value = ctx.getValue(node.getAttribute("t-esc")!); compileValueNode(value, node, qweb, ctx.subContext("escaping", true)); return true; - } + }, }); QWeb.addDirective({ @@ -106,7 +106,7 @@ QWeb.addDirective({ let value = ctx.getValue(node.getAttribute("t-raw")!); compileValueNode(value, node, qweb, ctx); return true; - } + }, }); //------------------------------------------------------------------------------ @@ -163,7 +163,7 @@ QWeb.addDirective({ } } return true; - } + }, }); //------------------------------------------------------------------------------ @@ -179,7 +179,7 @@ QWeb.addDirective({ }, finalize({ ctx }) { ctx.closeIf(); - } + }, }); QWeb.addDirective({ @@ -195,7 +195,7 @@ QWeb.addDirective({ }, finalize({ ctx }) { ctx.closeIf(); - } + }, }); QWeb.addDirective({ @@ -208,7 +208,7 @@ QWeb.addDirective({ }, finalize({ ctx }) { ctx.closeIf(); - } + }, }); //------------------------------------------------------------------------------ @@ -292,7 +292,7 @@ QWeb.addDirective({ } return true; - } + }, }); //------------------------------------------------------------------------------ @@ -353,7 +353,7 @@ QWeb.addDirective({ ctx.addLine("}"); ctx.stopProtectScope(varsID); return true; - } + }, }); //------------------------------------------------------------------------------ @@ -364,7 +364,7 @@ QWeb.addDirective({ priority: 1, atNodeEncounter({ ctx }) { ctx.addLine("debugger;"); - } + }, }); //------------------------------------------------------------------------------ @@ -376,5 +376,5 @@ QWeb.addDirective({ atNodeEncounter({ ctx, value }) { const expr = ctx.formatExpression(value); ctx.addLine(`console.log(${expr})`); - } + }, }); diff --git a/src/qweb/compilation_context.ts b/src/qweb/compilation_context.ts index 35dde215..38f0c46b 100644 --- a/src/qweb/compilation_context.ts +++ b/src/qweb/compilation_context.ts @@ -162,7 +162,7 @@ export class CompilationContext { const tokens = compileExprToArray(expr, this.variables); const done = new Set(); return tokens - .map(tok => { + .map((tok) => { if (tok.varName) { if (!done.has(tok.varName)) { done.add(tok.varName); @@ -189,7 +189,7 @@ export class CompilationContext { return `(${this.formatExpression(s.slice(2, -2))})`; } - let r = s.replace(/\{\{.*?\}\}/g, s => "${" + this.formatExpression(s.slice(2, -2)) + "}"); + let r = s.replace(/\{\{.*?\}\}/g, (s) => "${" + this.formatExpression(s.slice(2, -2)) + "}"); return "`" + r + "`"; } startProtectScope(codeBlock?: boolean): number { diff --git a/src/qweb/expression_parser.ts b/src/qweb/expression_parser.ts index ed74051f..95da771e 100644 --- a/src/qweb/expression_parser.ts +++ b/src/qweb/expression_parser.ts @@ -35,7 +35,7 @@ const WORD_REPLACEMENT = { gt: ">", gte: ">=", lt: "<", - lte: "<=" + lte: "<=", }; export interface QWebVar { @@ -77,7 +77,7 @@ const STATIC_TOKEN_MAP: { [key: string]: TKind } = { ":": "COLON", ",": "COMMA", "(": "LEFT_PAREN", - ")": "RIGHT_PAREN" + ")": "RIGHT_PAREN", }; // note that the space after typeof is relevant. It makes sure that the formatted @@ -86,7 +86,7 @@ const OPERATORS = "...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>, type Tokenizer = (expr: string) => Token | false; -let tokenizeString: Tokenizer = function(expr) { +let tokenizeString: Tokenizer = function (expr) { let s = expr[0]; let start = s; if (s !== "'" && s !== '"') { @@ -114,7 +114,7 @@ let tokenizeString: Tokenizer = function(expr) { return { type: "VALUE", value: s }; }; -let tokenizeNumber: Tokenizer = function(expr) { +let tokenizeNumber: Tokenizer = function (expr) { let s = expr[0]; if (s && s.match(/[0-9]/)) { let i = 1; @@ -128,7 +128,7 @@ let tokenizeNumber: Tokenizer = function(expr) { } }; -let tokenizeSymbol: Tokenizer = function(expr) { +let tokenizeSymbol: Tokenizer = function (expr) { let s = expr[0]; if (s && s.match(/[a-zA-Z_\$]/)) { let i = 1; @@ -145,7 +145,7 @@ let tokenizeSymbol: Tokenizer = function(expr) { } }; -const tokenizeStatic: Tokenizer = function(expr) { +const tokenizeStatic: Tokenizer = function (expr) { const char = expr[0]; if (char && char in STATIC_TOKEN_MAP) { return { type: STATIC_TOKEN_MAP[char], value: char }; @@ -153,7 +153,7 @@ const tokenizeStatic: Tokenizer = function(expr) { return false; }; -const tokenizeOperator: Tokenizer = function(expr) { +const tokenizeOperator: Tokenizer = function (expr) { for (let op of OPERATORS) { if (expr.startsWith(op)) { return { type: "OPERATOR", value: op }; @@ -167,7 +167,7 @@ const TOKENIZERS = [ tokenizeNumber, tokenizeOperator, tokenizeSymbol, - tokenizeStatic + tokenizeStatic, ]; /** @@ -284,6 +284,6 @@ export function compileExprToArray(expr: string, scope: { [key: string]: QWebVar export function compileExpr(expr: string, scope: { [key: string]: QWebVar }): string { return compileExprToArray(expr, scope) - .map(t => t.value) + .map((t) => t.value) .join(""); } diff --git a/src/qweb/extensions.ts b/src/qweb/extensions.ts index abd22a97..9c9f6c77 100644 --- a/src/qweb/extensions.ts +++ b/src/qweb/extensions.ts @@ -23,7 +23,7 @@ import { QWeb } from "./qweb"; export const MODS_CODE = { prevent: "e.preventDefault();", self: "if (e.target !== this.elm) {return}", - stop: "e.stopPropagation();" + stop: "e.stopPropagation();", }; interface HandlerInfo { @@ -50,7 +50,7 @@ export function makeHandlerCode( let code: string; // check if it is a method with no args, a method with args or an expression let args: string = ""; - const name: string = value.replace(/\(.*\)/, function(_args) { + const name: string = value.replace(/\(.*\)/, function (_args) { args = _args.slice(1, -1); return ""; }); @@ -74,7 +74,7 @@ export function makeHandlerCode( putInCache = false; code = ctx.captureExpression(value); } - const modCode = mods.map(mod => modcodes[mod]).join(""); + const modCode = mods.map((mod) => modcodes[mod]).join(""); let handler = `function (e) {if (!context.__owl__.isMounted){return}${modCode}${code}}`; if (putInCache) { const key = ctx.generateTemplateKey(event); @@ -90,7 +90,7 @@ QWeb.addDirective({ atNodeCreation({ ctx, fullName, value, nodeID }) { const { event, handler } = makeHandlerCode(ctx, fullName, value, true); ctx.addLine(`p${nodeID}.on['${event}'] = ${handler};`); - } + }, }); //------------------------------------------------------------------------------ @@ -105,17 +105,17 @@ QWeb.addDirective({ ctx.addLine(`const ${refKey} = ${ctx.interpolate(value)};`); addNodeHook("create", `context.__owl__.refs[${refKey}] = n.elm;`); addNodeHook("destroy", `delete context.__owl__.refs[${refKey}];`); - } + }, }); //------------------------------------------------------------------------------ // t-transition //------------------------------------------------------------------------------ -QWeb.utils.nextFrame = function(cb: () => void) { +QWeb.utils.nextFrame = function (cb: () => void) { requestAnimationFrame(() => requestAnimationFrame(cb)); }; -QWeb.utils.transitionInsert = function(vn: VNode, name: string) { +QWeb.utils.transitionInsert = function (vn: VNode, name: string) { const elm = vn.elm; // remove potential duplicated vnode that is currently being removed, to // prevent from having twice the same node in the DOM during an animation @@ -139,7 +139,7 @@ QWeb.utils.transitionInsert = function(vn: VNode, name: string) { }); }; -QWeb.utils.transitionRemove = function(vn: VNode, name: string, rm: () => void) { +QWeb.utils.transitionRemove = function (vn: VNode, name: string, rm: () => void) { const elm = vn.elm; elm.setAttribute("data-owl-key", vn.key!); @@ -209,12 +209,12 @@ QWeb.addDirective({ let name = value; const hooks = { insert: `utils.transitionInsert(vn, '${name}');`, - remove: `utils.transitionRemove(vn, '${name}', rm);` + remove: `utils.transitionRemove(vn, '${name}', rm);`, }; for (let hookName in hooks) { addNodeHook(hookName, hooks[hookName]); } - } + }, }); //------------------------------------------------------------------------------ @@ -251,13 +251,13 @@ QWeb.addDirective({ } ctx.closeIf(); return true; - } + }, }); //------------------------------------------------------------------------------ // t-model //------------------------------------------------------------------------------ -QWeb.utils.toNumber = function(val: string): number | string { +QWeb.utils.toNumber = function (val: string): number | string { const n = parseFloat(val); return isNaN(n) ? val : n; }; @@ -305,7 +305,7 @@ QWeb.addDirective({ } ctx.addLine(`extra.handlers[${key}] = extra.handlers[${key}] || (${handler});`); ctx.addLine(`p${nodeID}.on['${event}'] = extra.handlers[${key}];`); - } + }, }); //------------------------------------------------------------------------------ @@ -329,5 +329,5 @@ QWeb.addDirective({ if (ctx.loopNumber === 0) { ctx.rootContext.hasKey0 = ctx.keyStack.pop() as boolean; } - } + }, }); diff --git a/src/qweb/qweb.ts b/src/qweb/qweb.ts index 79ac9f97..a3e94cfd 100644 --- a/src/qweb/qweb.ts +++ b/src/qweb/qweb.ts @@ -77,7 +77,7 @@ const NODE_HOOKS_PARAMS = { create: "(_, n)", insert: "vn", remove: "(vn, rm)", - destroy: "()" + destroy: "()", }; interface Utils { @@ -112,9 +112,9 @@ const UTILS: Utils = { addNS(vnode.data, vnode.children, vnode.sel); }, VDomArray: class VDomArray extends Array {}, - vDomToString: function(vdom: VNode[]): string { + vDomToString: function (vdom: VNode[]): string { return vdom - .map(vnode => { + .map((vnode) => { if (vnode.sel) { const node = document.createElement(vnode.sel); const result = patch(node, vnode); @@ -145,7 +145,7 @@ const UTILS: Utils = { obj = newObj; } return obj; - } + }, }; function parseXML(xml: string): Document { @@ -195,7 +195,7 @@ export class QWeb extends EventBus { name: 1, att: 1, attf: 1, - translation: 1 + translation: 1, }; static DIRECTIVES: Directive[] = []; @@ -239,7 +239,7 @@ export class QWeb extends EventBus { QWeb.DIRECTIVE_NAMES[directive.name] = 1; QWeb.DIRECTIVES.sort((d1, d2) => d1.priority - d2.priority); if (directive.extraNames) { - directive.extraNames.forEach(n => (QWeb.DIRECTIVE_NAMES[n] = 1)); + directive.extraNames.forEach((n) => (QWeb.DIRECTIVE_NAMES[n] = 1)); } } @@ -303,11 +303,11 @@ export class QWeb extends EventBus { this._processTemplate(elem); const template = { elem, - fn: function(this: QWeb, context, extra) { + fn: function (this: QWeb, context, extra) { const compiledFunction = this._compile(name, elem); template.fn = compiledFunction; return compiledFunction.call(this, context, extra); - } + }, }; this.templates[name] = template; } @@ -317,10 +317,10 @@ export class QWeb extends EventBus { for (let i = 0, ilen = tbranch.length; i < ilen; i++) { let node = tbranch[i]; let prevElem = node.previousElementSibling!; - let pattr = function(name) { + let pattr = function (name) { return prevElem.getAttribute(name); }; - let nattr = function(name) { + let nattr = function (name) { return +!!node.getAttribute(name); }; if (prevElem && (pattr("t-if") || pattr("t-elif"))) { @@ -330,7 +330,7 @@ export class QWeb extends EventBus { ); } if ( - ["t-if", "t-elif", "t-else"].map(nattr).reduce(function(a, b) { + ["t-if", "t-elif", "t-else"].map(nattr).reduce(function (a, b) { return a + b; }) > 1 ) { @@ -582,7 +582,7 @@ export class QWeb extends EventBus { qweb: this, ctx, fullName, - value + value, }); if (isDone) { for (let { directive, value, fullName } of finalizers) { @@ -597,7 +597,7 @@ export class QWeb extends EventBus { let nodeID = this._compileGenericNode(node, ctx, withHandlers); ctx = ctx.withParent(nodeID); let nodeHooks = {}; - let addNodeHook = function(hook, handler) { + let addNodeHook = function (hook, handler) { nodeHooks[hook] = nodeHooks[hook] || []; nodeHooks[hook].push(handler); }; @@ -611,7 +611,7 @@ export class QWeb extends EventBus { fullName, value, nodeID, - addNodeHook + addNodeHook, }); } } @@ -702,7 +702,7 @@ export class QWeb extends EventBus { if ((value = value.trim())) { let classDef = value .split(/\s+/) - .map(a => `'${escapeQuotes(a)}':true`) + .map((a) => `'${escapeQuotes(a)}':true`) .join(","); if (classObj) { ctx.addLine(`Object.assign(${classObj}, {${classDef}})`); @@ -750,7 +750,7 @@ export class QWeb extends EventBus { const attValueID = ctx.generateID(); ctx.addLine(`let _${attValueID} = ${formattedValue};`); formattedValue = `'${attValue}' + (_${attValueID} ? ' ' + _${attValueID} : '')`; - const attrIndex = attrs.findIndex(att => att.startsWith(attName + ":")); + const attrIndex = attrs.findIndex((att) => att.startsWith(attName + ":")); attrs.splice(attrIndex, 1); } ctx.addLine(`let _${attID} = ${formattedValue};`); diff --git a/src/router/router.ts b/src/router/router.ts index d6c6ba87..4d61d79a 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -97,7 +97,7 @@ export class Router { //-------------------------------------------------------------------------- async start() { - (this as any)._listener = ev => this._navigate(this.currentPath(), ev); + (this as any)._listener = (ev) => this._navigate(this.currentPath(), ev); window.addEventListener("popstate", (this as any)._listener); if (this.mode === "hash") { window.addEventListener("hashchange", (this as any)._listener); @@ -198,7 +198,7 @@ export class Router { return { type: "match", route: route, - params: params + params: params, }; } } @@ -223,7 +223,7 @@ export class Router { const result = await route.beforeRouteEnter({ env: this.env, from: this.currentRoute, - to: route + to: route, }); if (result === false) { return { type: "cancelled" }; diff --git a/src/store.ts b/src/store.ts index 0099820b..8bfa5632 100644 --- a/src/store.ts +++ b/src/store.ts @@ -53,7 +53,7 @@ export class Store extends Context { if (config.getters) { const firstArg = { state: this.state, - getters: this.getters + getters: this.getters, }; for (let g in config.getters) { this.getters[g] = config.getters[g].bind(this, firstArg); @@ -70,7 +70,7 @@ export class Store extends Context { dispatch: this.dispatch.bind(this), env: this.env, state: this.state, - getters: this.getters + getters: this.getters, }, ...payload ); @@ -113,11 +113,11 @@ export function useStore(selector, options: SelectorOptions = {}): any { } return false; } - store.updateFunctions[componentId].push(function(): boolean { + store.updateFunctions[componentId].push(function (): boolean { return selectCompareUpdate(store!.state, component.props); }); - useContextWithCB(store, component, function(): Promise | void { + useContextWithCB(store, component, function (): Promise | void { let shouldRender = false; for (let fn of store.updateFunctions[componentId]) { shouldRender = fn() || shouldRender; @@ -126,12 +126,12 @@ export function useStore(selector, options: SelectorOptions = {}): any { return component.render(); } }); - onWillUpdateProps(props => { + onWillUpdateProps((props) => { selectCompareUpdate(store.state, props); }); const __destroy = component.__destroy; - component.__destroy = parent => { + component.__destroy = (parent) => { delete store.updateFunctions[componentId]; __destroy.call(component, parent); }; @@ -148,7 +148,7 @@ export function useStore(selector, options: SelectorOptions = {}): any { }, has(target, k) { return k in result; - } + }, }); } diff --git a/src/utils.ts b/src/utils.ts index 31772cca..53ddcbc9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,13 +13,13 @@ import { browser } from "./browser"; export function whenReady(fn?: any) { - return new Promise(function(resolve) { + return new Promise(function (resolve) { if (document.readyState !== "loading") { resolve(); } else { document.addEventListener("DOMContentLoaded", resolve, false); } - }).then(fn || function() {}); + }).then(fn || function () {}); } const loadedScripts: { [key: string]: Promise } = {}; @@ -28,14 +28,14 @@ export function loadJS(url: string): Promise { if (url in loadedScripts) { return loadedScripts[url]; } - const promise: Promise = new Promise(function(resolve, reject) { + const promise: Promise = new Promise(function (resolve, reject) { const script = document.createElement("script"); script.type = "text/javascript"; script.src = url; - script.onload = function() { + script.onload = function () { resolve(); }; - script.onerror = function() { + script.onerror = function () { reject(`Error loading file '${url}'`); }; const head = document.head || document.getElementsByTagName("head")[0]; @@ -75,7 +75,7 @@ export function escape(str: string | number | undefined): string { */ export function debounce(func: Function, wait: number, immediate?: boolean): Function { let timeout; - return function(this: any) { + return function (this: any) { const context = this; const args = arguments; function later() { diff --git a/src/vdom/modules.ts b/src/vdom/modules.ts index 4b1bd80d..413e9f24 100644 --- a/src/vdom/modules.ts +++ b/src/vdom/modules.ts @@ -33,7 +33,7 @@ function updateProps(oldVnode: VNode, vnode: VNode): void { export const propsModule = { create: updateProps, - update: updateProps + update: updateProps, } as Module; //------------------------------------------------------------------------------ @@ -151,7 +151,7 @@ function updateEventListeners(oldVnode: VNode, vnode?: VNode): void { export const eventListenersModule = { create: updateEventListeners, update: updateEventListeners, - destroy: updateEventListeners + destroy: updateEventListeners, } as Module; //------------------------------------------------------------------------------ @@ -210,7 +210,7 @@ function updateAttrs(oldVnode: VNode, vnode: VNode): void { export const attrsModule = { create: updateAttrs, - update: updateAttrs + update: updateAttrs, } as Module; //------------------------------------------------------------------------------ diff --git a/src/vdom/vdom.ts b/src/vdom/vdom.ts index d7533588..d1acf44b 100644 --- a/src/vdom/vdom.ts +++ b/src/vdom/vdom.ts @@ -520,7 +520,7 @@ const htmlDomApi = { parentNode, nextSibling, tagName, - setTextContent + setTextContent, } as DOMAPI; //------------------------------------------------------------------------------ diff --git a/tests/animations.test.ts b/tests/animations.test.ts index ee7626d7..def00553 100644 --- a/tests/animations.test.ts +++ b/tests/animations.test.ts @@ -9,7 +9,7 @@ import { patchNextFrame, renderToDOM, unpatchNextFrame, - nextTick + nextTick, } from "./helpers"; //------------------------------------------------------------------------------ @@ -71,7 +71,7 @@ describe("animations", () => { qweb.addTemplate("test", `blue`); let def = makeDeferred(); - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(node.className).toBe("chimay-enter chimay-enter-active"); cb(); expect(node.className).toBe("chimay-enter-active chimay-enter-to"); @@ -91,7 +91,7 @@ describe("animations", () => { qweb.addTemplate("test", `blue`); let def = makeDeferred(); - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(node.className).toBe("chimay-enter chimay-enter-active"); cb(); expect(node.className).toBe("chimay-enter-active chimay-enter-to"); @@ -112,7 +112,7 @@ describe("animations", () => { qweb.addTemplate("test", `blue`); let def = makeDeferred(); - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(node.className).toBe("jupiler-enter jupiler-enter-active"); cb(); expect(node.className).toBe(""); @@ -139,7 +139,7 @@ describe("animations", () => { // insert widget into the DOM let def = makeDeferred(); var spanNode; - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(spanNode.className).toBe("chimay-enter chimay-enter-active"); cb(); expect(spanNode.className).toBe("chimay-enter-active chimay-enter-to"); @@ -155,7 +155,7 @@ describe("animations", () => { // remove span from the DOM def = makeDeferred(); widget.state.hide = true; - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(spanNode.className).toBe("chimay-leave chimay-leave-active"); cb(); expect(spanNode.className).toBe("chimay-leave-active chimay-leave-to"); @@ -182,7 +182,7 @@ describe("animations", () => { // insert widget into the DOM let def = makeDeferred(); var spanNode; - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(spanNode.className).toBe("chimay-enter chimay-enter-active"); cb(); expect(spanNode.className).toBe("chimay-enter-active chimay-enter-to"); @@ -210,7 +210,7 @@ describe("animations", () => { let def = makeDeferred(); var spanNode; - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(fixture.innerHTML).toBe( '
blue
' ); @@ -250,7 +250,7 @@ describe("animations", () => { let def = makeDeferred(); var spanNode; - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(fixture.innerHTML).toBe( '
blue
' ); @@ -275,7 +275,7 @@ describe("animations", () => { // remove span from the DOM def = makeDeferred(); widget.state.display = false; - patchNextFrame(cb => { + patchNextFrame((cb) => { expect(fixture.innerHTML).toBe( '
blue
' ); @@ -315,7 +315,7 @@ describe("animations", () => { let def = makeDeferred(); let phase = "enter"; - patchNextFrame(cb => { + patchNextFrame((cb) => { let spans = fixture.querySelectorAll("span"); expect(spans.length).toBe(1); expect(spans[0].className).toBe(`chimay-${phase} chimay-${phase}-active`); @@ -366,7 +366,7 @@ describe("animations", () => { let def = makeDeferred(); let phase = "enter"; - patchNextFrame(cb => { + patchNextFrame((cb) => { let spans = fixture.querySelectorAll("span"); expect(spans.length).toBe(1); expect(spans[0].className).toBe(`chimay-${phase} chimay-${phase}-active`); @@ -413,7 +413,7 @@ describe("animations", () => { state = useState({ flag: false }); } - patchNextFrame(cb => cb()); + patchNextFrame((cb) => cb()); const widget = new Parent(); await widget.mount(fixture); diff --git a/tests/component/async.test.ts b/tests/component/async.test.ts index a9b51d2e..7644c61a 100644 --- a/tests/component/async.test.ts +++ b/tests/component/async.test.ts @@ -27,7 +27,7 @@ afterEach(() => { function children(w: Component): Component[] { const childrenMap = w.__owl__.children; - return Object.keys(childrenMap).map(id => childrenMap[id]); + return Object.keys(childrenMap).map((id) => childrenMap[id]); } describe("async rendering", () => { @@ -404,7 +404,7 @@ describe("async rendering", () => { } class ChildB extends Component { willStart(): any { - return new Promise(function() {}); + return new Promise(function () {}); } } class Parent extends Component { diff --git a/tests/component/component.test.ts b/tests/component/component.test.ts index ae8415f9..4be2df77 100644 --- a/tests/component/component.test.ts +++ b/tests/component/component.test.ts @@ -10,7 +10,7 @@ import { nextMicroTick, nextTick, normalize, - editInput + editInput, } from "../helpers"; //------------------------------------------------------------------------------ @@ -39,7 +39,7 @@ afterEach(() => { function children(w: Component): Component[] { const childrenMap = w.__owl__.children; - return Object.keys(childrenMap).map(id => childrenMap[id]); + return Object.keys(childrenMap).map((id) => childrenMap[id]); } // Test components @@ -133,7 +133,7 @@ describe("basic widget properties", () => { static template = xml`
`; state = useState({ - counter: 0 + counter: 0, }); } @@ -167,7 +167,7 @@ describe("basic widget properties", () => { static template = xml`
`; state = useState({ - counter: 0 + counter: 0, }); } @@ -537,7 +537,7 @@ describe("lifecycle hooks", () => { "child:mounted", "parent:willUnmount", "child:willUnmount", - "childchild:willUnmount" + "childchild:willUnmount", ]); }); @@ -589,7 +589,7 @@ describe("lifecycle hooks", () => { "childchild:willPatch", "childchild:patched", "child:patched", - "parent:patched" + "parent:patched", ]); }); @@ -782,7 +782,7 @@ describe("lifecycle hooks", () => { "c mounted", "p mounted", "p willunmount", - "c willunmount" + "c willunmount", ]); }); @@ -960,7 +960,7 @@ describe("lifecycle hooks", () => { "parent:willPatch", "child:willPatch", "child:patched", - "parent:patched" + "parent:patched", ]); }); }); @@ -1134,7 +1134,7 @@ describe("composition", () => { class App extends Component { static template = xml``; state = useState({ - child: "a" + child: "a", }); get myComponent() { return this.state.child === "a" ? A : B; @@ -1158,7 +1158,7 @@ describe("composition", () => { class App extends Component { static template = xml``; state = useState({ - child: "a" + child: "a", }); get myComponent() { return this.state.child === "a" ? A : B; @@ -1228,7 +1228,7 @@ describe("composition", () => { static template = xml`
`; state = useState({ - counter: 0 + counter: 0, }); } @@ -1327,7 +1327,7 @@ describe("composition", () => { static template = xml`
`; state = useState({ - counter: 0 + counter: 0, }); } @@ -1350,7 +1350,7 @@ describe("composition", () => { static template = xml`
`; state = useState({ - counter: 0 + counter: 0, }); } @@ -1389,7 +1389,7 @@ describe("composition", () => { ); class Parent extends Component { state = useState({ - numbers: [1, 2, 3] + numbers: [1, 2, 3], }); static components = { ChildWidget }; } @@ -1429,7 +1429,7 @@ describe("composition", () => { class Parent extends Component { static template = "parent"; state = useState({ - numbers: [1, 2, 3] + numbers: [1, 2, 3], }); static components = { ChildWidget }; } @@ -1513,8 +1513,8 @@ describe("composition", () => { blips: [ { a: "a", id: 1 }, { b: "b", id: 2 }, - { c: "c", id: 4 } - ] + { c: "c", id: 4 }, + ], }); } const parent = new Parent(); @@ -1621,8 +1621,8 @@ describe("composition", () => { records: [ { id: 1, val: 1 }, { id: 2, val: 2 }, - { id: 3, val: 3 } - ] + { id: 3, val: 3 }, + ], }); static components = { ChildWidget }; } @@ -2003,7 +2003,7 @@ describe("other directives with t-component", () => { } const widget = new ParentWidget(); await widget.mount(fixture); - (fixture).addEventListener("ev", function(e) { + (fixture).addEventListener("ev", function (e) { steps.push(e.defaultPrevented); }); @@ -2038,7 +2038,7 @@ describe("other directives with t-component", () => { } const widget = new ParentWidget(); await widget.mount(fixture); - (fixture).addEventListener("ev", function(e) { + (fixture).addEventListener("ev", function (e) { steps.push(e.defaultPrevented); }); @@ -2976,7 +2976,7 @@ describe("random stuff/miscellaneous", () => { "D:mounted", "C:mounted", "B:mounted", - "A:mounted" + "A:mounted", ]); // update @@ -2999,7 +2999,7 @@ describe("random stuff/miscellaneous", () => { "E:destroy", "F:mounted", "D:patched", - "C:patched" + "C:patched", ]); }); @@ -3410,7 +3410,7 @@ describe("t-model directive", () => { state = useState([ { f: false, id: 1 }, { f: false, id: 2 }, - { f: false, id: 3 } + { f: false, id: 3 }, ]); } const comp = new SomeComponent(); @@ -3455,7 +3455,7 @@ describe("environment and plugins", () => { let bus = new EventBus(); // definition of a plugin - const somePlugin = env => { + const somePlugin = (env) => { env.someFlag = true; bus.on("some-event", null, () => { env.someFlag = !env.someFlag; diff --git a/tests/component/props_validation.test.ts b/tests/component/props_validation.test.ts index 2b9cd726..8973cb2e 100644 --- a/tests/component/props_validation.test.ts +++ b/tests/component/props_validation.test.ts @@ -92,7 +92,7 @@ describe("props validation", () => { { type: String, ok: "1", ko: 1 }, { type: Object, ok: {}, ko: "1" }, { type: Date, ok: new Date(), ko: "1" }, - { type: Function, ok: () => {}, ko: "1" } + { type: Function, ok: () => {}, ko: "1" }, ]; let props; @@ -149,7 +149,7 @@ describe("props validation", () => { { type: String, ok: "1", ko: 1 }, { type: Object, ok: {}, ko: "1" }, { type: Date, ok: new Date(), ko: "1" }, - { type: Function, ok: () => {}, ko: "1" } + { type: Function, ok: () => {}, ko: "1" }, ]; let props; @@ -396,7 +396,7 @@ describe("props validation", () => { class TestWidget extends Component { static template = xml`
hey
`; static props = { - p: { type: Object, shape: { id: Number, url: String } } + p: { type: Object, shape: { id: Number, url: String } }, }; } class Parent extends Component { @@ -458,9 +458,9 @@ describe("props validation", () => { type: Object, shape: { id: Number, - url: [Boolean, { type: Array, element: Number }] - } - } + url: [Boolean, { type: Array, element: Number }], + }, + }, }; } class Parent extends Component { @@ -510,10 +510,10 @@ describe("props validation", () => { element: { type: Object, shape: { - num: { type: Number, optional: true } - } - } - } + num: { type: Number, optional: true }, + }, + }, + }, }; } let error; @@ -539,8 +539,8 @@ describe("props validation", () => { class TestComponent extends Component { static props = { size: { - validate: e => ["small", "medium", "large"].includes(e) - } + validate: (e) => ["small", "medium", "large"].includes(e), + }, }; } let error; @@ -561,13 +561,13 @@ describe("props validation", () => { }); test("can validate with a custom validator, and a type", () => { - const validator = jest.fn(n => 0 <= n && n <= 10); + const validator = jest.fn((n) => 0 <= n && n <= 10); class TestComponent extends Component { static props = { n: { type: Number, - validate: validator - } + validate: validator, + }, }; } let error; diff --git a/tests/component/slots.test.ts b/tests/component/slots.test.ts index 7c475807..59bca5af 100644 --- a/tests/component/slots.test.ts +++ b/tests/component/slots.test.ts @@ -28,7 +28,7 @@ afterEach(() => { function children(w: Component): Component[] { const childrenMap = w.__owl__.children; - return Object.keys(childrenMap).map(id => childrenMap[id]); + return Object.keys(childrenMap).map((id) => childrenMap[id]); } //------------------------------------------------------------------------------ @@ -224,8 +224,8 @@ describe("t-slot directive", () => { state = useState({ users: [ { id: 1, name: "Aaron" }, - { id: 2, name: "David" } - ] + { id: 2, name: "David" }, + ], }); static components = { Link }; } @@ -268,8 +268,8 @@ describe("t-slot directive", () => { state = useState({ users: [ { id: 1, name: "Aaron" }, - { id: 2, name: "David" } - ] + { id: 2, name: "David" }, + ], }); static components = { Link }; } diff --git a/tests/component/un_mounting.test.ts b/tests/component/un_mounting.test.ts index 052c2a7c..5a848938 100644 --- a/tests/component/un_mounting.test.ts +++ b/tests/component/un_mounting.test.ts @@ -335,7 +335,7 @@ describe("unmounting and remounting", () => { class Child extends Component { static template = xml``; state = useState({ - val: "C1" + val: "C1", }); constructor(parent, props) { super(parent, props); diff --git a/tests/core/event_bus.test.ts b/tests/core/event_bus.test.ts index c7e80255..dc59b459 100644 --- a/tests/core/event_bus.test.ts +++ b/tests/core/event_bus.test.ts @@ -14,7 +14,7 @@ describe("event bus behaviour", () => { expect.assertions(1); const bus = new EventBus(); const owner = {}; - bus.on("event", owner, function(this: any) { + bus.on("event", owner, function (this: any) { expect(this).toBe(owner); }); bus.trigger("event"); diff --git a/tests/core/observer.test.ts b/tests/core/observer.test.ts index 8644ff21..f416deec 100644 --- a/tests/core/observer.test.ts +++ b/tests/core/observer.test.ts @@ -22,7 +22,7 @@ describe("observer", () => { expect(observer.rev).toBe(2); expect(obj2).toEqual({ - a: 2 + a: 2, }); }); @@ -47,7 +47,7 @@ describe("observer", () => { expect(observer.rev).toBe(5); expect(obj).toEqual({ a: null, - b: undefined + b: undefined, }); }); diff --git a/tests/helpers.ts b/tests/helpers.ts index 772b3961..487a35b3 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -9,7 +9,7 @@ import "../src/component/directive"; import { browser } from "../src/browser"; // modifies scheduler to make it faster to test components -scheduler.requestAnimationFrame = function(callback: FrameRequestCallback) { +scheduler.requestAnimationFrame = function (callback: FrameRequestCallback) { setTimeout(callback, 1); return 1; }; @@ -43,7 +43,7 @@ export function nextMicroTick(): Promise { } export async function nextTick(): Promise { - return new Promise(function(resolve) { + return new Promise(function (resolve) { setTimeout(() => scheduler.requestAnimationFrame(() => resolve())); }); } @@ -77,7 +77,7 @@ export function makeDeferred(): Deferred { export function makeTestEnv(): Env { return { qweb: new QWeb(), - browser: browser + browser: browser, }; } diff --git a/tests/hooks.test.ts b/tests/hooks.test.ts index aea9492c..2ef79a6d 100644 --- a/tests/hooks.test.ts +++ b/tests/hooks.test.ts @@ -10,7 +10,7 @@ import { onWillStart, onWillUpdateProps, useSubEnv, - useExternalListener + useExternalListener, } from "../src/hooks"; import { xml } from "../src/tags"; @@ -214,7 +214,7 @@ describe("hooks", () => { "hook:mounted1", "hook:mounted2", "hook:willunmount2", - "hook:willunmount1" + "hook:willunmount1", ]); }); @@ -560,7 +560,7 @@ describe("hooks", () => { test("can use onWillStart, onWillUpdateProps", async () => { const steps: string[] = []; async function slow(): Promise { - return new Promise(resolve => { + return new Promise((resolve) => { setTimeout(() => { resolve("slow"); }, 0); @@ -571,7 +571,7 @@ describe("hooks", () => { steps.push(await slow()); steps.push("onWillStart"); }); - onWillUpdateProps(async nextProps => { + onWillUpdateProps(async (nextProps) => { expect(nextProps).toEqual({ value: 2 }); steps.push(await slow()); steps.push("onWillUpdateProps"); @@ -581,7 +581,7 @@ describe("hooks", () => { onWillStart(() => { steps.push("on2ndStart"); }); - onWillUpdateProps(nextProps => { + onWillUpdateProps((nextProps) => { expect(nextProps).toEqual({ value: 2 }); steps.push("on2ndUpdate"); }); @@ -623,7 +623,7 @@ describe("hooks", () => { "onWillStart", "on2ndUpdate", "slow", - "onWillUpdateProps" + "onWillUpdateProps", ]); }); diff --git a/tests/misc/portal.test.ts b/tests/misc/portal.test.ts index ea085a44..e907a1c6 100644 --- a/tests/misc/portal.test.ts +++ b/tests/misc/portal.test.ts @@ -486,7 +486,7 @@ describe("Portal: Basic use and DOM placement", () => { "parent:mounted", "parent:willPatch", "child:mounted", - "parent:patched" + "parent:patched", ]); parent.state.val = 2; @@ -499,7 +499,7 @@ describe("Portal: Basic use and DOM placement", () => { "parent:willPatch", "child:willPatch", "child:patched", - "parent:patched" + "parent:patched", ]); parent.state.hasChild = false; @@ -515,7 +515,7 @@ describe("Portal: Basic use and DOM placement", () => { "parent:patched", "parent:willPatch", "child:willUnmount", - "parent:patched" + "parent:patched", ]); }); @@ -741,7 +741,7 @@ describe("Portal: Events handling", () => { steps.push(ev.type as string); } } - const bodyListener = ev => { + const bodyListener = (ev) => { steps.push(`body: ${ev.type}`); }; document.body.addEventListener("click", bodyListener); diff --git a/tests/qweb/qweb.test.ts b/tests/qweb/qweb.test.ts index f550f22d..6ebb7893 100644 --- a/tests/qweb/qweb.test.ts +++ b/tests/qweb/qweb.test.ts @@ -195,7 +195,7 @@ describe("t-esc", () => { v2: undefined, v3: null, v4: 0, - v5: "" + v5: "", }; expect(renderToString(qweb, "test", vals)).toBe( "

false

0

" @@ -486,7 +486,7 @@ describe("t-if", () => { cond3: false, cond4: false, m: 5, - n: 2 + n: 2, }; expect(normalize(renderToString(qweb, "test", context))).toBe("
andormgtnlt
"); }); @@ -625,7 +625,7 @@ describe("attributes", () => { test("object", () => { qweb.addTemplate("test", `
`); const result = renderToString(qweb, "test", { - value: { a: 1, b: 2, c: 3 } + value: { a: 1, b: 2, c: 3 }, }); expect(result).toBe(`
`); }); @@ -684,7 +684,7 @@ describe("attributes", () => { const result = renderToString(qweb, "test", { value1: 0, value2: 1, - value3: 2 + value3: 2, }); expect(result).toBe(`
`); }); @@ -703,7 +703,7 @@ describe("attributes", () => { const result = renderToString(qweb, "test", { bar: 0, baz: 1, - qux: { qux: "<>" } + qux: { qux: "<>" }, }); const expected = '
'; expect(result).toBe(expected); @@ -973,7 +973,7 @@ describe("t-call (template calling", () => { `); const root = { val: "a", - children: [{ val: "b", children: [{ val: "c", children: [{ val: "d" }] }] }] + children: [{ val: "b", children: [{ val: "c", children: [{ val: "d" }] }] }], }; const expected = "

a 2

b 3

c 4

d 5

"; @@ -1235,7 +1235,7 @@ describe("t-on", () => { { add() { a = 3; - } + }, }, { handlers: [] } ); @@ -1258,7 +1258,7 @@ describe("t-on", () => { }, handleDblClick() { steps.push("dblclick"); - } + }, }, { handlers: [] } ); @@ -1278,7 +1278,7 @@ describe("t-on", () => { { add(n) { a = a + n; - } + }, }, { handlers: [] } ); @@ -1295,7 +1295,7 @@ describe("t-on", () => { { add({ val }) { a = a + val; - } + }, }, { handlers: [] } ); @@ -1312,7 +1312,7 @@ describe("t-on", () => { { doSomething(arg) { expect(arg).toEqual({}); - } + }, }, { handlers: [] } ); @@ -1328,7 +1328,7 @@ describe("t-on", () => { { doSomething(arg) { expect(arg).toEqual({}); - } + }, }, { handlers: [] } ); @@ -1350,7 +1350,7 @@ describe("t-on", () => { { activate(action) { expect(action).toBe("someval"); - } + }, }, { handlers: [] } ); @@ -1363,7 +1363,7 @@ describe("t-on", () => { let owner = { add() { expect(this).toBe(owner); - } + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); (node).click(); @@ -1373,8 +1373,8 @@ describe("t-on", () => { qweb.addTemplate("test", ``); let owner = { state: { - counter: 0 - } + counter: 0, + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); expect(owner.state.counter).toBe(0); @@ -1387,10 +1387,10 @@ describe("t-on", () => { let owner = { state: { counter: 0, - incrementCounter: inc => { + incrementCounter: (inc) => { owner.state.counter += inc; - } - } + }, + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); expect(owner.state.counter).toBe(0); @@ -1402,8 +1402,8 @@ describe("t-on", () => { qweb.addTemplate("test", ``); let owner = { state: { - flag: true - } + flag: true, + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); expect(owner.state.flag).toBe(true); @@ -1420,8 +1420,8 @@ describe("t-on", () => { return n + 1; }, state: { - n: 11 - } + n: 11, + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); expect(owner.state.n).toBe(11); @@ -1437,7 +1437,7 @@ describe("t-on", () => { let owner = { update() { expect(this).toBe(owner); - } + }, }; const node = renderToDOM(qweb, "main", owner, { handlers: [] }); @@ -1454,7 +1454,7 @@ describe("t-on", () => { expect(this).toBe(owner); expect(val).toBe(444); }, - value: 444 + value: 444, }; const node = renderToDOM(qweb, "main", owner, { handlers: [] }); @@ -1483,7 +1483,7 @@ describe("t-on", () => { onClickPreventedAndStopped(e) { expect(e.defaultPrevented).toBe(true); expect(e.cancelBubble).toBe(true); - } + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); @@ -1509,7 +1509,7 @@ describe("t-on", () => { }, onClickSelf(e) { steps.push("onClickSelf"); - } + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); @@ -1533,10 +1533,10 @@ describe("t-on", () => { ); let steps: boolean[] = []; let owner = { - onClick() {} + onClick() {}, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); - (node).addEventListener("click", function(e) { + (node).addEventListener("click", function (e) { steps.push(e.defaultPrevented); }); @@ -1558,10 +1558,10 @@ describe("t-on", () => { ); let steps: boolean[] = []; let owner = { - onClick() {} + onClick() {}, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); - (node).addEventListener("click", function(e) { + (node).addEventListener("click", function (e) { steps.push(e.defaultPrevented); }); @@ -1589,13 +1589,13 @@ describe("t-on", () => { const owner = { projects: [ { id: 1, name: "Project 1" }, - { id: 2, name: "Project 2" } + { id: 2, name: "Project 2" }, ], onEdit(projectId, ev) { expect(ev.defaultPrevented).toBe(true); steps.push(projectId); - } + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); @@ -1620,7 +1620,7 @@ describe("t-on", () => { ); const node = renderToDOM(qweb, "test", {}, { handlers: [] }); - node.addEventListener("click", e => { + node.addEventListener("click", (e) => { expect(e.defaultPrevented).toBe(true); }); @@ -1636,7 +1636,7 @@ describe("t-on", () => { text: "Click here", onClick() { steps.push("onClick"); - } + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); @@ -1655,7 +1655,7 @@ describe("t-on", () => { html: "Click here", onClick() { steps.push("onClick"); - } + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); @@ -1682,7 +1682,7 @@ describe("t-on", () => { }, doSomething() { steps.push("normal"); - } + }, }; const node = renderToDOM(qweb, "test", owner, { handlers: [] }); @@ -1846,7 +1846,7 @@ describe("t-key", () => { ); expect( renderToString(qweb, "test", { - beers: [{ id: 12, name: "Chimay Rouge" }] + beers: [{ id: 12, name: "Chimay Rouge" }], }) ).toMatchSnapshot(); }); @@ -1959,9 +1959,9 @@ describe("properly support svg", () => { describe("translation support", () => { test("can translate node content", () => { const translations = { - word: "mot" + word: "mot", }; - const translateFn = expr => translations[expr] || expr; + const translateFn = (expr) => translations[expr] || expr; const qweb = new QWeb({ translateFn }); qweb.addTemplate("test", "
word
"); expect(renderToString(qweb, "test")).toBe("
mot
"); @@ -1969,9 +1969,9 @@ describe("translation support", () => { test("does not translate node content if disabled", () => { const translations = { - word: "mot" + word: "mot", }; - const translateFn = expr => translations[expr] || expr; + const translateFn = (expr) => translations[expr] || expr; const qweb = new QWeb({ translateFn }); qweb.addTemplate( "test", @@ -1986,9 +1986,9 @@ describe("translation support", () => { test("some attributes are translated", () => { const translations = { - word: "mot" + word: "mot", }; - const translateFn = expr => translations[expr] || expr; + const translateFn = (expr) => translations[expr] || expr; const qweb = new QWeb({ translateFn }); qweb.addTemplate( "test", diff --git a/tests/qweb/qweb_expressions.test.ts b/tests/qweb/qweb_expressions.test.ts index e713511c..de4f383d 100644 --- a/tests/qweb/qweb_expressions.test.ts +++ b/tests/qweb/qweb_expressions.test.ts @@ -6,12 +6,12 @@ describe("tokenizer", () => { expect(tokenize("{}")).toEqual([ { type: "LEFT_BRACE", value: "{" }, - { type: "RIGHT_BRACE", value: "}" } + { type: "RIGHT_BRACE", value: "}" }, ]); expect(tokenize("{ }}")).toEqual([ { type: "LEFT_BRACE", value: "{" }, { type: "RIGHT_BRACE", value: "}" }, - { type: "RIGHT_BRACE", value: "}" } + { type: "RIGHT_BRACE", value: "}" }, ]); expect(tokenize("a")).toEqual([{ type: "SYMBOL", value: "a" }]); expect(tokenize("true")).toEqual([{ type: "SYMBOL", value: "true" }]); @@ -25,15 +25,15 @@ describe("tokenizer", () => { { type: "SYMBOL", value: "a" }, { type: "COLON", value: ":" }, { type: "VALUE", value: "2" }, - { type: "RIGHT_BRACE", value: "}" } + { type: "RIGHT_BRACE", value: "}" }, ]); expect(tokenize("a,")).toEqual([ { type: "SYMBOL", value: "a" }, - { type: "COMMA", value: "," } + { type: "COMMA", value: "," }, ]); expect(tokenize("][")).toEqual([ { type: "RIGHT_BRACKET", value: "]" }, - { type: "LEFT_BRACKET", value: "[" } + { type: "LEFT_BRACKET", value: "[" }, ]); }); @@ -44,23 +44,23 @@ describe("tokenizer", () => { { type: "OPERATOR", value: "<" }, { type: "OPERATOR", value: ">" }, { type: "OPERATOR", value: "!==" }, - { type: "OPERATOR", value: "!=" } + { type: "OPERATOR", value: "!=" }, ]); expect(tokenize("typeof a")).toEqual([ { type: "OPERATOR", value: "typeof " }, - { type: "SYMBOL", value: "a" } + { type: "SYMBOL", value: "a" }, ]); expect(tokenize("a...1")).toEqual([ { type: "SYMBOL", value: "a" }, { type: "OPERATOR", value: "..." }, - { type: "VALUE", value: "1" } + { type: "VALUE", value: "1" }, ]); expect(tokenize("a in b")).toEqual([ { type: "SYMBOL", value: "a" }, { type: "OPERATOR", value: "in " }, - { type: "SYMBOL", value: "b" } + { type: "SYMBOL", value: "b" }, ]); }); @@ -76,7 +76,7 @@ describe("tokenizer", () => { expect(tokenize('"hello ged"')).toEqual([{ type: "VALUE", value: '"hello ged"' }]); expect(tokenize('"hello ged"}')).toEqual([ { type: "VALUE", value: '"hello ged"' }, - { type: "RIGHT_BRACE", value: "}" } + { type: "RIGHT_BRACE", value: "}" }, ]); expect(tokenize('"hello \\"ged\\""')).toEqual([{ type: "VALUE", value: '"hello \\"ged\\""' }]); }); diff --git a/tests/router/link.test.ts b/tests/router/link.test.ts index e7d19be1..c1f8f9e2 100644 --- a/tests/router/link.test.ts +++ b/tests/router/link.test.ts @@ -37,7 +37,7 @@ describe("Link component", () => { const routes = [ { name: "about", path: "/about" }, - { name: "users", path: "/users" } + { name: "users", path: "/users" }, ]; router = new TestRouter(env, routes, { mode: "history" }); @@ -71,7 +71,7 @@ describe("Link component", () => { const routes = [ { name: "about", path: "/about" }, - { name: "users", path: "/users" } + { name: "users", path: "/users" }, ]; router = new TestRouter(env, routes, { mode: "history" }); @@ -81,7 +81,7 @@ describe("Link component", () => { expect(window.location.pathname).toBe("/users"); var evt = new MouseEvent("click", { - button: 1 + button: 1, }); fixture.querySelector("a")!.dispatchEvent(evt); diff --git a/tests/router/route_component.test.ts b/tests/router/route_component.test.ts index 310909c2..cd199cf1 100644 --- a/tests/router/route_component.test.ts +++ b/tests/router/route_component.test.ts @@ -41,7 +41,7 @@ describe("RouteComponent", () => { const routes = [ { name: "about", path: "/about", component: About }, - { name: "users", path: "/users", component: Users } + { name: "users", path: "/users", component: Users }, ]; router = new TestRouter(env, routes, { mode: "history" }); diff --git a/tests/router/router.test.ts b/tests/router/router.test.ts index 8a9213dc..083b9472 100644 --- a/tests/router/router.test.ts +++ b/tests/router/router.test.ts @@ -21,7 +21,7 @@ describe("router miscellaneous", () => { test("validate routes shape", () => { expect(() => { router = new TestRouter(env, [ - { name: "someroute", path: "/some/path", redirect: { abc: "hey" } as Destination } + { name: "someroute", path: "/some/path", redirect: { abc: "hey" } as Destination }, ]); }).toThrow(`Invalid destination: {"abc":"hey"}`); }); @@ -133,7 +133,7 @@ describe("getRouteParams", () => { test("match some parameterized routes", () => { router = new TestRouter(env, []); expect(router["getRouteParams"]({ path: "/invoices/{{id}}" } as Route, "/invoices/3")).toEqual({ - id: "3" + id: "3", }); }); @@ -141,7 +141,7 @@ describe("getRouteParams", () => { router = new TestRouter(env, [], { mode: "hash" }); expect(router["getRouteParams"]({ path: "/invoices/{{id}}" } as Route, "#/invoices/3")).toEqual( { - id: "3" + id: "3", } ); }); @@ -151,7 +151,7 @@ describe("getRouteParams", () => { expect( router["getRouteParams"]({ path: "/invoices/{{id.number}}" } as Route, "/invoices/3") ).toEqual({ - id: 3 + id: 3, }); }); @@ -160,7 +160,7 @@ describe("getRouteParams", () => { expect( router["getRouteParams"]({ path: "/invoices/{{id.number}}" } as Route, "#/invoices/3") ).toEqual({ - id: 3 + id: 3, }); }); }); @@ -169,7 +169,7 @@ describe("redirect", () => { test("can redirect to other route", async () => { router = new TestRouter(env, [ { name: "routea", path: "/some/path" }, - { name: "routeb", path: "/some/other/path", redirect: { to: "routea" } } + { name: "routeb", path: "/some/other/path", redirect: { to: "routea" } }, ]); await router.start(); @@ -182,7 +182,7 @@ describe("redirect", () => { test("can redirect to other path", async () => { router = new TestRouter(env, [ { name: "routea", path: "/some/path" }, - { name: "routeb", path: "/some/other/path", redirect: { path: "/some/path" } } + { name: "routeb", path: "/some/other/path", redirect: { path: "/some/path" } }, ]); router.navigate = jest.fn(router.navigate); @@ -214,7 +214,7 @@ describe("beforeRouteEnter", () => { const guard = jest.fn(() => false); router = new TestRouter(env, [ { name: "routea", path: "/some/patha" }, - { name: "routeb", path: "/some/pathb", beforeRouteEnter: guard } + { name: "routeb", path: "/some/pathb", beforeRouteEnter: guard }, ]); await router.start(); @@ -235,7 +235,7 @@ describe("beforeRouteEnter", () => { router = new TestRouter(env, [ { name: "routea", path: "/some/patha" }, { name: "routeb", path: "/some/pathb", beforeRouteEnter: guard }, - { name: "routec", path: "/some/pathc" } + { name: "routec", path: "/some/pathc" }, ]); await router.start(); @@ -255,7 +255,7 @@ describe("beforeRouteEnter", () => { }); router = new TestRouter(env, [ { name: "landing", path: "/", beforeRouteEnter: guard }, - { name: "otherroute", path: "/some/other/route" } + { name: "otherroute", path: "/some/other/route" }, ]); expect(window.location.pathname).toBe("/"); diff --git a/tests/store.test.ts b/tests/store.test.ts index 16c7424d..1f655a72 100644 --- a/tests/store.test.ts +++ b/tests/store.test.ts @@ -8,7 +8,7 @@ describe("basic use", () => { const actions = { inc({ state }, delta) { state.n += delta; - } + }, }; const store = new Store({ state, actions }); @@ -25,7 +25,7 @@ describe("basic use", () => { state.n1 += delta1; state.n2 += delta2; state.n3 += delta3; - } + }, }; const store = new Store({ state, actions }); @@ -47,7 +47,7 @@ describe("basic use", () => { }, inc100({ dispatch }) { dispatch("inc", 100); - } + }, }; const store = new Store({ state, actions }); @@ -61,7 +61,7 @@ describe("basic use", () => { const actions = { inc({ state }) { return ++state.n; - } + }, }; const store = new Store({ state, actions }); @@ -87,7 +87,7 @@ describe("basic use", () => { async setTo10({ dispatch }) { await Promise.resolve(); dispatch("setN", 10); - } + }, }; const store = new Store({ state, actions }); @@ -115,7 +115,7 @@ describe("basic use", () => { await Promise.resolve(); dispatch("setN", 10); return 5; - } + }, }; const store = new Store({ state, actions }); @@ -132,7 +132,7 @@ describe("basic use", () => { const actions = { someaction({ env }) { expect(env).toBe(someEnv); - } + }, }; const store = new Store({ state: {}, actions, env: someEnv }); @@ -145,15 +145,15 @@ describe("basic use", () => { 1: { id: 1, name: "bertinchamps", - tasterID: 1 - } + tasterID: 1, + }, }, tasters: { 1: { id: 1, - name: "aaron" - } - } + name: "aaron", + }, + }, }; const getters: { [key: string]: Getter } = { beerTasterName({ state }, beerID) { @@ -161,7 +161,7 @@ describe("basic use", () => { }, bestBeerName({ state }) { return state.beers[1].name; - } + }, }; const store = new Store({ state, actions: {}, getters }); expect(store.getters).toBeDefined(); @@ -176,15 +176,15 @@ describe("basic use", () => { 1: { id: 1, name: "bertinchamps", - tasterID: 1 - } + tasterID: 1, + }, }, tasters: { 1: { id: 1, - name: "aaron" - } - } + name: "aaron", + }, + }, }; const getters = { beerTasterName({ state }, beerID) { @@ -192,14 +192,14 @@ describe("basic use", () => { }, bestBeerName({ state }) { return state.beers[1].name; - } + }, }; const actions = { action({ getters }) { expect(getters).toBeDefined(); expect(getters.bestBeerName()).toBe("bertinchamps"); expect(getters.beerTasterName(1)).toBe("aaron"); - } + }, }; const store = new Store({ state, actions, getters }); store.dispatch("action"); @@ -215,7 +215,7 @@ describe("basic use", () => { }, c({}, i) { return `c${i}`; - } + }, }; const store = new Store({ getters, state: {}, actions: {} }); @@ -226,7 +226,7 @@ describe("basic use", () => { describe("advanced state properties", () => { test("state in the store is reference equal after mutation", async () => { const actions = { - donothing() {} + donothing() {}, }; const store = new Store({ state: {}, actions }); const state = store.state; @@ -242,7 +242,7 @@ describe("advanced state properties", () => { expect(state.a.length).toBe(3); const l = state.a.push(53); expect(l).toBe(4); - } + }, }; const store = new Store({ state, actions }); store.dispatch("m"); @@ -253,11 +253,11 @@ describe("advanced state properties", () => { const actions = { dosomething({ state }) { Object.assign(state.westmalle, { a: 3, b: 4 }); - } + }, }; const store = new Store({ state: { westmalle: { a: 1, b: 2 } }, - actions + actions, }); store.dispatch("dosomething"); expect(store.state.westmalle).toEqual({ a: 3, b: 4 }); @@ -267,7 +267,7 @@ describe("advanced state properties", () => { const actions = { inc({ state }) { state.counter++; - } + }, }; const state = { counter: 0 }; const store = new Store({ state, actions }); @@ -284,7 +284,7 @@ describe("updates triggered by the store", () => { const actions = { inc({ state }, delta) { state.n += delta; - } + }, }; const store = new Store({ state, actions }); store.on("update", null, () => updateCounter++); @@ -308,7 +308,7 @@ describe("updates triggered by the store", () => { noop2({ state }) { const val = state.n; state.n = val; - } + }, }; const store = new Store({ state, actions }); store.on("update", null, () => updateCounter++); diff --git a/tests/store_hooks.test.ts b/tests/store_hooks.test.ts index 86edfdfe..76616425 100644 --- a/tests/store_hooks.test.ts +++ b/tests/store_hooks.test.ts @@ -25,7 +25,7 @@ describe("connecting a component to store", () => { const actions = { addTodo({ state }, msg) { state.todos.push({ msg, id: nextId++ }); - } + }, }; const store = new Store({ state, actions }); @@ -34,7 +34,7 @@ describe("connecting a component to store", () => {
`; - todos = useStore(state => state.todos); + todos = useStore((state) => state.todos); } (env).store = store; @@ -56,7 +56,7 @@ describe("connecting a component to store", () => { }, setNotNull({ state }) { state.nullValue = "ok"; - } + }, }; const store = new Store({ state, actions }); @@ -70,15 +70,15 @@ describe("connecting a component to store", () => { nullValue: string; constructor() { super(); - this.isBoolean = useStore(state => state.isBoolean, { - onUpdate: isBoolean => { + this.isBoolean = useStore((state) => state.isBoolean, { + onUpdate: (isBoolean) => { this.isBoolean = isBoolean; - } + }, }); - this.nullValue = useStore(state => state.nullValue, { - onUpdate: nullValue => { + this.nullValue = useStore((state) => state.nullValue, { + onUpdate: (nullValue) => { this.nullValue = nullValue; - } + }, }); } } @@ -105,15 +105,15 @@ describe("connecting a component to store", () => { class App extends Component { static template = xml`
`; storeProps = { - array: useStore(state => { + array: useStore((state) => { if (state.useSmallArray) { return state.smallerArray; } return state.biggerArray; - }) + }), }; get mapAdd() { - return this.storeProps.array.map(a => { + return this.storeProps.array.map((a) => { return a + 1; }); } @@ -133,7 +133,7 @@ describe("connecting a component to store", () => { test("throw error if no store is found", async () => { class App extends Component { static template = xml`
`; - todos = useStore(state => state.todos); + todos = useStore((state) => state.todos); } let error; @@ -153,7 +153,7 @@ describe("connecting a component to store", () => { class App extends Component { static template = xml`
`; - storeState = useStore(state => state.a); + storeState = useStore((state) => state.a); } (env).store = store; @@ -170,7 +170,7 @@ describe("connecting a component to store", () => { doSomething({ state }) { state.a = 2; state.b = 3; - } + }, }; const store = new Store({ state, actions }); @@ -180,8 +180,8 @@ describe("connecting a component to store", () => {
`; - a = useStore(state => ({ value: state.a })); - b = useStore(state => ({ value: state.b })); + a = useStore((state) => ({ value: state.a })); + b = useStore((state) => ({ value: state.b })); } App.prototype.__render = jest.fn(App.prototype.__render); @@ -204,7 +204,7 @@ describe("connecting a component to store", () => { const actions = { addTodo({ state }, msg) { state.todos.push({ msg, id: nextId++ }); - } + }, }; const store = new Store({ state, actions }); @@ -213,7 +213,7 @@ describe("connecting a component to store", () => {
`; - todos = useStore(state => state.todos); + todos = useStore((state) => state.todos); } App.prototype.__render = jest.fn(App.prototype.__render); @@ -241,13 +241,13 @@ describe("connecting a component to store", () => { const actions = { addTodo({ state }, msg) { state.todos.push({ msg, id: nextId++ }); - } + }, }; const store = new Store({ state, actions }); class App extends Component { static template = xml`
`; - nbrTodos = useStore(state => ({ value: state.todos.length })); + nbrTodos = useStore((state) => ({ value: state.todos.length })); } (env).store = store; @@ -270,12 +270,12 @@ describe("connecting a component to store", () => { }, incrementA({ state }) { state.a++; - } + }, }; const store = new Store({ state, actions }); class App extends Component { static template = xml`
`; - nbrTodos = useStore(state => ({ value: state.todos.length }), { isEqual: shallowEqual }); + nbrTodos = useStore((state) => ({ value: state.todos.length }), { isEqual: shallowEqual }); } App.prototype.__render = jest.fn(App.prototype.__render); @@ -303,7 +303,7 @@ describe("connecting a component to store", () => { const actions = { addTodo({ state }, msg) { state.todos.push({ msg, id: nextId++ }); - } + }, }; const store = new Store({ state, actions }); @@ -312,7 +312,7 @@ describe("connecting a component to store", () => {
`; - todos = useStore(state => state.todos, { store }); + todos = useStore((state) => state.todos, { store }); } const app = new App(); @@ -331,8 +331,8 @@ describe("connecting a component to store", () => { actions: { inc({ state }) { state.value++; - } - } + }, + }, }); (env).store = store; @@ -342,7 +342,7 @@ describe("connecting a component to store", () => {
`; - storeState = useStore(state => state); + storeState = useStore((state) => state); dispatch = useDispatch(); } const app = new App(); @@ -360,15 +360,15 @@ describe("connecting a component to store", () => { const state = { todos: [ { id: 1, text: "jupiler" }, - { id: 2, text: "chimay" } - ] + { id: 2, text: "chimay" }, + ], }; const store = new Store({ state, actions: {} }); class TodoItem extends Component { static template = xml``; todo = useStore((state, props) => { - return state.todos.find(t => t.id === props.todoId); + return state.todos.find((t) => t.id === props.todoId); }); } @@ -395,14 +395,14 @@ describe("connecting a component to store", () => { const actions = { addTodo({ state }, text) { state.todos.push({ text, id: nextId++ }); - } + }, }; const store = new Store({ state, actions }); class TodoItem extends Component { static template = xml``; todo = useStore((state, props) => { - return state.todos.find(t => t.id === props.id); + return state.todos.find((t) => t.id === props.id); }); } @@ -412,7 +412,7 @@ describe("connecting a component to store", () => {
`; static components = { TodoItem }; - todos = useStore(state => state.todos); + todos = useStore((state) => state.todos); } (env).store = store; @@ -431,16 +431,16 @@ describe("connecting a component to store", () => { importantID: 1, todos: [ { id: 1, text: "jupiler" }, - { id: 2, text: "bertinchamps" } - ] + { id: 2, text: "bertinchamps" }, + ], }; const getters = { importantTodoText({ state }) { - return state.todos.find(todo => todo.id === state.importantID).text; + return state.todos.find((todo) => todo.id === state.importantID).text; }, text({ state }, id) { - return state.todos.find(todo => todo.id === id).text; - } + return state.todos.find((todo) => todo.id === id).text; + }, }; const store = new Store({ state, getters }); @@ -452,10 +452,10 @@ describe("connecting a component to store", () => { `; getters = useGetters(); storeProps = useStore((state, props) => { - const todo = state.todos.find(t => t.id === props.id); + const todo = state.todos.find((t) => t.id === props.id); return { activeTodoText: this.getters.text(todo.id), - importantTodoText: this.getters.importantTodoText() + importantTodoText: this.getters.importantTodoText(), }; }); } @@ -468,7 +468,7 @@ describe("connecting a component to store", () => {
`; - todos = useStore(state => state.todos); + todos = useStore((state) => state.todos); } (env).store = store; @@ -513,13 +513,13 @@ describe("connecting a component to store", () => { `; // we have here a new object - data = useStore(state => ({ beers: state.beers, otherKey: 1 })); + data = useStore((state) => ({ beers: state.beers, otherKey: 1 })); } const actions = { addBeer({ state }, name) { state.beers.push({ name }); - } + }, }; const state = { beers: [{ name: "jupiler" }] }; @@ -542,9 +542,9 @@ describe("connecting a component to store", () => { class Beer extends Component { static template = xml``; beer = useStore((state, props) => state.beers[props.id], { - onUpdate: result => { + onUpdate: (result) => { ++counter; - } + }, }); } @@ -558,7 +558,7 @@ describe("connecting a component to store", () => { const actions = { renameBeer({ state }, { id, name }) { state.beers[id].name = name; - } + }, }; const store = new Store({ state, actions }); (env).store = store; @@ -609,7 +609,7 @@ describe("connecting a component to store", () => { data = useStore((state, props) => ({ selected: state.beers[props.id], consumed: state.beers[state.consumedID] || null, - taster: state.taster + taster: state.taster, })); } @@ -622,14 +622,14 @@ describe("connecting a component to store", () => { const actions = { consume({ state }, beerId) { state.consumedID = beerId; - } + }, }; const state = { beers: { - 1: { name: "jupiler" } + 1: { name: "jupiler" }, }, consumedID: null, - taster: "aaron" + taster: "aaron", }; const store = new Store({ state, actions }); (env).store = store; @@ -665,11 +665,11 @@ describe("connecting a component to store", () => { selected: consumed: `; - info = useStore(function(state, props) { + info = useStore(function (state, props) { return { selected: state.beers[props.id], consumed: state.beers[state.consumedID] || null, - taster: state.taster + taster: state.taster, }; }); } @@ -689,14 +689,14 @@ describe("connecting a component to store", () => { }, renameBeer({ state }, { beerId, name }) { state.beers[beerId].name = name; - } + }, }; const state = { beers: { - 1: { name: "jupiler" } + 1: { name: "jupiler" }, }, consumedID: null, - taster: "aaron" + taster: "aaron", }; const store = new Store({ state, actions }); (env).store = store; @@ -747,11 +747,11 @@ describe("connecting a component to store", () => { const actions = { setValue({ state }, val) { state.x.val = val; - } + }, }; class Parent extends Component { static template = xml`
`; - x = useStore(state => { + x = useStore((state) => { return Object.assign({}, state.x); }); dispatch = useDispatch(); @@ -782,11 +782,11 @@ describe("connecting a component to store", () => { static template = xml`
`; static components = { Child }; - state = useStore(state => { + state = useStore((state) => { steps.push("parent"); return { current: state.current, - isvisible: state.isvisible + isvisible: state.isvisible, }; }); } @@ -795,7 +795,7 @@ describe("connecting a component to store", () => { const actions = { setCurrent({ state }, c) { state.current = c; - } + }, }; const store = new Store({ state, actions }); @@ -831,7 +831,7 @@ describe("connecting a component to store", () => { `; static components = { Child }; - state = useStore(s => { + state = useStore((s) => { steps.push("parent"); return { flag: s.flag, someId: s.someId }; }); @@ -846,7 +846,7 @@ describe("connecting a component to store", () => { const actions = { setFlagToFalse({ state }) { state.flag = false; - } + }, }; const store = new Store({ state, actions }); @@ -874,15 +874,15 @@ describe("connecting a component to store", () => { const actions = { editTodo({ state }) { state.todos[1].title = "abc"; - } + }, }; const todos = { 1: { id: 1, title: "kikoou" } }; const state = { - todos + todos, }; const store = new Store({ state, - actions + actions, }); class TodoItem extends Component<{}, EnvWithStore> { @@ -894,7 +894,7 @@ describe("connecting a component to store", () => { state = useStore((state, props) => { steps.push("item:usestore"); return { - todo: state.todos[props.id] + todo: state.todos[props.id], }; }); @@ -914,7 +914,7 @@ describe("connecting a component to store", () => {
`; static components = { TodoItem }; - state = useStore(state => { + state = useStore((state) => { steps.push("app:usestore"); return { todos: state.todos }; }); @@ -947,15 +947,15 @@ describe("connecting a component to store", () => { const actions = { removeTodo({ state }) { delete state.todos[1]; - } + }, }; const todos = { 1: { id: 1, title: "kikoou" } }; const state = { - todos + todos, }; const store = new Store({ state, - actions + actions, }); class TodoItem extends Component<{}, EnvWithStore> { @@ -967,7 +967,7 @@ describe("connecting a component to store", () => { state = useStore((state, props) => { steps.push("item:usestore"); return { - todo: state.todos[props.id] + todo: state.todos[props.id], }; }); @@ -988,7 +988,7 @@ describe("connecting a component to store", () => {
`; static components = { TodoItem }; - state = useStore(state => { + state = useStore((state) => { steps.push("app:usestore"); return { todos: state.todos }; }); @@ -1016,7 +1016,7 @@ describe("connecting a component to store", () => { "item:usestore", "item:render", "app:usestore", - "app:render" + "app:render", ]); expect(fixture.innerHTML).toBe('
'); }); @@ -1026,7 +1026,7 @@ describe("connecting a component to store", () => { class App extends Component { static template = xml`
`; - store = useStore(s => ({ msg: s.msg })); + store = useStore((s) => ({ msg: s.msg })); willPatch() { steps.push("willpatch"); @@ -1040,7 +1040,7 @@ describe("connecting a component to store", () => { const actions = { setMsg({ state }, c) { state.msg = c; - } + }, }; const store = new Store({ state, actions }); @@ -1061,7 +1061,7 @@ describe("connecting a component to store", () => { class Child extends Component { static template = xml`
`; - store = useStore(s => s); + store = useStore((s) => s); } class Parent extends Component { @@ -1099,7 +1099,7 @@ describe("connecting a component to store", () => { class Child extends Component { static template = xml`
`; - store = useStore(s => { + store = useStore((s) => { steps.push("child selector"); return s; }); @@ -1107,7 +1107,7 @@ describe("connecting a component to store", () => { class Parent extends Component { static template = xml`
`; static components = { Child }; - store = useStore(s => { + store = useStore((s) => { steps.push("parent selector"); return s; }); @@ -1118,7 +1118,7 @@ describe("connecting a component to store", () => { const actions = { toggleChild({ state }) { state.child = !state.child; - } + }, }; const store = new Store({ state, actions }); (env).store = store; @@ -1137,18 +1137,18 @@ describe("connecting a component to store", () => { test("dispatch an action", async () => { class App extends Component { static template = xml`
`; - store = useStore(state => state); + store = useStore((state) => state); dispatch = useDispatch(); } const state = { - counter: 0 + counter: 0, }; const actions = { inc({ state }) { return ++state.counter; - } + }, }; const store = new Store({ state, actions }); @@ -1185,21 +1185,21 @@ describe("various scenarios", () => { await Promise.resolve(); delete state.attachments[100]; state.messages[10].attachmentIds = []; - } + }, }; const state = { attachments: { 100: { id: 100, - name: "text.txt" - } + name: "text.txt", + }, }, messages: { 10: { attachmentIds: [100], - id: 10 - } - } + id: 10, + }, + }, }; const store = new Store({ actions, state }); @@ -1220,7 +1220,7 @@ describe("various scenarios", () => { `; - store = useStore(state => ({ attachmentIds: state.messages[10].attachmentIds })); + store = useStore((state) => ({ attachmentIds: state.messages[10].attachmentIds })); static components = { Attachment }; state = { isAttachmentDeleted: false }; dispatch = useDispatch(); diff --git a/tests/tooling/debug_script_1.test.ts b/tests/tooling/debug_script_1.test.ts index 30202011..50f84702 100644 --- a/tests/tooling/debug_script_1.test.ts +++ b/tests/tooling/debug_script_1.test.ts @@ -20,7 +20,7 @@ debugOwl(owl, {}); test("can log full lifecycle", async () => { const steps: string[] = []; const log = console.log; - console.log = arg => steps.push(arg); + console.log = (arg) => steps.push(arg); class Child extends Component { static template = xml`
child
`; @@ -51,7 +51,7 @@ test("can log full lifecycle", async () => { "[OWL_DEBUG] Child rendering template", "[OWL_DEBUG] Parent willPatch", "[OWL_DEBUG] Child mounted", - "[OWL_DEBUG] Parent patched" + "[OWL_DEBUG] Parent patched", ]); console.log = log; }); diff --git a/tests/tooling/debug_script_2.test.ts b/tests/tooling/debug_script_2.test.ts index 83efcbab..e54b90b5 100644 --- a/tests/tooling/debug_script_2.test.ts +++ b/tests/tooling/debug_script_2.test.ts @@ -19,7 +19,7 @@ debugOwl(owl, { logScheduler: true }); test("can log scheduler start and stop", async () => { const steps: string[] = []; const log = console.log; - console.log = arg => steps.push(arg); + console.log = (arg) => steps.push(arg); class Child extends Component { static template = xml`
child
`; @@ -44,7 +44,7 @@ test("can log scheduler start and stop", async () => { "[OWL_DEBUG] Child rendering template", "[OWL_DEBUG] Child mounted", "[OWL_DEBUG] Parent mounted", - "[OWL_DEBUG] scheduler: stop running tasks queue" + "[OWL_DEBUG] scheduler: stop running tasks queue", ]); console.log = log; }); diff --git a/tests/tooling/debug_script_3.test.ts b/tests/tooling/debug_script_3.test.ts index 7f476c98..a978fdd5 100644 --- a/tests/tooling/debug_script_3.test.ts +++ b/tests/tooling/debug_script_3.test.ts @@ -19,7 +19,7 @@ debugOwl(owl, { logScheduler: true }); test("log a specific message for render method calls if component is not mounted", async () => { const steps: string[] = []; const log = console.log; - console.log = arg => steps.push(arg); + console.log = (arg) => steps.push(arg); class Parent extends Component { static template = xml`
`; @@ -40,7 +40,7 @@ test("log a specific message for render method calls if component is not mounted "[OWL_DEBUG] Parent mounted", "[OWL_DEBUG] scheduler: stop running tasks queue", "[OWL_DEBUG] Parent willUnmount", - "[OWL_DEBUG] Parent render (warning: component is not mounted, this render has no effect)" + "[OWL_DEBUG] Parent render (warning: component is not mounted, this render has no effect)", ]); console.log = log; }); diff --git a/tests/tooling/debug_script_4.test.ts b/tests/tooling/debug_script_4.test.ts index 26850cc9..3eb72532 100644 --- a/tests/tooling/debug_script_4.test.ts +++ b/tests/tooling/debug_script_4.test.ts @@ -19,7 +19,7 @@ debugOwl(owl, { logScheduler: true }); test("log a sub component with non stringifiable props", async () => { const steps: string[] = []; const log = console.log; - console.log = arg => steps.push(arg); + console.log = (arg) => steps.push(arg); class Child extends Component { static template = xml``; @@ -51,7 +51,7 @@ test("log a sub component with non stringifiable props", async () => { "[OWL_DEBUG] Parent mounted", "[OWL_DEBUG] scheduler: stop running tasks queue", "[OWL_DEBUG] Parent willUnmount", - "[OWL_DEBUG] Child willUnmount" + "[OWL_DEBUG] Child willUnmount", ]); console.log = log; }); diff --git a/tests/tooling/doc_link_checker.test.ts b/tests/tooling/doc_link_checker.test.ts index a11133ff..7755eeba 100644 --- a/tests/tooling/doc_link_checker.test.ts +++ b/tests/tooling/doc_link_checker.test.ts @@ -60,14 +60,14 @@ function getFiles(path: string[] = []): FileData[] { if (path.length === 0) { const baseFiles: FileData[] = [ { name: "README.md", path: [], links: [], sections: [], fullName: "README.md" }, - { name: "roadmap.md", path: [], links: [], sections: [], fullName: "roadmap.md" } + { name: "roadmap.md", path: [], links: [], sections: [], fullName: "roadmap.md" }, ]; const rest = getFiles(["doc"]); const result = baseFiles.concat(rest); result.forEach(addMardownData); return result; } - const files = fs.readdirSync(path.join("/"), { withFileTypes: true }).map(f => { + const files = fs.readdirSync(path.join("/"), { withFileTypes: true }).map((f) => { if (f.isDirectory()) { return getFiles(path.concat(f.name)); } @@ -78,8 +78,8 @@ function getFiles(path: string[] = []): FileData[] { path, links: [], sections: [], - fullName - } + fullName, + }, ]; }); return Array.prototype.concat(...files); @@ -127,7 +127,7 @@ export function isLinkValid(link: MarkDownLink, current: FileData, files: FileDa } // Step 4: check if there is a matching file - let target: FileData | undefined = files.find(f => f.fullName === linkFullName); + let target: FileData | undefined = files.find((f) => f.fullName === linkFullName); if (!target) { return false; } @@ -135,7 +135,7 @@ export function isLinkValid(link: MarkDownLink, current: FileData, files: FileDa // Step 5: if necessary, check if there is a corresponding link inside the target // link name if (hash) { - if (!target.sections.find(s => s.slug === hash)) { + if (!target.sections.find((s) => s.slug === hash)) { return false; } } @@ -153,7 +153,7 @@ function slugify(str) { .toLowerCase() .replace(/\//g, "") // remove / .replace(/\s+/g, "-") // Replace spaces with - - .replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters + .replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special characters .replace(/&/g, "-and-") // Replace & with ‘and’ .replace(/[^\w\-]+/g, "") // Remove all non-word characters .replace(/\-\-+/g, "-") // Replace multiple - with single - diff --git a/tests/vdom.test.ts b/tests/vdom.test.ts index 1c66a955..54366cb6 100644 --- a/tests/vdom.test.ts +++ b/tests/vdom.test.ts @@ -13,16 +13,16 @@ function map(list, fn) { //------------------------------------------------------------------------------ // Attributes //------------------------------------------------------------------------------ -describe("attributes", function() { +describe("attributes", function () { let elm, vnode0; - beforeEach(function() { + beforeEach(function () { elm = document.createElement("div"); vnode0 = elm; }); - test("have their provided values", function() { + test("have their provided values", function () { const vnode1 = h("div", { - attrs: { href: "/foo", minlength: 1, selected: true, disabled: false } + attrs: { href: "/foo", minlength: 1, selected: true, disabled: false }, }); elm = patch(vnode0, vnode1).elm; @@ -33,7 +33,7 @@ describe("attributes", function() { expect(elm.hasAttribute("disabled")).toBe(false); }); - test("can be memoized", function() { + test("can be memoized", function () { const cachedAttrs = { href: "/foo", minlength: 1, selected: true }; const vnode1 = h("div", { attrs: cachedAttrs }); const vnode2 = h("div", { attrs: cachedAttrs }); @@ -47,9 +47,9 @@ describe("attributes", function() { expect(elm.getAttribute("selected")).toBe(""); }); - test("are not omitted when falsy values are provided", function() { + test("are not omitted when falsy values are provided", function () { const vnode1 = h("div", { - attrs: { href: null, minlength: 0, value: "", title: "undefined" } + attrs: { href: null, minlength: 0, value: "", title: "undefined" }, }); elm = patch(vnode0, vnode1).elm; expect(elm.getAttribute("href")).toBe("null"); @@ -58,13 +58,13 @@ describe("attributes", function() { expect(elm.getAttribute("title")).toBe("undefined"); }); - test("are set correctly when namespaced", function() { + test("are set correctly when namespaced", function () { const vnode1 = h("div", { attrs: { "xlink:href": "#foo" } }); elm = patch(vnode0, vnode1).elm; expect(elm.getAttributeNS("http://www.w3.org/1999/xlink", "href")).toBe("#foo"); }); - test("should not touch class nor id fields", function() { + test("should not touch class nor id fields", function () { elm = document.createElement("div"); elm.id = "myId"; elm.className = "myClass"; @@ -77,10 +77,10 @@ describe("attributes", function() { expect(elm.textContent).toBe("Hello"); }); - describe("boolean attribute", function() { - test("is present and empty string if the value is truthy", function() { + describe("boolean attribute", function () { + test("is present and empty string if the value is truthy", function () { const vnode1 = h("div", { - attrs: { required: true, readonly: 1, noresize: "truthy" } + attrs: { required: true, readonly: 1, noresize: "truthy" }, }); elm = patch(vnode0, vnode1).elm; expect(elm.hasAttribute("required")).toBe(true); @@ -91,14 +91,14 @@ describe("attributes", function() { expect(elm.getAttribute("noresize")).toBe("truthy"); }); - test("is omitted if the value is false", function() { + test("is omitted if the value is false", function () { const vnode1 = h("div", { attrs: { required: false } }); elm = patch(vnode0, vnode1).elm; expect(elm.hasAttribute("required")).toBe(false); expect(elm.getAttribute("required")).toBe(null); }); - test("is not omitted if the value is falsy but casted to string", function() { + test("is not omitted if the value is falsy but casted to string", function () { const vnode1 = h("div", { attrs: { readonly: 0, noresize: null } }); elm = patch(vnode0, vnode1).elm; expect(elm.getAttribute("readonly")).toBe("0"); @@ -106,8 +106,8 @@ describe("attributes", function() { }); }); - describe("Object.prototype property", function() { - test("is not considered as a boolean attribute and shouldn't be omitted", function() { + describe("Object.prototype property", function () { + test("is not considered as a boolean attribute and shouldn't be omitted", function () { const vnode1 = h("div", { attrs: { constructor: true } }); elm = patch(vnode0, vnode1).elm; expect(elm.hasAttribute("constructor")).toBe(true); @@ -122,47 +122,47 @@ describe("attributes", function() { //------------------------------------------------------------------------------ // Hyperscript //------------------------------------------------------------------------------ -describe("hyperscript", function() { - test("can create vnode with proper tag", function() { +describe("hyperscript", function () { + test("can create vnode with proper tag", function () { expect(h("div").sel).toBe("div"); expect(h("a").sel).toBe("a"); }); - test("can create vnode with children", function() { + test("can create vnode with children", function () { const vnode = h("div", [h("span#hello"), h("b.world")]); expect(vnode.sel).toBe("div"); expect((vnode).children[0].sel).toBe("span#hello"); expect((vnode).children[1].sel).toBe("b.world"); }); - test("can create vnode with one child vnode", function() { + test("can create vnode with one child vnode", function () { const vnode = h("div", h("span#hello")); expect(vnode.sel).toBe("div"); expect((vnode).children[0].sel).toBe("span#hello"); }); - test("can create vnode with props and one child vnode", function() { + test("can create vnode with props and one child vnode", function () { const vnode = h("div", {}, h("span#hello")); expect(vnode.sel).toBe("div"); expect((vnode).children[0].sel).toBe("span#hello"); }); - test("can create vnode with text content", function() { + test("can create vnode with text content", function () { const vnode = h("a", ["I am a string"]); expect((vnode).children[0].text).toBe("I am a string"); }); - test("can create vnode with text content in string", function() { + test("can create vnode with text content in string", function () { const vnode = h("a", "I am a string"); expect(vnode.text).toBe("I am a string"); }); - test("can create vnode with props and text content in string", function() { + test("can create vnode with props and text content in string", function () { const vnode = h("a", {}, "I am a string"); expect(vnode.text).toBe("I am a string"); }); - test("can create vnode for comment", function() { + test("can create vnode for comment", function () { const vnode = h("!", "test"); expect(vnode.sel).toBe("!"); expect(vnode.text).toBe("test"); @@ -172,20 +172,20 @@ describe("hyperscript", function() { //------------------------------------------------------------------------------ // VDOM //------------------------------------------------------------------------------ -describe("snabbdom", function() { +describe("snabbdom", function () { let elm: any, vnode0; - beforeEach(function() { + beforeEach(function () { elm = document.createElement("div"); vnode0 = elm; }); - describe("created element", function() { - test("has tag", function() { + describe("created element", function () { + test("has tag", function () { elm = patch(vnode0, h("div")).elm; expect(elm.tagName).toBe("DIV"); }); - test("has correct namespace", function() { + test("has correct namespace", function () { const SVGNamespace = "http://www.w3.org/2000/svg"; const XHTMLNamespace = "http://www.w3.org/1999/xhtml"; @@ -204,23 +204,23 @@ describe("snabbdom", function() { expect(elm.firstChild.firstChild.namespaceURI).toBe(XHTMLNamespace); }); - test("can create elements with text content", function() { + test("can create elements with text content", function () { elm = patch(vnode0, h("div", ["I am a string"])).elm; expect(elm.innerHTML).toBe("I am a string"); }); - test("can create elements with span and text content", function() { + test("can create elements with span and text content", function () { elm = patch(vnode0, h("a", [h("span"), "I am a string"])).elm; expect(elm.childNodes[0].tagName).toBe("SPAN"); expect(elm.childNodes[1].textContent).toBe("I am a string"); }); - test("can create elements with props", function() { + test("can create elements with props", function () { elm = patch(vnode0, h("a", { props: { src: "http://localhost/" } })).elm; expect(elm.src).toBe("http://localhost/"); }); - test("is a patch of the root element", function() { + test("is a patch of the root element", function () { const elmWithIdAndClass = document.createElement("div"); elmWithIdAndClass.id = "id"; elmWithIdAndClass.className = "class"; @@ -232,15 +232,15 @@ describe("snabbdom", function() { expect(elm.className).toBe("class"); }); - test("can create comments", function() { + test("can create comments", function () { elm = patch(vnode0, h("!", "test")).elm; expect(elm.nodeType).toBe(document.COMMENT_NODE); expect(elm.textContent).toBe("test"); }); }); - describe("patching an element", function() { - test("changes an elements props", function() { + describe("patching an element", function () { + test("changes an elements props", function () { const vnode1 = h("a", { props: { src: "http://other/" } }); const vnode2 = h("a", { props: { src: "http://localhost/" } }); patch(vnode0, vnode1); @@ -248,7 +248,7 @@ describe("snabbdom", function() { expect(elm.src).toBe("http://localhost/"); }); - test("preserves memoized props", function() { + test("preserves memoized props", function () { const cachedProps = { src: "http://other/" }; const vnode1 = h("a", { props: cachedProps }); const vnode2 = h("a", { props: cachedProps }); @@ -258,7 +258,7 @@ describe("snabbdom", function() { expect(elm.src).toBe("http://other/"); }); - test("removes an elements props", function() { + test("removes an elements props", function () { const vnode1 = h("a", { props: { src: "http://other/" } }); const vnode2 = h("a"); patch(vnode0, vnode1); @@ -267,7 +267,7 @@ describe("snabbdom", function() { }); }); - describe("updating children with keys", function() { + describe("updating children with keys", function () { function spanNum(n) { if (n == null) { return n; @@ -278,8 +278,8 @@ describe("snabbdom", function() { } } - describe("addition of elements", function() { - test("appends elements", function() { + describe("addition of elements", function () { + test("appends elements", function () { const vnode1 = h("span", [1].map(spanNum)); const vnode2 = h("span", [1, 2, 3].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -290,79 +290,79 @@ describe("snabbdom", function() { expect(elm.children[2].innerHTML).toBe("3"); }); - test("prepends elements", function() { + test("prepends elements", function () { const vnode1 = h("span", [4, 5].map(spanNum)); const vnode2 = h("span", [1, 2, 3, 4, 5].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(2); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]); }); - test("add elements in the middle", function() { + test("add elements in the middle", function () { const vnode1 = h("span", [1, 2, 4, 5].map(spanNum)); const vnode2 = h("span", [1, 2, 3, 4, 5].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(4); expect(elm.children.length).toBe(4); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]); }); - test("add elements at beginning and end", function() { + test("add elements at beginning and end", function () { const vnode1 = h("span", [2, 3, 4].map(spanNum)); const vnode2 = h("span", [1, 2, 3, 4, 5].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(3); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]); }); - test("adds children to parent with no children", function() { + test("adds children to parent with no children", function () { const vnode1 = h("span", { key: "span" }); const vnode2 = h("span", { key: "span" }, [1, 2, 3].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(0); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2", "3"]); }); - test("removes all children from parent", function() { + test("removes all children from parent", function () { const vnode1 = h("span", { key: "span" }, [1, 2, 3].map(spanNum)); const vnode2 = h("span", { key: "span" }); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2", "3"]); elm = patch(vnode1, vnode2).elm; expect(elm.children.length).toBe(0); }); - test("update one child with same key but different sel", function() { + test("update one child with same key but different sel", function () { const vnode1 = h("span", { key: "span" }, [1, 2, 3].map(spanNum)); const vnode2 = h("span", { key: "span" }, [ spanNum(1), h("i", { key: 2 }, "2"), - spanNum(3) + spanNum(3), ]); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2", "3"]); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2", "3"]); expect(elm.children.length).toBe(3); expect(elm.children[1].tagName).toBe("I"); }); }); - describe("removal of elements", function() { - test("removes elements from the beginning", function() { + describe("removal of elements", function () { + test("removes elements from the beginning", function () { const vnode1 = h("span", [1, 2, 3, 4, 5].map(spanNum)); const vnode2 = h("span", [3, 4, 5].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(5); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["3", "4", "5"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["3", "4", "5"]); }); - test("removes elements from the end", function() { + test("removes elements from the end", function () { const vnode1 = h("span", [1, 2, 3, 4, 5].map(spanNum)); const vnode2 = h("span", [1, 2, 3].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -374,7 +374,7 @@ describe("snabbdom", function() { expect(elm.children[2].innerHTML).toBe("3"); }); - test("removes elements from the middle", function() { + test("removes elements from the middle", function () { const vnode1 = h("span", [1, 2, 3, 4, 5].map(spanNum)); const vnode2 = h("span", [1, 2, 4, 5].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -388,8 +388,8 @@ describe("snabbdom", function() { }); }); - describe("element reordering", function() { - test("moves element forward", function() { + describe("element reordering", function () { + test("moves element forward", function () { const vnode1 = h("span", [1, 2, 3, 4].map(spanNum)); const vnode2 = h("span", [2, 3, 1, 4].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -402,7 +402,7 @@ describe("snabbdom", function() { expect(elm.children[3].innerHTML).toBe("4"); }); - test("moves element to end", function() { + test("moves element to end", function () { const vnode1 = h("span", [1, 2, 3].map(spanNum)); const vnode2 = h("span", [2, 3, 1].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -414,7 +414,7 @@ describe("snabbdom", function() { expect(elm.children[2].innerHTML).toBe("1"); }); - test("moves element backwards", function() { + test("moves element backwards", function () { const vnode1 = h("span", [1, 2, 3, 4].map(spanNum)); const vnode2 = h("span", [1, 4, 2, 3].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -427,7 +427,7 @@ describe("snabbdom", function() { expect(elm.children[3].innerHTML).toBe("3"); }); - test("swaps first and last", function() { + test("swaps first and last", function () { const vnode1 = h("span", [1, 2, 3, 4].map(spanNum)); const vnode2 = h("span", [4, 2, 3, 1].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -441,8 +441,8 @@ describe("snabbdom", function() { }); }); - describe("combinations of additions, removals and reorderings", function() { - test("move to left and replace", function() { + describe("combinations of additions, removals and reorderings", function () { + test("move to left and replace", function () { const vnode1 = h("span", [1, 2, 3, 4, 5].map(spanNum)); const vnode2 = h("span", [4, 1, 2, 3, 6].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -456,16 +456,16 @@ describe("snabbdom", function() { expect(elm.children[4].innerHTML).toBe("6"); }); - test("moves to left and leaves hole", function() { + test("moves to left and leaves hole", function () { const vnode1 = h("span", [1, 4, 5].map(spanNum)); const vnode2 = h("span", [4, 6].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(3); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["4", "6"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["4", "6"]); }); - test("handles moved and set to undefined element ending at the end", function() { + test("handles moved and set to undefined element ending at the end", function () { const vnode1 = h("span", [2, 4, 5].map(spanNum)); const vnode2 = h("span", [4, 5, 3].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -477,7 +477,7 @@ describe("snabbdom", function() { expect(elm.children[2].innerHTML).toBe("3"); }); - test("moves a key in non-keyed nodes with a size up", function() { + test("moves a key in non-keyed nodes with a size up", function () { const vnode1 = h("span", [1, "a", "b", "c"].map(spanNum)); const vnode2 = h("span", ["d", "a", "b", "c", 1, "e"].map(spanNum)); elm = patch(vnode0, vnode1).elm; @@ -489,14 +489,14 @@ describe("snabbdom", function() { }); }); - describe("misc", function() { - test("reverses elements", function() { + describe("misc", function () { + test("reverses elements", function () { const vnode1 = h("span", [1, 2, 3, 4, 5, 6, 7, 8].map(spanNum)); const vnode2 = h("span", [8, 7, 6, 5, 4, 3, 2, 1].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(8); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual([ + expect(map(elm.children, (c) => c.innerHTML)).toEqual([ "8", "7", "6", @@ -504,20 +504,20 @@ describe("snabbdom", function() { "4", "3", "2", - "1" + "1", ]); }); - test("something", function() { + test("something", function () { const vnode1 = h("span", [0, 1, 2, 3, 4, 5].map(spanNum)); const vnode2 = h("span", [4, 3, 2, 1, 5, 0].map(spanNum)); elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(6); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["4", "3", "2", "1", "5", "0"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["4", "3", "2", "1", "5", "0"]); }); - test("supports null/undefined children", function() { + test("supports null/undefined children", function () { const vnode1 = h("i", [0, 1, 2, 3, 4, 5].map(spanNum)); const vnode2 = h( "i", @@ -526,10 +526,10 @@ describe("snabbdom", function() { elm = patch(vnode0, vnode1).elm; expect(elm.children.length).toBe(6); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["2", "1", "0", "5", "4", "3"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["2", "1", "0", "5", "4", "3"]); }); - test("supports all null/undefined children", function() { + test("supports all null/undefined children", function () { const vnode1 = h("i", [0, 1, 2, 3, 4, 5].map(spanNum)); const vnode2 = h("i", [null, null, undefined, null, null, undefined]); const vnode3 = h("i", [5, 4, 3, 2, 1, 0].map(spanNum)); @@ -537,22 +537,22 @@ describe("snabbdom", function() { elm = patch(vnode1, vnode2).elm; expect(elm.children.length).toBe(0); elm = patch(vnode2, vnode3).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["5", "4", "3", "2", "1", "0"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["5", "4", "3", "2", "1", "0"]); }); }); }); - describe("updating children without keys", function() { - test("appends elements", function() { + describe("updating children without keys", function () { + test("appends elements", function () { const vnode1 = h("div", [h("span", "Hello")]); const vnode2 = h("div", [h("span", "Hello"), h("span", "World")]); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["Hello"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["Hello"]); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["Hello", "World"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["Hello", "World"]); }); - test("handles unmoved text nodes", function() { + test("handles unmoved text nodes", function () { const vnode1 = h("div", ["Text", h("span", "Span")]); const vnode2 = h("div", ["Text", h("span", "Span")]); elm = patch(vnode0, vnode1).elm; @@ -561,7 +561,7 @@ describe("snabbdom", function() { expect(elm.childNodes[0].textContent).toBe("Text"); }); - test("handles changing text children", function() { + test("handles changing text children", function () { const vnode1 = h("div", ["Text", h("span", "Span")]); const vnode2 = h("div", ["Text2", h("span", "Span")]); elm = patch(vnode0, vnode1).elm; @@ -570,7 +570,7 @@ describe("snabbdom", function() { expect(elm.childNodes[0].textContent).toBe("Text2"); }); - test("handles unmoved comment nodes", function() { + test("handles unmoved comment nodes", function () { const vnode1 = h("div", [h("!", "Text"), h("span", "Span")]); const vnode2 = h("div", [h("!", "Text"), h("span", "Span")]); elm = patch(vnode0, vnode1).elm; @@ -579,7 +579,7 @@ describe("snabbdom", function() { expect(elm.childNodes[0].textContent).toBe("Text"); }); - test("handles changing comment text", function() { + test("handles changing comment text", function () { const vnode1 = h("div", [h("!", "Text"), h("span", "Span")]); const vnode2 = h("div", [h("!", "Text2"), h("span", "Span")]); elm = patch(vnode0, vnode1).elm; @@ -588,7 +588,7 @@ describe("snabbdom", function() { expect(elm.childNodes[0].textContent).toBe("Text2"); }); - test("handles changing empty comment", function() { + test("handles changing empty comment", function () { const vnode1 = h("div", [h("!"), h("span", "Span")]); const vnode2 = h("div", [h("!", "Test"), h("span", "Span")]); elm = patch(vnode0, vnode1).elm; @@ -597,35 +597,35 @@ describe("snabbdom", function() { expect(elm.childNodes[0].textContent).toBe("Test"); }); - test("prepends element", function() { + test("prepends element", function () { const vnode1 = h("div", [h("span", "World")]); const vnode2 = h("div", [h("span", "Hello"), h("span", "World")]); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["World"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["World"]); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["Hello", "World"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["Hello", "World"]); }); - test("prepends element of different tag type", function() { + test("prepends element of different tag type", function () { const vnode1 = h("div", [h("span", "World")]); const vnode2 = h("div", [h("div", "Hello"), h("span", "World")]); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["World"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["World"]); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.tagName)).toEqual(["DIV", "SPAN"]); - expect(map(elm.children, c => c.innerHTML)).toEqual(["Hello", "World"]); + expect(map(elm.children, (c) => c.tagName)).toEqual(["DIV", "SPAN"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["Hello", "World"]); }); - test("removes elements", function() { + test("removes elements", function () { const vnode1 = h("div", [h("span", "One"), h("span", "Two"), h("span", "Three")]); const vnode2 = h("div", [h("span", "One"), h("span", "Three")]); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["One", "Two", "Three"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["One", "Two", "Three"]); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["One", "Three"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["One", "Three"]); }); - test("removes a single text node", function() { + test("removes a single text node", function () { const vnode1 = h("div", "One"); const vnode2 = h("div"); patch(vnode0, vnode1); @@ -634,49 +634,49 @@ describe("snabbdom", function() { expect(elm.textContent).toBe(""); }); - test("removes a single text node when children are updated", function() { + test("removes a single text node when children are updated", function () { const vnode1 = h("div", "One"); const vnode2 = h("div", [h("div", "Two"), h("span", "Three")]); patch(vnode0, vnode1); expect(elm.textContent).toBe("One"); patch(vnode1, vnode2); - expect(map(elm.children, c => c.textContent)).toEqual(["Two", "Three"]); + expect(map(elm.children, (c) => c.textContent)).toEqual(["Two", "Three"]); }); - test("removes a text node among other elements", function() { + test("removes a text node among other elements", function () { const vnode1 = h("div", ["One", h("span", "Two")]); const vnode2 = h("div", [h("div", "Three")]); patch(vnode0, vnode1); - expect(map(elm.childNodes, c => c.textContent)).toEqual(["One", "Two"]); + expect(map(elm.childNodes, (c) => c.textContent)).toEqual(["One", "Two"]); patch(vnode1, vnode2); expect(elm.childNodes.length).toBe(1); expect(elm.childNodes[0].tagName).toBe("DIV"); expect(elm.childNodes[0].textContent).toBe("Three"); }); - test("reorders elements", function() { + test("reorders elements", function () { const vnode1 = h("div", [h("span", "One"), h("div", "Two"), h("b", "Three")]); const vnode2 = h("div", [h("b", "Three"), h("span", "One"), h("div", "Two")]); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["One", "Two", "Three"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["One", "Two", "Three"]); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.tagName)).toEqual(["B", "SPAN", "DIV"]); - expect(map(elm.children, c => c.innerHTML)).toEqual(["Three", "One", "Two"]); + expect(map(elm.children, (c) => c.tagName)).toEqual(["B", "SPAN", "DIV"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["Three", "One", "Two"]); }); - test("supports null/undefined children", function() { + test("supports null/undefined children", function () { const vnode1 = h("i", [null, h("i", "1"), h("i", "2"), null]); const vnode2 = h("i", [h("i", "2"), undefined, undefined, h("i", "1"), undefined]); const vnode3 = h("i", [null, h("i", "1"), undefined, null, h("i", "2"), undefined, null]); elm = patch(vnode0, vnode1).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2"]); elm = patch(vnode1, vnode2).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["2", "1"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["2", "1"]); elm = patch(vnode2, vnode3).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["1", "2"]); }); - test("supports all null/undefined children", function() { + test("supports all null/undefined children", function () { const vnode1 = h("i", [h("i", "1"), h("i", "2")]); const vnode2 = h("i", [null, undefined]); const vnode3 = h("i", [h("i", "2"), h("i", "1")]); @@ -684,13 +684,13 @@ describe("snabbdom", function() { elm = patch(vnode1, vnode2).elm; expect(elm.children.length).toBe(0); elm = patch(vnode2, vnode3).elm; - expect(map(elm.children, c => c.innerHTML)).toEqual(["2", "1"]); + expect(map(elm.children, (c) => c.innerHTML)).toEqual(["2", "1"]); }); }); - describe("hooks", function() { - describe("element hooks", function() { - test("calls `create` listener before inserted into parent but after children", function() { + describe("hooks", function () { + describe("element hooks", function () { + test("calls `create` listener before inserted into parent but after children", function () { const result: any[] = []; function cb(empty, vnode) { expect(vnode.elm).toBeInstanceOf(Element); @@ -701,13 +701,13 @@ describe("snabbdom", function() { const vnode1 = h("div", [ h("span", "First sibling"), h("div", { hook: { create: cb } }, [h("span", "Child 1"), h("span", "Child 2")]), - h("span", "Can't touch me") + h("span", "Can't touch me"), ]); patch(vnode0, vnode1); expect(result).toHaveLength(1); }); - test("calls `insert` listener after both parents, siblings and children have been inserted", function() { + test("calls `insert` listener after both parents, siblings and children have been inserted", function () { const result: any[] = []; function cb(vnode) { expect(vnode.elm).toBeInstanceOf(Element); @@ -718,13 +718,13 @@ describe("snabbdom", function() { const vnode1 = h("div", [ h("span", "First sibling"), h("div", { hook: { insert: cb } }, [h("span", "Child 1"), h("span", "Child 2")]), - h("span", "Can touch me") + h("span", "Can touch me"), ]); patch(vnode0, vnode1); expect(result).toHaveLength(1); }); - test("calls `prepatch` listener", function() { + test("calls `prepatch` listener", function () { const result: any[] = []; function cb(oldVnode, vnode) { expect(oldVnode).toBe(vnode1.children![1]); @@ -733,18 +733,18 @@ describe("snabbdom", function() { } const vnode1 = h("div", [ h("span", "First sibling"), - h("div", { hook: { prepatch: cb } }, [h("span", "Child 1"), h("span", "Child 2")]) + h("div", { hook: { prepatch: cb } }, [h("span", "Child 1"), h("span", "Child 2")]), ]); const vnode2 = h("div", [ h("span", "First sibling"), - h("div", { hook: { prepatch: cb } }, [h("span", "Child 1"), h("span", "Child 2")]) + h("div", { hook: { prepatch: cb } }, [h("span", "Child 1"), h("span", "Child 2")]), ]); patch(vnode0, vnode1); patch(vnode1, vnode2); expect(result).toHaveLength(1); }); - test("calls `postpatch` after `prepatch` listener", function() { + test("calls `postpatch` after `prepatch` listener", function () { const pre: any[] = [], post: any[] = []; function preCb(oldVnode, vnode) { @@ -758,15 +758,15 @@ describe("snabbdom", function() { h("span", "First sibling"), h("div", { hook: { prepatch: preCb, postpatch: postCb } }, [ h("span", "Child 1"), - h("span", "Child 2") - ]) + h("span", "Child 2"), + ]), ]); const vnode2 = h("div", [ h("span", "First sibling"), h("div", { hook: { prepatch: preCb, postpatch: postCb } }, [ h("span", "Child 1"), - h("span", "Child 2") - ]) + h("span", "Child 2"), + ]), ]); patch(vnode0, vnode1); patch(vnode1, vnode2); @@ -774,7 +774,7 @@ describe("snabbdom", function() { expect(post).toHaveLength(1); }); - test("calls `update` listener", function() { + test("calls `update` listener", function () { const result1: any[] = []; const result2: any[] = []; function cb(result, oldVnode, vnode) { @@ -789,15 +789,15 @@ describe("snabbdom", function() { h("span", "First sibling"), h("div", { hook: { update: cb.bind(null, result1) } }, [ h("span", "Child 1"), - h("span", { hook: { update: cb.bind(null, result2) } }, "Child 2") - ]) + h("span", { hook: { update: cb.bind(null, result2) } }, "Child 2"), + ]), ]); const vnode2 = h("div", [ h("span", "First sibling"), h("div", { hook: { update: cb.bind(null, result1) } }, [ h("span", "Child 1"), - h("span", { hook: { update: cb.bind(null, result2) } }, "Child 2") - ]) + h("span", { hook: { update: cb.bind(null, result2) } }, "Child 2"), + ]), ]); patch(vnode0, vnode1); patch(vnode1, vnode2); @@ -805,7 +805,7 @@ describe("snabbdom", function() { expect(result2).toHaveLength(1); }); - test("calls `remove` listener", function() { + test("calls `remove` listener", function () { const result: any[] = []; function cb(vnode, rm) { const parent = vnode.elm.parentNode; @@ -818,7 +818,7 @@ describe("snabbdom", function() { } const vnode1 = h("div", [ h("span", "First sibling"), - h("div", { hook: { remove: cb } }, [h("span", "Child 1"), h("span", "Child 2")]) + h("div", { hook: { remove: cb } }, [h("span", "Child 1"), h("span", "Child 2")]), ]); const vnode2 = h("div", [h("span", "First sibling")]); patch(vnode0, vnode1); @@ -826,7 +826,7 @@ describe("snabbdom", function() { expect(result).toHaveLength(1); }); - test("calls `destroy` listener when patching text node over node with children", function() { + test("calls `destroy` listener when patching text node over node with children", function () { let calls = 0; function cb(vnode) { calls++; @@ -838,7 +838,7 @@ describe("snabbdom", function() { expect(calls).toBe(1); }); - test("calls `init` and `prepatch` listeners on root", function() { + test("calls `init` and `prepatch` listeners on root", function () { let count = 0; function init(vnode) { expect(vnode).toBe(vnode2); @@ -856,28 +856,28 @@ describe("snabbdom", function() { expect(count).toBe(2); }); - test("removes element when all remove listeners are done", function() { + test("removes element when all remove listeners are done", function () { let rm1, rm2, rm3; const patch = init([ { - remove: function(_, rm) { + remove: function (_, rm) { rm1 = rm; - } + }, }, { - remove: function(_, rm) { + remove: function (_, rm) { rm2 = rm; - } - } + }, + }, ]); const vnode1 = h("div", [ h("a", { hook: { - remove: function(_, rm) { + remove: function (_, rm) { rm3 = rm; - } - } - }) + }, + }, + }), ]); const vnode2 = h("div", []); elm = patch(vnode0, vnode1).elm; @@ -892,7 +892,7 @@ describe("snabbdom", function() { expect(elm.children).toHaveLength(0); }); - test("invokes remove hook on replaced root", function() { + test("invokes remove hook on replaced root", function () { const result: any[] = []; const parent = document.createElement("div"); const vnode0 = document.createElement("div"); @@ -909,34 +909,34 @@ describe("snabbdom", function() { }); }); - describe("module hooks", function() { - test("invokes `pre` and `post` hook", function() { + describe("module hooks", function () { + test("invokes `pre` and `post` hook", function () { const result: any[] = []; const patch = init([ { - pre: function() { + pre: function () { result.push("pre"); - } + }, }, { - post: function() { + post: function () { result.push("post"); - } - } + }, + }, ]); const vnode1 = h("div"); patch(vnode0, vnode1); expect(result).toEqual(["pre", "post"]); }); - test("invokes global `destroy` hook for all removed children", function() { + test("invokes global `destroy` hook for all removed children", function () { const result: any[] = []; function cb(vnode) { result.push(vnode); } const vnode1 = h("div", [ h("span", "First sibling"), - h("div", [h("span", { hook: { destroy: cb } }, "Child 1"), h("span", "Child 2")]) + h("div", [h("span", { hook: { destroy: cb } }, "Child 1"), h("span", "Child 2")]), ]); const vnode2 = h("div"); patch(vnode0, vnode1); @@ -944,31 +944,31 @@ describe("snabbdom", function() { expect(result).toHaveLength(1); }); - test("handles text vnodes with `undefined` `data` property", function() { + test("handles text vnodes with `undefined` `data` property", function () { const vnode1 = h("div", [" "]); const vnode2 = h("div", []); patch(vnode0, vnode1); patch(vnode1, vnode2); }); - test("invokes `destroy` module hook for all removed children", function() { + test("invokes `destroy` module hook for all removed children", function () { let created = 0; let destroyed = 0; const patch = init([ { - create: function() { + create: function () { created++; - } + }, }, { - destroy: function() { + destroy: function () { destroyed++; - } - } + }, + }, ]); const vnode1 = h("div", [ h("span", "First sibling"), - h("div", [h("span", "Child 1"), h("span", "Child 2")]) + h("div", [h("span", "Child 1"), h("span", "Child 2")]), ]); const vnode2 = h("div"); patch(vnode0, vnode1); @@ -977,20 +977,20 @@ describe("snabbdom", function() { expect(destroyed).toBe(4); }); - test("does not invoke `create` and `remove` module hook for text nodes", function() { + test("does not invoke `create` and `remove` module hook for text nodes", function () { let created = 0; let removed = 0; const patch = init([ { - create: function() { + create: function () { created++; - } + }, }, { - remove: function() { + remove: function () { removed++; - } - } + }, + }, ]); const vnode1 = h("div", [h("span", "First child"), "", h("span", "Third child")]); const vnode2 = h("div"); @@ -1000,24 +1000,24 @@ describe("snabbdom", function() { expect(removed).toBe(2); }); - test("does not invoke `destroy` module hook for text nodes", function() { + test("does not invoke `destroy` module hook for text nodes", function () { let created = 0; let destroyed = 0; const patch = init([ { - create: function() { + create: function () { created++; - } + }, }, { - destroy: function() { + destroy: function () { destroyed++; - } - } + }, + }, ]); const vnode1 = h("div", [ h("span", "First sibling"), - h("div", [h("span", "Child 1"), h("span", ["Text 1", "Text 2"])]) + h("div", [h("span", "Child 1"), h("span", ["Text 1", "Text 2"])]), ]); const vnode2 = h("div"); patch(vnode0, vnode1); @@ -1028,8 +1028,8 @@ describe("snabbdom", function() { }); }); - describe("short circuiting", function() { - test("does not update strictly equal vnodes", function() { + describe("short circuiting", function () { + test("does not update strictly equal vnodes", function () { const result: any[] = []; function cb(vnode) { result.push(vnode); @@ -1040,14 +1040,14 @@ describe("snabbdom", function() { expect(result).toHaveLength(0); }); - test("does not update strictly equal children", function() { + test("does not update strictly equal children", function () { const result: any[] = []; function cb(vnode) { result.push(vnode); } const vnode1 = h("div", [ h("span", { hook: { patch: cb } }, "Hello"), - h("span", "there") + h("span", "there"), ]); const vnode2 = h("div"); vnode2.children = vnode1.children; @@ -1061,45 +1061,45 @@ describe("snabbdom", function() { //------------------------------------------------------------------------------ // Html to vdom //------------------------------------------------------------------------------ -describe("html to vdom", function() { +describe("html to vdom", function () { let elm, vnode0; - beforeEach(function() { + beforeEach(function () { elm = document.createElement("div"); vnode0 = elm; }); - test("empty strings return empty list", function() { + test("empty strings return empty list", function () { expect(htmlToVDOM("")).toEqual([]); }); - test("just text", function() { + test("just text", function () { const nodeList = htmlToVDOM("simple text"); expect(nodeList).toHaveLength(1); expect(nodeList[0]).toEqual({ text: "simple text" }); }); - test("empty tag", function() { + test("empty tag", function () { const nodeList = htmlToVDOM(""); expect(nodeList).toHaveLength(1); elm = patch(vnode0, nodeList[0]).elm; expect(elm.outerHTML).toEqual(""); }); - test("tag with text", function() { + test("tag with text", function () { const nodeList = htmlToVDOM("abc"); expect(nodeList).toHaveLength(1); elm = patch(vnode0, nodeList[0]).elm; expect(elm.outerHTML).toEqual("abc"); }); - test("tag with attribute", function() { + test("tag with attribute", function () { const nodeList = htmlToVDOM(`abc`); expect(nodeList).toHaveLength(1); elm = patch(vnode0, nodeList[0]).elm; expect(elm.outerHTML).toEqual(`abc`); }); - test("misc", function() { + test("misc", function () { const nodeList = htmlToVDOM(`abc
1
`); expect(nodeList).toHaveLength(1); elm = patch(vnode0, nodeList[0]).elm;