File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11/*!
22 * Lang.js for Laravel localization in JavaScript.
33 *
4+ * @version 1.0.0
45 * @license MIT
56 * @site https://github.com/rmariuzzo/Laravel-JS-Localization
67 * @author rmariuzzo
910'use strict' ;
1011
1112( function ( root , factory ) {
13+
1214 if ( typeof define === 'function' && define . amd ) {
1315 // AMD support.
1416 define ( [ ] , factory ) ;
1921 // Browser global support.
2022 root . Lang = factory ( ) ;
2123 }
24+
2225} ( this , function ( ) {
2326
2427 // Default options //
7073 * @return {boolean } true if the given key is defined on the messages source, otherwise false.
7174 */
7275 Lang . prototype . has = function ( key ) {
73- if ( ! this . messages ) {
76+ if ( typeof key !== 'string' || ! this . messages ) {
7477 return false ;
7578 }
7679 key = this . parseKey ( key ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var util = require ( 'util' ) ;
4+ var Lang = new ( require ( '../../js/lang.js' ) ) ( ) ;
5+ var messages = require ( './data/messages' ) ;
6+
7+ Lang . setMessages ( messages ) ;
8+
9+ describe ( 'The Lang.has() method' , function ( ) {
10+
11+ it ( 'should exists' , function ( ) {
12+ expect ( Lang . has ) . toBeDefined ( ) ;
13+ } ) ;
14+
15+ it ( 'should be a function' , function ( ) {
16+ expect ( typeof Lang . has ) . toBe ( 'function' ) ;
17+ } ) ;
18+
19+ it ( 'should return false when the given key is no defined' , function ( ) {
20+ expect ( Lang . has ( 'foo.bar' ) ) . toBe ( false ) ;
21+ expect ( Lang . has ( null ) ) . toBe ( false ) ;
22+ } ) ;
23+
24+ it ( 'should return true when the given key is defined' , function ( ) {
25+ expect ( Lang . has ( 'messages.home' ) ) . toBe ( true ) ;
26+ expect ( Lang . has ( 'validation.accepted' ) ) . toBe ( true ) ;
27+ } ) ;
28+
29+ } ) ;
You can’t perform that action at this time.
0 commit comments