@@ -8,11 +8,44 @@ const clean = html => html.replace(/(\n|\t)/g, '').trim();
8
8
test ( 'Must fail when namespace path is not found without fallback root' , async t => {
9
9
const actual = `<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>` ;
10
10
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 ) ) ) ;
12
12
} ) ;
13
13
14
14
test ( 'Must fail when namespace path is not found with fallback root' , async t => {
15
15
const actual = `<div><x-empty-namespace::button>Submit</x-empty-namespace::button></div>` ;
16
16
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 ) ;
18
51
} ) ;
0 commit comments