Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("html parser should handle CRLF correctly", () => {
const input = "";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(prettier.format(input, { parser: "html" }))
).toMatchSnapshot();
});
test("markdown parser should handle CRLF correctly", () => {
const input = "```\r\n\r\n\r\n```";
expect(
// use JSON.stringify to observe CRLF
JSON.stringify(prettier.format(input, { parser: "markdown" }))
).toMatchSnapshot();
});
test("prettier.format", () => {
expect(prettier.format(" foo ( )")).toEqual("foo();\n");
expect(global.console.warn).toHaveBeenCalledTimes(1);
expect(global.console.warn.mock.calls[0]).toMatchSnapshot();
});
test("allows usage of prettier's supported parsers", () => {
const output = prettier.format("foo ( )", {
parser(text, parsers) {
expect(typeof parsers.babel).toEqual("function");
expect(typeof parsers.babylon).toEqual("function");
const ast = parsers.babel(text);
ast.program.body[0].expression.callee.name = "bar";
return ast;
}
});
expect(output).toEqual("bar();\n");
});
test("json from .prettierrc", () => {
expect(
prettier.format(" { } ", { filepath: "x/y/.prettierrc" })
).toEqual("{}\n");
});
test("allows custom parser provided as object", () => {
const output = prettier.format("1", {
parser(text) {
expect(text).toEqual("1");
return {
type: "Literal",
value: 2,
raw: "2"
};
}
});
expect(output).toEqual("2");
});
test("babel from Jakefile", () => {
expect(
prettier.format("let foo = ( x = 1 ) => x", { filepath: "x/y/Jakefile" })
).toEqual("let foo = (x = 1) => x;\n");
});
});
expect(() =>
prettier.format(input, { parser: "typescript" })
).toThrowErrorMatchingSnapshot();
expect(() => {
prettier.format("hello_world( )", { parser: "babylon" });
prettier.format("hello_world( )", { parser: "babylon" });
}).not.toThrowError();
expect(warnings).toMatchInlineSnapshot(`
expect(() =>
prettier.format("body { color: #131313; }", { parser: "postcss" })
).not.toThrowError();