I’m experimenting with the Jasmine JavaScript testing framework to see if I can create a cucumber style testing framework using JavaScript. I want to go full out TDD on it so I started with a feature file, now I’m working on a spec to get that file running.

However as I work I get stuck on the following:

describe("A Feature Runner", function() {  
    it("can be created without error", function(){
        var runner = new FeatureRunner();
    });
    it("can load a feature file", function() {
        runner.load("test.feature");
        expect(runner.totalFeatures).toEqual(1);
    });
    it("can run the steps for the features", function() {
        var runner = new FeatureRunner();
        runner.load("test.feature");
        expect(runner.steps).toEqual(3);
    });
});

The description is too high level!

What happens when I load the feature file? Obviously a feature is loaded, but how? Something needs to happen between loading the feature and running the steps. My test needs to be more detailed.

Why not describe the load function then?

describe("A Feature Runner", function() {  
    it("can be created without error", function(){
        var runner = new FeatureRunner();
    });
    it("can load a feature file", function() {
        runner.load("test.feature");
        expect(runner.totalFeatures).toEqual(1);
    });
    describe("the load function", function() {
        it("will fetch the file from the given url", function() {

        });
    });
    it("can run the steps for the features", function() {
        var runner = new FeatureRunner();
        runner.load("test.feature");
        expect(runner.steps).toEqual(3);
    });
});

At once I realized that the load function needs to be asynchronous.