"TypeError: 'undefined' is not a function
Issue description or question
I am following docs. from https://wallabyjs.com/docs/intro/get-started-jetbrains.html
I wrote a very simple test but getting the following error. "TypeError: 'undefined' is not a function (evaluating 'animal.toBe('cat')')"
Wallaby.js configuration file
{
"files": [
"src/**/*.js"
],
"tests": [
"test/**/*Spec.js"
]
}
Code editor or IDE name and version
WebStorm v11
OS name and version
OSX
By default wallaby.js is using jasmine for browser tests (if you are writing node tests, you need to configure your runner accordingly). Jasmine has its built-in assertion library, so you may do:
expect(animal).toBe('cat');
Your config files/tests lists are files that will be loaded into the test sandbox page. If you use mocha and/or you'd like to use any other assertion library in browser environment, for example chai, or whatever assertion lib you are trying to use, you need to install it locally (via a package manager or whatever you use to manage testing dependencies), and then may just add it to your files. In case if your assertion lib needs to set some globals, you may do it in wallaby setup/bootstrap function.
I have not configured any runner so by default it should use jasmine. Hence it should use the built-in assertion library which is not happening in this case. Anyway, I added "jasmine" as runner.
First I got "wallaby license expired" although I just installed it today for trial. Then I restarted Webstorm and am getting "phantomjs-node: You don't have 'phantomjs' installed".
I can confirm that I have phantomjs installed under
Anyway, I added "jasmine" as runner.
No need, it's a default option for browser tests.
Hence it should use the built-in assertion library which is not happening in this case
Perhaps I'm missing something, but animal.toBe('cat') is not a valid jasmine assertion. expect(animal).toBe('cat'); is a correct one.
First I got "wallaby license expired" although I just installed it today for trial.
You have probably got the message that your trial session has expired. Wallaby.js has a limitation that you need to restart your IDE every hour or so to keep working with the trial version.
Then I restarted Webstorm and am getting "phantomjs-node: You don't have 'phantomjs' installed".
Just to confirm, it was working for you in an unrestricted machine and stopped when you copied it to the restricted environment?
If so, could you please check the <IDEA>/wallaby/phantomjs_v1.9.8/phantomjs file is executable, and if not, run
chmod +x phantomjs
in that folder to make it executable.
Never worked for me so far. I am on an unrestricted Mac machine. I am using latest webstorm (trial) version downloaded just to trial wallaby.js.
I confirmed that phantomjs is executable.
If I add "runner":"jasmine", then I get phantomjs-node: You don't have 'phantomjs' installed
if I remove this line then I get "TypeError: 'undefined' is not a function (evaluating 'expect(animal.toBe('cat'))"
{
"files": [
"src/**/*.js"
],
"tests": [
"app/test/**/*Spec.js"
],
"env": {
"runner" : "jasmine"
}
}
You need to remove the
"env": {
"runner" : "jasmine"
}
code. The env.runner setting is for a test runner, not a testing framework.
I get "TypeError: 'undefined' is not a function (evaluating 'expect(animal.toBe('cat'))"
The error is valid. You are running:
expect(animal.toBe('cat'))
You are calling the toBe function on the animal variable and the function doesn't exist there. As I have mentioned, you should be using:
expect(animal).toBe('cat');
if you are using jasmine built-in assertion library. You may read more about the syntax in jasmine docs.
really sorry for missing out that syntax error. It is working ok now. I've opened another issue (feature request) to add an "offline" mode so I can use it on my (restricted) work machine.
No worries, glad it's working now.
Regarding the "offline" mode, for now you may try coping the ~/Library/Caches/YOUR_IDE/wallaby to the same folder on your restricted machine as I was suggesting on Twitter.
I tried that but wallaby goes into infinite loop and the idea.log shows the following error. "Failed to check or update wallaby.js server, <<user_folder>>\AppData\Local\Temp\versionDataFile0.json (The system cannot find the file specified).
I tried to look for this file in another (unrestricted) windows installation but could not find.
Not sure why it's happening (it shouldn't), when I do it on OSX, it works for me. Also, once installed correctly, wallaby can perfectly work offline (we have quite a few users with restricted internet access). So, as an another alternative, you may try connecting to unrestricted internet from you work machine (from your phone internet for example), install all dependencies, get it running and then switch the the restricted internet.
work machine is IT controlled and I can't connect to any other network. can you tell me if I can locate and copy this versionDataFile0.json from OSX machine?
And how does it work for other users since wallaby tries to update itself whenever the IDE starts and takes 2-3+ minutes to fail with no option to cancel the network request?
can you tell me if I can locate and copy this versionDataFile0.json from OSX machine?
This file is not relevant. It's just a temp file wallaby creates and deletes. This just means that wallaby can't check the latest version.
And how does it work for other users since wallaby tries to update itself whenever the IDE starts and takes 2-3+ minutes to fail
Wallaby does try to check for newer versions whenever the IDE (re)starts and you start wallaby. But we didn't have any complaints about 2-3 minutes wait. If it can't download the version file, it just keeps working. If I just turn off the internet on my machine and restart WebStorm and start wallaby, it starts immediately. The same way it works for all other users. What it's doing internally, is just issuing an HTTP request via the standard IDE infrastructure. Perhaps the issue is specific to your restricted environment, and for some reason it takes 2-3 minutes for an HTTP request to a restricted resource to fail in your work environment?
you are right, it's my network environment/proxy server that doesn't fail immediately and king of hangs the IDE and there's no way around it. I am just hoping that you can consider adding a config option to not to check for latest version. In the mean time, I will try to copy the working installation again.
I just disabled proxy server in Intellij settings and now it returns right away and works ok. still an 'offline' mode would help.
Thanks for the update. Agreed, the 'offline' mode for installing would be good to have, I have labelled your other issue as an enhancement.