![]() ![]() ![]() You can even configure multiple browsers, which will run the tests on each one in succession. Feel free to use another browser launcher instead. Of course, if you’re using Jasmine 1.x, be sure to install the adapter for that version.įollowing that, we install the PhantomJS launcher, the headless “browser” we’ll be using. The part is important, or we would be installing the adapter for the 1.x line of Jasmine, which will throw errors when run. The next line installs the karma-jasmine adapter for Jasmine 2.0. Again, it’s up to you if you prefer a local installation. The first line uses npm to install Karma globally. I’ll expand on what each one does after the code block: So let’s install Karma and the plugins we’ll be using. The difference in syntax means using the “-g” flag for global, or optionally “–save-dev” for local installation. The ultimate decision is up to you, and you can (almost) always mix-and-match. Karma recommends local installations, so that each individual project can rely on different versions, plugins, etc. Installation is pretty simple, and the only major decision we need to make right now is whether to install globally or locally. Karma is the test runner we’ll be using to actually execute our Jasmine tests from earlier. Once that is complete, we should be ready to install Karma. Either way, be sure to install npm as well (enabled by default). You can also use NVM (Node Version Manager) on OSX and Linux. The exact steps can vary slightly by platform, but the easiest way is to navigate to the download section and grab the files appropriate for your platform. The next step we need to take is to install Node.js and npm ( not really an acronym), which are required to install and run Karma and its plugins. Save these for now as we will use them to ensure proper setup. Inside the jasmine-standalone directory, “ lib/” contains the core framework, while “ src/” and “ spec/” have sample JavaScript files and Jasmine tests, respectively. You can use a different location if you prefer, but be aware that using “ web-app/js/” is not typically recommended. Go ahead and create a “javascript” directory under “ test/unit/“, then move and unzip Jasmine into there. 1.x or 2.x) you are using so you can grab the correct Karma adapter later. The easiest way is to navigate to the master distributions and download the standalone files from there. The first step is to add Jasmine to our project, so we can actually test our code. This is intended to get you up and running with basic knowledge as quickly as possible. ![]() My focus will be to keep a pretty minimal approach while still explaining each step of the way. Installing the Grails karma-test-runner plugin. Installing and configuring Karma and its plugins.Ĥ. Fortunately with frameworks like Jasmine and Karma, and with a little help from the karma-test-runner plugin, we can treat our JavaScript logic with the same respect as our Grails code. Client-side JavaScript code typically doesn’t get as much testing as back-end code, but with technologies like AngularJS becoming popular, more logic is making its way to the front-end, creating a higher need for tests. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |