@@ -8,11 +8,44 @@ const clean = html => html.replace(/(\n|\t)/g, '').trim();
88test ( 'Must fail when namespace path is not found without fallback root' , async t => {
99 const actual = `<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>` ;
1010
11- await t . throwsAsync ( async ( ) => posthtml ( [ plugin ( { root : './test/templates' , namespaces : [ { name : 'empty-namespace' , root : './test/templates/empty-namespace' } ] } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ) ;
11+ await t . throwsAsync ( async ( ) => posthtml ( [ plugin ( { root : './test/templates' , namespaceFallback : false , namespaces : [ { name : 'empty-namespace' , root : './test/templates/empty-namespace' } ] } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ) ;
1212} ) ;
1313
1414test ( 'Must fail when namespace path is not found with fallback root' , async t => {
1515 const actual = `<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>` ;
1616
17- await t . throwsAsync ( async ( ) => posthtml ( [ plugin ( { root : './test/templates' , namespaces : [ { name : 'empty-namespace' , root : './test/templates/empty-namespace' } ] } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ) ;
17+ await t . throwsAsync ( async ( ) => posthtml ( [ plugin ( { root : './test/templates' , namespaceFallback : true , namespaces : [ { name : 'empty-namespace' , root : './test/templates/empty-namespace' } ] } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ) ;
18+ } ) ;
19+
20+ test ( 'Must fail when namespace is unknown' , async t => {
21+ const actual = `<div><x-unknown-namespace::button>Submit</x-unknown-namespace::button></div>` ;
22+
23+ await t . throwsAsync ( async ( ) => posthtml ( [ plugin ( { root : './test/templates' } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ) ;
24+ } ) ;
25+
26+ test ( 'Must return node as-is when namespace is unknown with strict mode disabled' , async t => {
27+ const actual = `<div><x-unknown-namespace::button>Submit</x-unknown-namespace::button></div>` ;
28+ const expected = `<div><x-unknown-namespace::button>Submit</x-unknown-namespace::button></div>` ;
29+
30+ const html = await posthtml ( [ plugin ( { root : './test/templates' , strict : false } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ;
31+
32+ t . is ( html , expected ) ;
33+ } ) ;
34+
35+ test ( 'Must return node as-is when namespace is empty with strict mode disabled' , async t => {
36+ const actual = `<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>` ;
37+ const expected = `<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>` ;
38+
39+ const html = await posthtml ( [ plugin ( { root : './test/templates' , strict : false , namespaces : [ { name : 'empty-namespace' , root : './test/templates/empty-namespace' } ] } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ;
40+
41+ t . is ( html , expected ) ;
42+ } ) ;
43+
44+ test ( 'Must return node as-is when all defined roots are empty with strict mode disabled' , async t => {
45+ const actual = `<div><x-button>Submit</x-button></div>` ;
46+ const expected = `<div><x-button>Submit</x-button></div>` ;
47+
48+ const html = await posthtml ( [ plugin ( { root : './test/templates/empty-root' , strict : false } ) ] ) . process ( actual ) . then ( result => clean ( result . html ) ) ;
49+
50+ t . is ( html , expected ) ;
1851} ) ;
0 commit comments