UNPKG

1.92 kBJavaScriptView Raw
1/* global describe, it, expect */
2
3const { prepareESLint, lint } = require("../../test_utils");
4
5const engine = prepareESLint("legacy");
6
7it("Doesn't work with ES6", async () => {
8 const result = await lint(
9 engine,
10 `
11const something = [];
12
13something.push("a value");
14`
15 );
16
17 expect(result.messages).toMatchSnapshot();
18 expect(result.warningCount).toBe(0);
19 expect(result.errorCount).toBe(1);
20});
21
22describe("ES5 formatting", () => {
23 it("Gives no warning on correct code", async () => {
24 const result = await lint(
25 engine,
26 `
27/* global jQuery */
28(function($) {
29 "use strict";
30
31 function getjQueryObject(string) {
32 // Make string a vaild jQuery thing
33 var jqObj = $("");
34 try {
35 jqObj = $(string);
36 } catch (e) {
37 jqObj = $("<span />").html(string);
38 }
39 return jqObj;
40 }
41
42 $.print = $.fn.print = function(newOptions) {
43 var defaults = {
44 globalStyles: true,
45 mediaPrint: false,
46 someObject: "actuallyNot"
47 };
48
49 // Print a given set of elements
50 var options = $.extend({}, defaults, newOptions || {});
51 var $styles = getjQueryObject(options.someObject);
52 if (options.globalStyles) {
53 // Apply the stlyes from the current sheet to the printed page
54 $styles = $("style, link, meta, base, title");
55 } else if (options.mediaPrint) {
56 // Apply the media-print stylesheet
57 $styles = $("link[media=print]");
58 }
59 return $styles;
60 };
61})(jQuery);
62`
63 );
64
65 expect(result.messages).toMatchSnapshot();
66 expect(result.warningCount).toBe(0);
67 expect(result.errorCount).toBe(0);
68 });
69
70 it("Warns on wrong format", async () => {
71 const result = await lint(
72 engine,
73 `
74
75function test() { "use strict"; fetch("This is spartaaa"); }
76
77test()
78
79`
80 );
81
82 expect(result.messages).toMatchSnapshot();
83 expect(result.warningCount).toBe(0);
84 expect(result.errorCount).toBe(2);
85 });
86});