diff options
| author | mitermayer <mitermayer.reis@gmail.com> | 2020-02-13 11:30:10 +0000 |
|---|---|---|
| committer | mitermayer <mitermayer.reis@gmail.com> | 2020-02-13 11:30:10 +0000 |
| commit | 3093ca04047ac38598b515e2e62f4697174c3e0e (patch) | |
| tree | bbb392361bc0bcbb4a0cbac2c97e78a53571d682 | |
| parent | e5824806aef1edb462faf1dc540b6538ba3acb0e (diff) | |
| download | vim-prettier-3093ca04047ac38598b515e2e62f4697174c3e0e.tar.xz | |
Including snapshots as part of assertions
- Having snapshots can help when debugging tests
| -rw-r--r-- | tests/__snapshots__/formatting.test.js.snap | 255 | ||||
| -rw-r--r-- | tests/formatting.test.js | 6 |
2 files changed, 261 insertions, 0 deletions
diff --git a/tests/__snapshots__/formatting.test.js.snap b/tests/__snapshots__/formatting.test.js.snap new file mode 100644 index 0000000..67cd15b --- /dev/null +++ b/tests/__snapshots__/formatting.test.js.snap @@ -0,0 +1,255 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Prettier formats foo.css file with :Prettier command 1`] = ` +".redClass { + background: \\"red\\"; +} +#redId { + background: \\"red\\"; +}" +`; + +exports[`Prettier formats foo.css file with :PrettierAsync command 1`] = ` +".redClass { + background: \\"red\\"; +} +#redId { + background: \\"red\\"; +}" +`; + +exports[`Prettier formats foo.graphql file with :Prettier command 1`] = ` +"{ + baz { + blah + ...name + } + bean { + foo + blah + bleh + } + bar { + ...name + } +}" +`; + +exports[`Prettier formats foo.graphql file with :PrettierAsync command 1`] = ` +"{ + baz { + blah + ...name + } + bean { + foo + blah + bleh + } + bar { + ...name + } +}" +`; + +exports[`Prettier formats foo.html file with :Prettier command 1`] = ` +"<html> + <head> + <title>foo</title> + </head> + <body> + <h1>foo</h1> + </body> +</html>" +`; + +exports[`Prettier formats foo.html file with :PrettierAsync command 1`] = ` +"<html> + <head> + <title>foo</title> + </head> + <body> + <h1>foo</h1> + </body> +</html>" +`; + +exports[`Prettier formats foo.js file with :Prettier command 1`] = ` +"const a = () => { + return 2; +};" +`; + +exports[`Prettier formats foo.js file with :PrettierAsync command 1`] = ` +"const a = () => { + return 2; +};" +`; + +exports[`Prettier formats foo.json file with :Prettier command 1`] = ` +"{ + \\"name\\": \\"foo\\", + \\"bar\\": \\"baz\\" +}" +`; + +exports[`Prettier formats foo.json file with :PrettierAsync command 1`] = ` +"{ + \\"name\\": \\"foo\\", + \\"bar\\": \\"baz\\" +}" +`; + +exports[`Prettier formats foo.less file with :Prettier command 1`] = ` +".redClass { + background: \\"red\\"; +} +#redId { + background: \\"red\\"; +}" +`; + +exports[`Prettier formats foo.less file with :PrettierAsync command 1`] = ` +".redClass { + background: \\"red\\"; +} +#redId { + background: \\"red\\"; +}" +`; + +exports[`Prettier formats foo.md file with :Prettier command 1`] = ` +"## foo + +Lorem ipsum dolor amet + +### bar + +- a +- b +- c" +`; + +exports[`Prettier formats foo.md file with :PrettierAsync command 1`] = ` +"## foo + +Lorem ipsum dolor amet + +### bar + +- a +- b +- c" +`; + +exports[`Prettier formats foo.php file with :Prettier command 1`] = ` +"<?php +$a = 'a'; + +$b = $a . $a . ' asda';" +`; + +exports[`Prettier formats foo.php file with :PrettierAsync command 1`] = ` +"<?php +$a = 'a'; + +$b = $a . $a . ' asda';" +`; + +exports[`Prettier formats foo.scss file with :Prettier command 1`] = ` +".redClass { + background: \\"red\\"; +} +#redId { + background: \\"red\\"; +}" +`; + +exports[`Prettier formats foo.scss file with :PrettierAsync command 1`] = ` +".redClass { + background: \\"red\\"; +} +#redId { + background: \\"red\\"; +}" +`; + +exports[`Prettier formats foo.ts file with :Prettier command 1`] = ` +"const a: () => number = () => { + return 2; +};" +`; + +exports[`Prettier formats foo.ts file with :PrettierAsync command 1`] = ` +"const a: () => number = () => { + return 2; +};" +`; + +exports[`Prettier formats foo.vue file with :Prettier command 1`] = ` +"<template> + <div class=\\"example\\">{{ msg }}</div> +</template> + +<script> +export default { + data() { + return { msg: \\"Hello world!\\" }; + } +}; +</script> + +<style> +.example { + color: red; +} +</style> + +<custom1> + This could be e.g. documentation for the component. +</custom1>" +`; + +exports[`Prettier formats foo.vue file with :PrettierAsync command 1`] = ` +"<template> + <div class=\\"example\\">{{ msg }}</div> +</template> + +<script> +export default { + data() { + return { msg: \\"Hello world!\\" }; + } +}; +</script> + +<style> +.example { + color: red; +} +</style> + +<custom1> + This could be e.g. documentation for the component. +</custom1>" +`; + +exports[`Prettier formats foo.yaml file with :Prettier command 1`] = ` +"foo: + bar: + baz: + bleh: ./foo + foobar: foobar + args: + buildno: 1" +`; + +exports[`Prettier formats foo.yaml file with :PrettierAsync command 1`] = ` +"foo: + bar: + baz: + bleh: ./foo + foobar: foobar + args: + buildno: 1" +`; diff --git a/tests/formatting.test.js b/tests/formatting.test.js index 6514fec..2a3e373 100644 --- a/tests/formatting.test.js +++ b/tests/formatting.test.js @@ -54,6 +54,9 @@ const assertFormatting = (file) => { // we now check that we have indeed formatted the code expect(updatedLines).not.toBe(lines); + + // check snapshot + expect(updatedLines).toMatchSnapshot(); }); test(`Prettier formats ${filename} file with :PrettierAsync command`, async () => { @@ -76,6 +79,9 @@ const assertFormatting = (file) => { // we now check that we have indeed formatted the code expect(lines).not.toBe(updatedLines); + + // check snapshot + expect(updatedLines).toMatchSnapshot(); }); }; |
