Calling a function recursively in appium node.js script

I am trying to click on an element in android simulator using appium , till a particular text is visible on the screen . For example i have to click on a calender next month icon till i receive checkText = July 2017.

The code i am using is :

exports.keepClickingWhileTextIsNot = function(element, checkText) {
var nextbtn = driver.elementById(‘datePickerViewMonthNameTextView’)
return nextbtn.text().then(function(text) {
if (text == checkText) {
} else {
return driver.keepClickingWhileTextIsNot(element, checkText);
The next icon is clicking repeatedly and is as expected , but it is not stopping on July 2017. Its not coming in if block when text on the android equals July 2017. I have tried string1.equals(string2) as well.

As per logs value of the variable text is coming as NaN. Where am i going wrong?