File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ module.exports = function (Twig) {
5
5
'use strict' ;
6
6
Twig . tests = {
7
7
empty ( value ) {
8
+ // Handle boolean true
9
+ if ( value === true ) {
10
+ return false ;
11
+ }
12
+
13
+ // Handle null or undefined
8
14
if ( value === null || value === undefined ) {
9
15
return true ;
10
16
}
Original file line number Diff line number Diff line change @@ -22,6 +22,18 @@ describe('Twig.js Tests ->', function () {
22
22
twig ( { data : '{{ ["1"] is empty }}' } ) . render ( ) . should . equal ( 'false' ) ;
23
23
} ) ;
24
24
25
+ it ( 'should identify booleans' , function ( ) {
26
+ // Array
27
+ twig ( { data : '{{ foo is empty }}' } ) . render ( { foo : true } ) . should . equal ( 'false' ) ;
28
+ twig ( { data : '{{ foo is empty }}' } ) . render ( { foo : false } ) . should . equal ( 'true' ) ;
29
+ } ) ;
30
+
31
+ it ( 'should identify null or undefined' , function ( ) {
32
+ // Array
33
+ twig ( { data : '{{ foo is empty }}' } ) . render ( { foo : null } ) . should . equal ( 'true' ) ;
34
+ twig ( { data : '{{ foo is empty }}' } ) . render ( { foo : undefined } ) . should . equal ( 'true' ) ;
35
+ } ) ;
36
+
25
37
it ( 'should identify empty objects' , function ( ) {
26
38
// Object
27
39
twig ( { data : '{{ {} is empty }}' } ) . render ( ) . should . equal ( 'true' ) ;
You can’t perform that action at this time.
0 commit comments