From 3093ca04047ac38598b515e2e62f4697174c3e0e Mon Sep 17 00:00:00 2001 From: mitermayer Date: Thu, 13 Feb 2020 11:30:10 +0000 Subject: Including snapshots as part of assertions - Having snapshots can help when debugging tests --- tests/__snapshots__/formatting.test.js.snap | 255 ++++++++++++++++++++++++++++ tests/formatting.test.js | 6 + 2 files changed, 261 insertions(+) create mode 100644 tests/__snapshots__/formatting.test.js.snap 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`] = ` +" + + foo + + +

foo

+ +" +`; + +exports[`Prettier formats foo.html file with :PrettierAsync command 1`] = ` +" + + foo + + +

foo

+ +" +`; + +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`] = ` +" 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`] = ` +" + + + + + + + This could be e.g. documentation for the component. +" +`; + +exports[`Prettier formats foo.vue file with :PrettierAsync command 1`] = ` +" + + + + + + + This could be e.g. documentation for the component. +" +`; + +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(); }); }; -- cgit v1.3