-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8c8832
commit fc3eb7e
Showing
10 changed files
with
310 additions
and
87 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// @ts-check | ||
|
||
/** | ||
* @file This formatter is the same used in jest-serializer-vue-tjw. It is meant | ||
* to help people migrate from that libary to this one. | ||
*/ | ||
|
||
import beautify from 'js-beautify'; | ||
|
||
/** @typedef {import('../../types.js').CLASSICFORMATTING} CLASSICFORMATTING */ | ||
|
||
/** | ||
* The classic formatter which uses js-beautify.html, exactly matching | ||
* jest-serializer-vue-tjw. | ||
* | ||
* @param {string} markup The markup to format. | ||
* @return {string} The formatted markup. | ||
*/ | ||
export const classicFormatter = function (markup) { | ||
/** @type {CLASSICFORMATTING} */ | ||
const formatting = globalThis.vueSnapshots.classicFormatting; | ||
|
||
return beautify.html(markup, formatting); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import { classicFormatter } from '@/formatters/classic.js'; | ||
|
||
describe('classicFormatter', () => { | ||
let MyComponent; | ||
|
||
beforeEach(() => { | ||
MyComponent = { template: '' }; | ||
globalThis.vueSnapshots = { | ||
formatter: 'classic', | ||
classicFormatting: {} | ||
}; | ||
}); | ||
|
||
test('No arguments', () => { | ||
expect(classicFormatter()) | ||
.toEqual(''); | ||
}); | ||
|
||
test('Empty attributes', () => { | ||
MyComponent.template = '<div class="x y" id title="">Text</div><p class></p>'; | ||
|
||
expect(mount(MyComponent)) | ||
.toMatchInlineSnapshot(` | ||
<div class="x y" id title>Text</div> | ||
<p class></p> | ||
`); | ||
}); | ||
|
||
test('Self Closing Tags', () => { | ||
MyComponent.template = '<div></div><span class="orange"></span><svg><path d=""></path></svg> <input></input> <input type="range"> <textarea></textarea>'; | ||
const wrapper = mount(MyComponent); | ||
|
||
expect(wrapper) | ||
.toMatchInlineSnapshot(` | ||
<div></div> | ||
<span class="orange"></span> | ||
<svg> | ||
<path d="" /> | ||
</svg> | ||
<input value="''"> | ||
<input type="range" value="''"> | ||
<textarea value="''"></textarea> | ||
`); | ||
}); | ||
|
||
test('Void elements', () => { | ||
const INPUT = '<input><input type="range"><input type="range" max="50">'; | ||
|
||
expect(INPUT) | ||
.toMatchInlineSnapshot(` | ||
<input> | ||
<input type="range"> | ||
<input max="50" type="range"> | ||
`); | ||
}); | ||
|
||
describe('Stubbed components', () => { | ||
test('Fake TR in TBODY fragment', () => { | ||
const markup = ` | ||
<tbody> | ||
<tr><td>Text</td></tr> | ||
<fake-tr></fake-tr> | ||
</tbody> | ||
`.trim(); | ||
|
||
expect(markup) | ||
.toMatchInlineSnapshot(` | ||
<tbody> | ||
<tr> | ||
<td>Text</td> | ||
</tr> | ||
<fake-tr></fake-tr> | ||
</tbody> | ||
`); | ||
}); | ||
|
||
test('Fake TR in normal table', () => { | ||
const markup = ` | ||
<table> | ||
<tbody> | ||
<tr><td>Text</td></tr> | ||
<fake-tr></fake-tr> | ||
</tbody> | ||
</table> | ||
`.trim(); | ||
|
||
expect(markup) | ||
.toMatchInlineSnapshot(` | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td>Text</td> | ||
</tr> | ||
<fake-tr></fake-tr> | ||
</tbody> | ||
</table> | ||
`); | ||
}); | ||
}); | ||
|
||
test('Tags with whitespace preserved', () => { | ||
MyComponent.template = `<div>Hello World</div> | ||
<a>Hello World</a> | ||
<pre>Hello World</pre>`; | ||
|
||
const wrapper = mount(MyComponent); | ||
|
||
expect(wrapper) | ||
.toMatchInlineSnapshot(` | ||
<div>Hello World</div> | ||
<a>Hello World</a> | ||
<pre>Hello World</pre> | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.