Source code

Revision control

Copy as Markdown

Other Tools

/* Any copyright is dedicated to the Public Domain.
"use strict";
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
var rule = require("../lib/rules/no-arbitrary-setTimeout");
var RuleTester = require("eslint").RuleTester;
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } });
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
function wrapCode(code, filename = "xpcshell/test_foo.js") {
return { code, filename };
}
function invalidCode(code) {
let obj = wrapCode(code);
obj.errors = [{ messageId: "listenForEvents", type: "CallExpression" }];
return obj;
}
ruleTester.run("no-arbitrary-setTimeout", rule, {
valid: [
wrapCode("setTimeout(function() {}, 0);"),
wrapCode("setTimeout(function() {});"),
wrapCode("setTimeout(function() {}, 10);", "test_foo.js"),
],
invalid: [
invalidCode("setTimeout(function() {}, 10);"),
invalidCode("setTimeout(function() {}, timeout);"),
],
});