Files
test-repo/tests/cursor/jsfmt.spec.js
T
Simon Lydell 43cb08c45c Make production tests always run against dist/ (attempt 2) (#2942)
* Make production tests always run against dist/

* Try to mock process.stdin instead of get-stream

* fix: mock `get-stream` from `index.js`

* refactor: remove unnecessary variable

* Try `transform: {}` in jest.config.js

* Add comment explaining the unusual get-stream mocking
2017-10-02 17:58:55 +02:00

39 lines
1.0 KiB
JavaScript

const prettier = require("../../tests_config/require_prettier");
test("translates cursor correctly in basic case", () => {
expect(prettier.formatWithCursor(" 1", { cursorOffset: 2 })).toEqual({
formatted: "1;\n",
cursorOffset: 1
});
});
test("positions cursor relative to closest node, not SourceElement", () => {
const code = "return 15";
expect(prettier.formatWithCursor(code, { cursorOffset: 15 })).toEqual({
formatted: "return 15;\n",
cursorOffset: 7
});
});
test("keeps cursor inside formatted node", () => {
const code = "return 15";
expect(prettier.formatWithCursor(code, { cursorOffset: 14 })).toEqual({
formatted: "return 15;\n",
cursorOffset: 14 // TODO fix this
});
});
test("doesn't insert second placeholder for nonexistent TypeAnnotation", () => {
const code = `
foo('bar', cb => {
console.log('stuff')
})`;
expect(prettier.formatWithCursor(code, { cursorOffset: 24 })).toEqual({
formatted: `foo("bar", cb => {
console.log("stuff");
});
`,
cursorOffset: 23
});
});