Unit testing JavaScript

Tags:

I’ve recently been looking into some JavaScript unit testing frameworks. There are many alternatives, and while many of them seem good, very few of them actually matched my requirements:

  • Must be able to run tests from the commend-line
  • Tests should be relatively easy to write

Read More

Weekend coding: Add a character counter as the background of a textarea with JavaScript

Tags:

Have you ever filled a textarea on a page, which had a limit to how many characters you could type into it? Or maybe you are a Twitter user, and as you know, Twitter only displays 140 characters of your tweets.


(Not an actual textarea)

The other day I was thinking of this: How to effectively communicate how many characters you can type into a box, and have it look good. As I got the idea from Twitter, I thought what various Twitter clients had: Just a normal counter on the side of the textbox. But then I had a brilliant idea..

Add the number counter as the background of the textarea! Perhaps someone has done this before, but I wanted to give it a shot anyway. Here I’ll show you how to do that in a “progressive” manner, so you will still keep a normal textarea if it doesn’t work out.

Read More

Why your mobile site probably sucks

Tags:

Mobile phones of today can handle big sites fine. They can handle JavaScript quite well too. Then why is it that I constantly encounter crappy mobile versions of sites? What is it that makes these sites so bad, even though they were obviously designed with small screens in mind?

While making a special layout for small screens is a great idea, there’s often something that people still get completely wrong with their mobile “optimized” sites.

Read More

How to install Palm Pre/webOS SDK on Windows 7 x64?

Tags:

Note: latest versions of webOS SDK should install without problems on Win 7 x64. However you are free to try this if you encounter problems with it.

Palm has recently released the Palm Pre webOS SDK to the public. Installing it on Windows 7 64-bit is a bit problematic however.

When attempting to install it, the setup runs through fine at first, but then does a rollback of everything. Palm says it’s working on a solution, but in the meantime, here’s an easy way to fix it!

Read More

Opera Mobile vs. iPhone Safari Mobile

Tags:

Lately I’ve had the chance to use an iPhone 3G. As I’ve been considering purchasing the new 3G S, this has been a good opportunity to see if I like the thing, but what I think of the phone itself is a matter of another post – Today, let’s look at its browse and compare it to Opera Mobile, which is another excellent “desktop browser in your pocket”.

Web browsing is an important factor for me in a smartphone. If the browser is no good, or even if it is but doesn’t do something properly, it’s immediately detrimental to the value of the device in my opinion. Lucky for them, both of these browsers do a good job, but there are some small things nevertheless…

Read More

Opera Command, JavaScript based Missile Command game

Tags:

Firstly I’d just like to let you know that the lack of posts lately is because I have a new full time job which I’m enjoying quite much so far, but it still means I have less time / motivation to write stuff. The unit testing series and other postings will continue (see how I didn’t say “next week”, but “next time” in part 5? ;) ), but probably on a bit slower schedule.

As for packageizer and few other things not working, that’s because I’m setting them up on a new server. They should be up soon’ish.

Now for the actual post!

Today I’ll talk a bit about my other popular JavaScript widget game, Opera Command. As you may have guessed, it’s a clone of Missile Command and I originally wrote it to run as an Opera Widget.

I recently modified it to run in other browsers, so you can try it out even if you don’t have Opera. There may be some issues regarding the Z, X and C keys being taken by the browser for other purproses but other than that it should work quite fine.

Read More

Unit testing 5: test-driven development

Tags:

In this post I’ll introduce the methodology known as test-driven development, and how to use it in your projects.

The difference between “normal” and test-driven development (TDD) is that when doing TDD, you write unit tests for your new code before writing the code itself. This way you ensure good test coverage for your code, and your code will also be more flexible and reusable, as you have to design the class interfaces for easy testing.

Read More

TankWar Online, my JavaScript based cannons game

Tags:

Back in late 2006 I wrote my most ambitious JavaScript/game project so far: TankWar Online, which as you may guess from the name was about tanks, shooting stuff, and it had a real-time online game mode – as far as I know, the first such ever in a JS based game.

Originally the game was made for an older version of Opera 9, and only worked in it. However, I have now modified the game so it should work in most browsers (tested Firefox, Opera 9, 10).

Click here to play cross-browser version of the game. The game should work for other parts than the online game mode, as the server is no longer functional.

Interested in hearing how the game works, such as terrain, physics and the computer AI? Keep reading!

Read More

Unit testing 4: Mock objects and testing code which uses the database

Tags:

After learning to write tests and some good testing practices, it’s now time to look at mock objects.

When testing a class which needs an instance of another class to work, you do not want to depend on the other class too much. This is where mock objects come in – a mock object is a “clone” of an object, which we can use to simplify our tests, by having the mock object perform assertions or by replacing some functionality of the mock with our custom functionality.

In this post we’ll first look at how mock objects are created and used with PHPUnit, and then we’ll take a practical example of using mocks to test code which uses the database to fetch some data.

Read More