sergeyt / karma-typescript-preprocessor

TypeScript preprocessor for karma-runner
MIT License
50 stars 20 forks source link

Cannot find name describe etc or any jasmine symbol #28

Closed duncanhunter closed 8 years ago

duncanhunter commented 9 years ago

Hi

Thanks for a great tool

When I run the below test I get a successful result (shown below) but only after I get an error for every jasmine symbol in the spec file.

example error and then passing tests:

ERROR [preprocessor.typescript]: C:/app/foodTracker/foodTracker.controller.spec.ts.ktp.ts(23,9): error TS2304: Cannot find name 'expect'. PhantomJS 1.9.8 (Windows 8): Executed 3 of 3 SUCCESS (0.004 secs / 0.002 secs)

example spec file

/// <reference path='../../tools/typings/tsd.d.ts' />
/// <reference path="../../tools/typings/jasmine/jasmine.d.ts" />

'use strict';
function greeter(person: any) {
    return 'Hello, ' + person.firstname + ' ' + person.lastname;
}

describe('A suite',() => {
    it('contains spec with an expectation',() => {
        expect(true).toBe(true);
    });
    it('greeter',() => {
        var user = { firstname: 'Jane', lastname: 'User' };
        console.log(greeter(user));
    });
});

describe('A suite is just a function',() => {
    var a: boolean;
    it('and so is a spec',() => {
        a = true;
        expect(a).toBe(true);
    });
});
niemyjski commented 9 years ago

+1

niemyjski commented 9 years ago

Did you figure this out?

DavidValin commented 9 years ago

Getting the same...

dvabuzyarov commented 9 years ago

try noResolve: false

cwiederspan commented 9 years ago

When I added something like...

/// <reference path="../_typings/jasmine/jasmine.d.ts" />

... to the top of my specs.ts file, it worked. Not sure why I need it here and not other places.

ryananthonydrake commented 8 years ago

Hi @cwiederspan I still have the same issue now even though I've included jasmine to my spec file. I'm unsure still too as to why I need it here...

Any suggestions?

/// <reference path="../../../../typings/tsd.d.ts" />
/// <reference path="../../../../typings/jasmine/jasmine.d.ts" />

describe("CampaignsService", () => {

        var $httpBackend : ng.IHttpBackendService;
        var campaignsService : ICampaignsService;

        beforeEach(module('olCampaigns'));

        beforeEach(() => {
            inject(function ( _$httpBackend_, _Campaigns_) {
                $httpBackend = _$httpBackend_;
                campaignsService = _Campaigns_;
            });
        });

        afterEach(function () {
            $httpBackend.verifyNoOutstandingExpectation();
            $httpBackend.verifyNoOutstandingRequest();
        });

        it("should initialize correctly", () => {
            expect(campaignsService).toBeDefined();
        });

        it("should GET campaigns", () => {
            $httpBackend.expectGET("campaigns.json").respond([
                {"id": "1", "name": "Campaign 1", "description": "My new campaign", "status": "live", "start": new Date(2015, 6, 2), "end": new Date(2016, 3, 5),"createdAt": new Date(2015, 6, 2),
                "updatedAt": new Date(2016, 3, 5)},
                {"id": "2", "name": "Campaign 2", "description": "My old campaign", "status": "complete", "start": new Date(2014, 3, 3), "end": new Date(2015, 3, 5), "createdAt": new Date(2015, 6, 2),
                "updatedAt": new Date(2016, 3, 5)}
            ]);

            var campaigns = campaignsService.query(function(){
                expect(campaigns).toBeDefined();
            });
            $httpBackend.flush();
        });
});

I get the error error TS2304: Cannot find name 'module' in line 10. Any suggestions as to how to best include this module?

geyang commented 8 years ago

This is resolved after I change my karma.config.js to:

noResolve: false.

tonyeung commented 8 years ago

have you guys tried including tsd.d.ts to the beginning of the globs?

sergeyt commented 8 years ago

adding reference on jasmine definitions in the spec file should fix the issue